Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allocation of Memory in Variable-Length Tables

Tags:

cobol

Say I have the following variable-length table defined in WORKING-STORAGE...

01  SOAP-RECORD.                                           
    05  SOAP-INPUT        PIC X(8)          VALUE SPACES.
    05  SOAP-STATUS       PIC 9             VALUE ZERO.                         
    05  SOAP-MESSAGE      PIC X(50)         VALUE SPACES.
    05  SOAP-ITEMS        OCCURS 0 TO 500 TIMES   
                          DEPENDING ON ITEM-COUNT
                          INDEXED BY ITEM-X.     
        10 SI-SUB-ITEMS   OCCURS 0 TO 100 TIMES
                          DEPENDING ON SUB-COUNT
                          INDEXED BY SUB-X.     
           15 SS-KEY      PIC X(8)          VALUE SPACES.
           15 SS-AMOUNT   PIC -9(7).99      VALUE ZEROS.
           15 SS-DESCR    PIC x(100)        VALUE SPACES.

When this program runs, will it initially allocate as much space as this table could possibly need, or is it more dynamic about allocating memory? I would guess that the DEPENDING ON clause would make it more dynamic in the sense that it would allocate more memory as the ITEM-COUNT variable is incremented. A co-worker tells me otherwise, but he is not 100% sure. So I would really like to know how this works in order to structure my program as efficiently as possible.

PS: Yes, I am writing a new COBOL program! It's actually a CICS web service. I don't think this language will ever die :(

like image 232
Josh Stodola Avatar asked Jan 04 '10 17:01

Josh Stodola


1 Answers

You don't mention which compiler you're using, but, at least up through the current, 2002, COBOL standard, the space allocated for an OCCURS...DEPENDING ON (ODO) data item is not required to be dynamic. (It's really only the number of occurrences, not the length, of the data item that varies.) Although your compiler vendor may've implemented an extension to the standard, I'm not aware of any vendor that has done so in this area.

The next, but not yet approved, revision of the standard includes support for dynamic-capacity tables with a new OCCURS DYNAMIC format.

like image 159
Bruce Hobbs Avatar answered Sep 27 '22 15:09

Bruce Hobbs