When using COBOL the programmer may use data or paragraph names that are not unique in the program, provided that the data names occur under a unique group level. For example, when information of a specific type such as a date is used for several items, the code will be easy to read if the same data name is used.
When a data name is duplicated, each name is qualified so that it can be uniquely identified. OF or IN is used to clearly specify the name of the group to which the data belongs.
000010 @OPTIONS MAIN 000020*---------------------------------------------------------------------- 000030* Uniqueness of qualification can be used to distinguish a data item 000035* from another of the same name. 000040*---------------------------------------------------------------------- 000050 IDENTIFICATION DIVISION. 000060 PROGRAM-ID. SAMPLE. 000070 DATA DIVISION. 000080 WORKING-STORAGE SECTION. 000090*---------------------------------------------------------------------- 000100* The same data name can be assigned to data that has the same meaning. 000110*---------------------------------------------------------------------- 000120 01 BIRTHDAY. 000130 02 YYYY PIC 9(4). 000140 02 MMDD PIC 9(4). 000150 01 TODAY. 000160 02 YYYY PIC 9(4). 000170 02 MMDD PIC 9(4). 000180*---------------------------------------------------------------------- 000190 01 AGE PIC ZZ9. 000200 PROCEDURE DIVISION. 000210 DISPLAY "When is your birthday? Example: 19690123 >>" WITH NO 000215 ADVANCING. 000220 ACCEPT BIRTHDAY. 000230 MOVE FUNCTION CURRENT-DATE TO TODAY. 000240*---------------------------------------------------------------------- 000250* OF is used to qualify data so that the data can be identified when it 000255* is referenced. 000260*---------------------------------------------------------------------- 000270 IF MMDD OF BIRTHDAY <= MMDD OF TODAY THEN 000280 COMPUTE AGE = YYYY OF TODAY - YYYY OF BIRTHDAY 000290 ELSE 000300 COMPUTE AGE = YYYY OF TODAY - YYYY OF BIRTHDAY - 1 000310 END-IF. 000320*---------------------------------------------------------------------- 000330 DISPLAY "You are" AGE " years old." 000340 EXIT PROGRAM. 000350 END PROGRAM SAMPLE.