Summary -

Why Data item?

In every language, the program processes the input data to get the desired outputs. The data generally stores in the memory location and can’t be processed directly in the program.

So, the program requires some pointers to map the data from the memory location. COBOL uses the data items that can point the data from the memory location. These data items should declare in the program before using to process the data.

What is Data item?

Data item holds the data that process in the application programs. Data item is a data unit that require one or several bytes or words to represent an entity.

How to declare data item?

The data item declaration is different from programming language to programming language. The most used data item declaration in COBOL language is below –

Dataitem declaration

The declaration has the below components –

  • Level number - The level number specifies the hierarchy or levels of data entries/items.
  • Data-item - Variable is a name used to identify the memory location where the program writes, retrieves the data while processing.
  • REDEFINES Clause - The REDEFINES clause allows to use multiple data description (data item) entries to describe the same storage area.
  • BLANK WHEN ZERO Clause - This clause specified only for elementary item where its picture clause defined as category numeric-edited or numeric without the symbol S or *.
  • JUSTIFIED Clause - The JUSTIFIED clause overrides standard positioning rules for category alphabetic or alphanumeric.
  • OCCURS Clause - OCCURES clause specifies the number that represents how many times the data item repeated in the table.
  • PICTURE Clause - PICTURE clause specifies the characteristics of the data items. i.e. data item type, length etc,.
  • Data Type - Data type describes the data items characteristics that are declared in the program.
  • SIGN Clause - The SIGN clause specifies the position and representation mode of the sign.
  • SYNCHRONIZED Clause - Specifies the alignment of an elementary item on a natural boundary in storage.
  • USAGE Clause - The USAGE clause specifies the format how the data is stored in memory.
  • VALUE clause - Specifies the initial values of a data item or the values associated with a condition-name.

What are the types of Data items?

Based on the level numbers, the data items divided into three categories -

  • Individual data item
  • Group data item
  • Elementary data item

Individual data item -

Individual data item is a data-item that is not part of the group data item. Individual data item always have a data-name-1, picture clause and no sub items. Individual data item name should be unique in a program or in all communicating programs(calling/called). Individual data item level numbers are from 01 to 49.

Group data item -

Group data item is a data-item that has the sub items. Group data item didn’t have a data-name-1 and picture clause. Group data item name should be unique in a program or in all communicating programs(calling/called). Group data item level numbers are from 01 to 48.

Elementary data item -

Elementary data item is a data item which is under the group data item. Elementary data item has a data-name-1 and picture clause. Elementary data item may not require to be unique and can be same under different group data item. The elementary data items under the different group data item can refer with OF keyword followed with Group item name. Elementary data item level numbers are from 02 to 49.

Practical Example -

Scenario - Below example describes how to declare data items in the program.

Code -

Declaring Data Item program Code
***************************** Top of Data ******************************
       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID. DECLDI.                                              
       AUTHOR. MTH.                                                     
       DATA DIVISION.                                                   
       WORKING-STORAGE SECTION.                                         
      *INDIVIDUAL VARIABLE / DATA ITEM                                  
       01 WS-LEVEL01           PIC 9(03) VALUE 128.                     
      *GROUP VARIABLE / DATA ITEM                                       
       01 WS-GROUP.                                                     
      *ELEMENTARY VARIABLE / DATA ITEM                                  
          05 WS-ELEM1          PIC 9(03).                               
          05 WS-ELEM2          PIC 9(03).                               
       PROCEDURE DIVISION.                                              
           MOVE 128            TO WS-ELEM1                              
           MOVE 256            TO WS-ELEM2.                             
           DISPLAY "ELEMNTARY VARIABLE1 VALUE:     " WS-ELEM1.          
           DISPLAY "ELEMNTARY VARIABLE2 VALUE:     " WS-ELEM2.          
           DISPLAY "GROUP VARIABLE VALUE:          " WS-GROUP.          
           STOP RUN.                                                    
**************************** Bottom of Data ****************************

Output -

Declaring Data Item program Output

Explaining Example -

In the above example, WS-LEVEL01 is the individual variable or data item. WS-GROUP is the group variable or data item that contains two elementary items. WS-ELEM1 & WS-ELEM2 are the elementary variable or data item under the group variable WS-GROUP.

WS-LEVEL01, WS-ELEM1 and WS-ELEM2 displays the values assigned to them. WS-GROUP variable displays the WS-ELEM1 and WS-ELEM2 variables data together one after the other.