COBOL Confusion

Hey there. I am having problems with a coding project that I am trying to solve in a zOS environment using COBOL. I need to read the file and put it in an indexed table (I know there will be less than 90 entries).

What throws me away is that we are bound by the project parameters using the "Table-Size" variable (in a declaration with a null value).

Given all this, I need to do something like “It happens from 1 to 90 times depending on the size of the table”, but I don’t understand how it will work if the size of the table should (as far as I can tell) because the size of the table increases along with each record that is added to the table. Can anyone clarify this for me?

Thanks!

+3
source share
2 answers

It seems like your main problem is this: how does the compiler know how much to allocate in the array if the size changes at runtime?

The answer is that it allocates the maximum amount of space (enough for 90 entries). Please note that this is the space for working storage. When a record is written to a file, only the corresponding part is written.

Example:

01  TABLE-SIZE  PIC 9
01  TABLE OCCURS 1 TO 9 TIMES DEPENDING ON TABLE-SIZE
    03 FLD1  PIC X(4)

This will contain 36 characters (9 times 4) for TABLEin working storage. If it is TABLE-SIZEset to 2, when a record is written to a file, then only 8 characters will be written TABLE(for example, over characters written for TABLE-SIZE).

, , , TABLE, AaaaBbbbCcccDdddEeeeFfffGgggHhhhIiii, , , ( ): 2AaaaBbbb.

, , TABLE-SIZE, TABLE ( ).

, TABLE -, . , , , .

TABLE-SIZE USAGE IS COMP.

+9

, , , DEPENDING ON, . -

01   TABLE-SIZE     PIC 99
01   TABLE OCCURS 1 TO 90 TIMES
       DEPENDING ON TABLE-SIZE
    03 FIELD-1
    03 FIELD-2

..

. Publib.

+2

Source: https://habr.com/ru/post/1705489/


All Articles