Allocation of Memory in Variable-Length Tables

自闭症网瘾萝莉.ら 提交于 2019-12-03 17:28:41

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.

NealB

In the CICS world, OCCURS DEPENDING ON (ODO) can be used to create a table that is dynamically sized at run time. However, the way you are declaring SOAP-RECORD will allocate enough memory to hold a record of maximum size.

Try the following:

First, move the SOAP-RECORD into LINKAGE SECTION. Items declared in the linkage section do not have any memory allocated for them. At this point you only have a record layout. Leave the declaration of ITEM-COUNT and SUB-COUNT in WORKING-STORAGE.

Next, declare a pointer and a length in WORKING-STORAGE something like:

77 SOAP-PTR       USAGE POINTER.
77 SOAP-LENGTH    PIC S9(8) BINARY.

Finally in the PROCEDURE DIVISION: Set the size of the array dimensions to some real values; allocate the appropriate amount of memory and then connect the two. For example:

MOVE 200 TO ITEM-COUNT
MOVE 15 TO SUB-COUNT
MOVE LENGTH OF SOAP-RECORD TO SOAP-LENGTH
EXEC CICS GETMAIN
     BELOW
     USERDATAKEY
     SET(SOAP-PTR)
     FLENGTH(SOAP-LENGTH)
END-EXEC
SET ADDRESS OF SOAP-RECORD TO SOAP-PTR

This will allocate only enough memory to store a SOAP-RECORD with 200 SOAP-ITEMS each of which contain 15 SI-SUB-ITEMS.

Note that the LENGTH OF register gives you the size of SOAP-RECORD based on the ODO object values (ITEM-COUNT, SUB-COUNT) as opposed to the maximum number of OCCURS.

Very important... Don't forget to deallocate the memory when your done!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!