OCCURS clauses in level 01
According to Standard COBOL 2002,
you must follow the syntax rules for the OCCURS
clause.
When you use IBM® COBOL for Linux® on x86 to
compile source code that contains an OCCURS
clause
in level 01, you will receive the error messages in the following
example:
$ cat tcOccursClause.cbl
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TEST-CASE.
000030 ENVIRONMENT DIVISION.
000040 DATA DIVISION.
000050
000060 WORKING-STORAGE SECTION.
000061
000062
000063 01 EMPLOYEES OCCURS 100 TIMES.
000064 05 FNAME PIC X(10).
000065 05 LNAME PIC X(10).
000066 05 SALARY PIC 9(5).
000067
000068 77 COUNTER PIC 9.
000070
000071 PROCEDURE DIVISION.
000072 MOVE "DAVID" TO FNAME(1).
000073 MOVE "SMITH" TO LNAME(1).
000074 MOVE "60000" TO SALARY(1).
000075 MOVE "JENNY" TO FNAME(2).
000076 MOVE "HU" TO LNAME(2).
000077 MOVE "55000" TO SALARY(2).
000078
000080 DISPLAY-RESULT.
000081 PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER > 2
000082 DISPLAY "EMPLOYEE: " FNAME IN EMPLOYEES(COUNTER)" "
000083 LNAME IN EMPLOYEES(COUNTER)" "
000084 "Salary: " SALARY IN EMPLOYEES(COUNTER)
000085 END-PERFORM.
000086 STOP-PROGRAM.
000090 STOP RUN.
$ cob2 -o tcOccursClause tcOccursClause.cbl
IBM COBOL for Linux 1.2.0 compile started
0LineID Message code Message text
9 IGYDS1063-E An "OCCURS" clause was found in the definition of a level-1 item. The
"OCCURS" clause was discarded.
-Messages Total Informational Warning Error Severe Terminating
0Printed: 1 1
End of compilation 1, program TEST-CASE, highest severity: Error.
Return code 8
According to Standard COBOL 2002, the
OCCURS
clause cannot be specified in a data description entry that has any of the
following items:- A level-number of 01, 66, 77, or 88
- A variable-occurrence data item subordinate to it
Change your COBOL source to follow Standard COBOL 2002.
For example, if you change the code in the previous example by using
the definition of EMPLOYEES that is moved from level 01 to level 03,
it compiles without messages.
$ cat sol-tcOccursClause.cbl
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TEST-CASE.
000030 ENVIRONMENT DIVISION.
000040 DATA DIVISION.
000050
000060 WORKING-STORAGE SECTION.
000061
000062 01.
000063 03 EMPLOYEES OCCURS 100 TIMES.
000065 05 FNAME PIC X(10).
000066 05 LNAME PIC X(10).
000067 05 SALARY PIC 9(5).
000068
000069 77 COUNTER PIC 9.000070
000071 PROCEDURE DIVISION.
000072 MOVE "DAVID" TO FNAME(1).
000073 MOVE "SMITH" TO LNAME(1).
000074 MOVE "60000" TO SALARY(1).
000075 MOVE "JENNY" TO FNAME(2).
000076 MOVE "HU" TO LNAME(2).
000077 MOVE "55000" TO SALARY(2).
000078
000080 DISPLAY-RESULT.
000082 PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER > 2
000084 DISPLAY "EMPLOYEE: " FNAME IN EMPLOYEE(COUNTER) " "
000085 LNAME IN EMPLOYEE(COUNTER) " "
000085 "Salary: " SALARY IN EMPLOYEE(COUNTER)
000086 END-PERFORM.
000087 STOP-PROGRAM.
000120 STOP RUN.