support: Customer Portal
Focused on delivering choice, investment protection and flexibility to organizations with valuable COBOL assets
 

Veryant Knowledge Base
Home > All Categories > isCOBOL General > Performance > Why start using the OCCURS DYNAMIC? How to save memory by replacing your fixed arrays
Question Title Why start using the OCCURS DYNAMIC? How to save memory by replacing your fixed arrays

Every COBOL application has many programs containing definitions with OCCURS in Working Storage or Linkage sections.
These arrays are usually of a fixed size to accommodate the maximum number of references possible in the table.
The result is that the memory consumed for the array is fixed, even when the program doesn't need to use all the occurrences.
For example, this definition:

    78  max-element    value 900.
    01  w-group.
        03 w-element   occurs max-element.
           05 w-cod    pic 9(3).
           05 w-desc   pic x(20).
           05 w-note   pic x(100).
will allocate the memory for all 900 occurrences at the program startup, even if the program will use only few references.

To reduce the memory consumed by allocating only the memory really necessary, you can change your code to use a dynamic occurs. For example:
    01  w-group.
        03 w-element   dynamic capacity max-element.
           05 w-cod    pic 9(3).
           05 w-desc   pic x(20).
           05 w-note   pic x(100).
The existing code works without any change, so statements like MOVE, IF, SORT... are still supported.
When using occurs dynamic, you cannot move or pass a parent level (w-element above) of a dynamic occurs to a similar structure with a fixed occurs.
For instance, when moving a working storage field to an FD field (where the fixed occurs remains because files were already created with that size) or vice versa, using the parent level (w-group) returns this compiler warning: "Dynamic items will be ignored". It's necessary to write a loop to move all the child fields instead of the parent.
Passing the occurs dynamic group level as a parameter in a CALL statement is supported as long as the called program receives the group in a similar OCCURS DYNAMIC array in the Linkage definition

Authored by: Veryant Support This question has been viewed 30 times so far.
Click Here to View all the questions in Performance category.
File Attachments File Attachments
How helpful was this article to you?
User Comments User Comments Add Comment
There are no user comments for this question. Be the first to post a comment. Click Here
Related Questions Related Questions
  1. Does Veryant have any performance benchmarks for isCOBOL?
  2. Long time to restore minimized application
  3. How to have better runtime performance?
  4. How can I optimize the strings management?
  5. How can I improve the startup time?
  6. How can I improve the startup time?
Article Information Additional Information
Article Number: 323
Created: 2021-11-15 7:51 AM
Rating: No Rating
 
Article Options Article Options
Print Question Print this Question
Email Question Email Question to Friend
Export to Adobe PDF Export to PDF File
Export to MS Word Export to MS Word
Bookmark Article
Subscribe to Article Subscribe to Article
 
Search Knowledge Base Search Knowledge Base



 
 

© Veryant - All Rights Reserved
Veryant and isCOBOL are trademarks or registered marks of Veryant in the United States and other countries. All other marks are the property of their respective owners.