Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

Cobol
Introduction to Cobol Programming
Cobol Basics
Cobol Divisions
The Identification Division
The Environment Division
Data Division
Procedure Division
Defining Data Part 1
Number Formats
Moving and Editing Data
Initializing Data
Defining Data Part 2
Printing and Writing Data
Tables
Boolean Data
HIGH-VALUES and LOW-VALUES
Commands and Logics
Accept and Display
Move
Perform
Cobol IF... THEN...ELSE...
Conditions
Cobol Evaluate
Cobol Strings
Cobol Write
Scope Terminators
File Handling
Reading and Writing
REWRITE, DELETE, and EXTEND
SORT and MERGE
Input and Output Procedure
FILE STATUS (error handling)
Debugging COBOL Code

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


Moving and Editing Data


Previoushome Next






Moving and Editing Data

Care must be taken when moving (using the MOVE verb) data to an item. In other languages, such as Pascal, when to assign a value to XYZ (defined at the beginning of the program as an integer for example), then that's it. In COBOL, you have to be sure that the value you are moving to XYZ item is not bigger than the defined size.

A D V E R T I S E M E N T
If you moved 1234 to a PIC 999 defined item, then if you were to examine XYZ it would contain 234. For numeric data, the digits are truncated from the left. If item ABC were defined as PIC XXX and you moved "abcd" into it, on examination you would find it contained "abc". For alpha-numeric data characters are truncated from the right.

Conversely, moving data that is smaller than the PIC definition has certain effects. If 2 was moved to item XYZ above, then the number 2 is written to the right-most position and the leading positions are zero-filled (see figure below). Likewise, moving "A" to ABC above, the letter "A" would be written to the left-most position with the trialing positions being space-filled.


 

So what about data with decimal places?
To use decimal places, the letter 'V' is used in the PIC description:

      01 COST-OF-ITEM PIC 9(4)V99.

Here the item COST-OF-ITEM can contain a number that has two decimal places. 'V' is called an implied decimal place in that the 'V' itself is not an area of memory, i.e. the above PIC description will hold 6 digits - 4 before the decimal point and two after. The computer will align the number being moved into the item around the decimal point. See the examples below:

 

number going into COST-OF-ITEM   contents of COST-OF-ITEM  [PIC 9(4)V99]
 
     1234.56                      1234.56
     1234                         1234.00  (zero-filled)
        1                         0001.00  (zero-filled)
        0.1                       0000.10  (zero-filled)
   654321.12                      4321.12  (digits are truncated)
   654321                         4321.00  (digits are truncated)
     1234.567                     1234.56  (figure is NOT rounded up to 1234.57)

If you were to display COST-OF-ITEM it would appear as 123456 since the decimal point is assumed, not actual. For the purposes of printing or displaying a number you would need to actually show where decimal point is. You may also wish to avoid having a long string of zeros in front of a number and have spaces used instead. So the number would first have to be moved into an outputing item...well have a look at the small program below (don't worry too much about any of the commands used in the procedure division, although they're pretty self explanatory):

 

