COBOL: OCCURS and Indexed By Tricky Example

Can you pass an Index to another COBOL Program, via LINKAGE SECTION?
No, an INDEX is not a Working-storage area. It is maintained by the System.

You can only send the data in Working-storage areas(Rough-work area) or in File Input-Output Areas to a COBOL Program.

You can pass a Subscript to another COBOL Program.

Typical COBOL Question

05  A-TABLE.                                   
    10  A-TABLE-LIST OCCURS 10 TIMES INDEXED BY A-IDX. 

        15  FILLER              PIC X(7) VALUE '<TEST>'. 
        15  A-LIST-VALUE        PIC X(30).                
        15  FILLER              PIC X(8) VALUE '</TEST>'.

The next he did as below:

SET A-IDX  to 1.
MOVE 'XYZ' to A-LIST-VALUE(A-IDX).

He displayed A-TABLE-LIST data and it populates as ‘XYZ—————————‘

The first field is FILLER so all spaces even you define value.

Second field, when you issue ‘MOVE’. First 3 bytes occupies XYZ and rest all spaces

Third field is FILLER so all spaces even you define value.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.