Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 5: Data Division


COBOL Data-item (variable) Declaration

  • As mentioned earlier, DATA DIVISION is used to define Data items (also known as variable). In order to define data item we have to follow its syntax.
  • Variable declaration in COBOL programs, begins with level number and variable name. The number of optional clauses such as PICTURE, DISPLAY, VALUE, SYNC, SIGN etc. follows variable name.
  • Basic syntax for variable declaration:-

    LEVEL_NUM [varable-name|FILLER] [PICTURE] [VALUE]

  • There must be at least one space between two consecutive fields. For example, there must be one space between LEVEL _NUM and variable-name
  • Before we explain each fields of above syntax, let’s understand one simple example of variable declaration
  • Example:-

    01 FIX-AMOUNT PICTURE X(3) VALUE ‘250’.

  • In above example, 01 indicates Level number of variable, FIX-AMOUNT indicates variable-name, ‘PICTURE X(3)’ indicates that the alphanumeric data with length of 3 can be stored in this variable. At the end ‘VALUE ‘250’ ‘ indicates that the FIX-AMOUNT will have value 250 when the program is invoked for the first time. However this value can be changed by various clauses and statements which will be discussed in PROCEDURE DIVISION Module

LEVEL NUMBER

  • In COBOL, the hierarchy of variables can be specified using the level number concept.
  • Level number can range from 01 to 49. However, there are some special purpose level numbers also exists such as 66, 77 and 88.
  • Data items defined with level number can be of two types:-
    • Group Data Item
    • Elementary Data Item
  • Level 01 entries must begin in Margin A and can be continued to Margin B of coding sheet
  • The other level entries i.e. 02-49, 66 and 88 can begin with Margin A and Margin B(i.e. column position 8 to 72)
  • LEVEL NUMBER is explained in details here

Data name (or variable-name or identifier) and FILLER

  • Data name or identifier is used to reference the storage location in the memory where the actual data is stored.
  • Data name must be user-defined word; COBOL reserved words are not allowed
  • FILLER is used to name those elementary data item which the programmer does not want to assign specific name.
  • FILLER items cannot be initialized or used in any of the operation in procedure division
  • Data name (or variable-name or identifier) and FILLER is explained in detail here

PICTURE clause

  • PICTURE clause is used to specify the characteristics of the Elementary Data-Item such as Data-type, Sign, Decimal point location, Size etc.
  • PICTURE clause can be used only with elementary data-item
  • PICTURE clause is explained in detail here

VALUE clause

  • VALUE clause is used for initializing data items in working storage section. This can be done during variable declaration
  • While assigning value it is important to ensure that value of data item must not exceed picture size
  • VALUE clause cannot be specified for the data items whose size is variable
  • VALUE clause is explained in detail here



Advertisements






© copyright mainframebug.com
Privacy Policy