000010 IDENTIFICATION DIVISION.
000020
000030 PROGRAM-ID. DATA-MOVING-PROG.
000040 AUTHOR. TRP BROWN.
000050
000070 DATA DIVISION.
000080
000090 WORKING-STORAGE SECTION.
000100 01 COST-OF-ITEM PIC 9(4)V99.
000110 01 NUMBER-OF-ITEMS PIC 99.
000130 01 TOTAL-COST PIC 9(5)V99.
000140 01 TOTAL-COST-OUT PIC Z(4)9.99.
000150
000160 PROCEDURE DIVISION.
000170 MAIN-PARAGRAPH.
000180 MOVE 4.56 TO COST-OF-ITEM
000190 MOVE 5 TO NUMBER-OF-ITEMS
000200 COMPUTE TOTAL-COST =
000205 COST-OF-ITEM * NUMBER-OF-ITEMS
000210 MOVE TOTAL-COST TO TOTAL-COST-OUT
000220 DISPLAY "" TOTAL-COST-OUT " in total"
000230 STOP RUN.
  • the VDU will then diplay:
    22.80 in total
  • The program gives values to COST-OF-ITEM and NUMBER-OF-ITEMS (lines 180 & 190) and multiples them to give TOTAL-COST (line 200).
  • This result of this calculation is then moved to TOTAL-COST-OUT (line 210).
  • Line 140 has a PIC description 'ZZZZ9.99'. The Z means 'zero-supression' where spaces are added instead of zeros. This means that you would not be allowed to perform arithemic functions on TOTAL-COST-OUT since it now contains alphanumeric data (i.e. spaces). Also, an actual decimal point (i.e. a full stop) is used in place of the 'V'
  • You could actually write in line 200: COMPUTE TOTAL-COST-OUT = COST-OF-ITEMS * NUMBER-OF-ITEMS. Here the result of the calculation is put straight into TOTAL-COST-OUT, but no further calculations could be performed on the result.

    You'll notice that there is a gap (of 2 spaces) between the '' sign and the actual number in the displayed output. To avoid this when using '' or '$' signs (well COBOL is a business language), you can zero-suppress as follows:

     

         000140 01 TOTAL-COST-OUT  PIC 9V99.
    the VDU will then display:
    22.80 in total 

    If you want nothing in a field when printing a value that is zero then use BLANK WHEN ZERO:
     

         000140 01 PRINT-VALUE  PIC Z(5)9V99 BLANK WHEN ZERO.
    

    the VDU will then display:            ...er nothing...
          More Data Editing

    Signed data needs to be able to indicate whether it is a positive or negative number. An item may have a definition:

         01 DATA-VALUE-1 PIC S999.

    'S' indicates that the data is signed and so allows for negative values to be stored. If data is being entered from a keyboard say, as -201, into DATA-ITEM-2, the computer needs to be told that the first character is a sign:

         01 DATA-VALUE-2 PIC S999 SIGN LEADING SEPARATE.

    This would be suitable for a item into which "-201" can be entered. Here 'SIGN LEADING SEPARATE' indicates that a + or - occurs immediately before the number (you can also have 'SIGN TRAILING SEPARATE'). The important feature is the 'S' prior to the 999 (irrespective of leading or trailing signs).

    For output, the sign can be maniputed to show signs and zero-suppress using a 'floating sign'. Look at the following examples:

     

    Sending field Receiving field
      Description (PIC)     Contents     Description (PIC)     Contents  
    S999 -21 S999 -021
    S999 -21 --99 -21
    S999 +21 --99 21
    S999 -21 ++99 -21
    S999 +21 ++99 +21
    S999 SIGN LEADING SEPARATE -347 999+ 347-
    S999 SIGN TRAILING SEPARATE 347- -999 -347

    The last two examples in the table show how the sign can be moved to the other end of the number when SIGN LEADING/TRAILING SEPARATE is used.

    Some characters can be inserted into numbers, these being SPACE, SOLIDUS, ZERO (using 'B' '/' and '0' respectively):

     

    Sending field Receiving field
      Description (PIC)     Contents     Description (PIC)     Contents  
    99999 12345 99B9B99 12 3 45
    99999 12345 9909099 1203045
    999999 170568 99/99/99 17/05/68

    Adding a solidus can be useful for printing the date (which can be obtained directly from the computer in the form of yymmdd [you have to switch the order around first]). I can only assume that adding zeros to a number is for fraudulent purposes.

      Redefining Data

    It is sometimes useful to be able to have data that can be defined as either numeric or alphanumeric. This is done by redefining the data. One way is implicit redefinition:
     

        01 DATA-ITEM-X.
             03 DATA-ITEM-1  PIC 99.
    

    Although DATA-ITEM-X and DATA-ITEM-1 refer to the same area of memory storage, the level 03 item is numeric. However, group items are always alphanumeric and as a result, if you moved the number 25 into DATA-ITEM-1, you could use DATA-ITEM-X as an alphanumeric item containing the literal "25".

    Explicit redefinition uses the verb REDEFINES so that you could do this:
     

        01 DATA-ITEM-X.
             03 DATA-ITEM-1  PIC 99.
             03 DATA-ITEM-2  REDEFINES DATA-ITEM-1 PIC XX.
    

    REDEFINES cannot be used for level 01 items and can only redefine items on the same level.

    Another use for REDEFINES is to offer an alternative PIC desciption for the same data group:
     

     
    		
    01 DATE-TODAY.
    03 UK-DATE.
    05 UK-DAY PIC 99.
    05 UK-MONTH PIC 99.
    05 UK-YEAR PIC 99.
    03 JULIAN-DATE REDEFINES UK-DATE.
    05 JUL-YEAR PIC 99.
    05 JUL-DAY PIC 999.
    • UK date format is ddmmyy while Julian date format is yyddd (i.e. nth day of the year)
    • You could move (depending on the type of date given) the date into either UK-DATE or JULIAN-DATE and later in the program call the date using DATE-TODAY
    • JULIAN-DATE has one less 9 than UK-DATE. The computer will simply space-fill the unused byte.


Be the first one to comment on this page.




  Cobol eBooks
More Links » »
 
 Cobol FAQs
More Links » »
 
 Cobol Interview Questions
More Links » »
 
 Cobol Articles
More Links » »
 
 Cobol News
More Links » »
 
 Cobol Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: Cobol Basics, cobol programming language, cobol language programming tutorial pdf, history of cobol programming, basic cobol programming, syntax use in cobol programming, cobol programming software download, cobol programming code, learn cobol programming, cobol performs syntax, cobol 2008

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2021 Vyom Technosoft Pvt. Ltd., All Rights Reserved.