Module 5: Data Division
- In COBOL, the hierarchy of variables can be specified using the level number concept.
- For example: - variables ‘DD’, ‘MM’ and ‘YYYY’ are three individual elementary data items. These three elementary items can be clubbed together to form a group data item named DATE. The organization for these variables is shown in below figure:-
- It is important to note that the memory space referred to by DATE variable is the combined memory space of DD, MM and YYYY variables.
- Benefit of such grouping is that programmer can now refer to the individual elementary data items ‘DD’, ‘MM’, ‘YYYY’ or directly to the group data item ‘DATE’.
- Below is declaration of variables for the above explained example:-
01 DATE. (no PIC clause as it is group data item) 05 DD PIC X(2). 05 MM PIC X(2). 05 YYYY PIC X(4).
- 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:-
- Data item that is further sub-divided are called as Group Data item.
- Group data item do not have PICTURE clause
- Group data item should be unique in a program
- Group data items can have level number from 01 to 48
- For example:- data item ‘DATE’ is Group data item which is further sub-divided into three data items ‘DD’, ‘MM’ and ‘YYYY’
- Elementary Data Item: -
- Data items that is not further sub-divided. For example:- data items ‘DD’, ‘MM’, ‘YYYY’ in above example are elementary data item as they are not further divided
- Elementary data item must include a PICTURE clause
- Elementary data item need not to be unique within same group as these data items can be uniquely referenced using OF keyword followed by group data item
- Elementary data items can be declared at level number 77, 01 - 49
- Group 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)
|01||Used to declare Group data item or Elementary data item. Data items is also referred to as Record when declared at this level|
|02-49||Used to declare Group data item or Elementary data item.|
|66||Used to declare data item with RENAMES clause|
|77||Used to declare independent data items. Data item declared at 77 level cannot be further sub-divided|
|88||Used to declare CONDITION NAME entry|