I am using an internal array of 600 bytes of length which occurs 1 to 999 times with Occurs Depending On max-size
1) Will the space be allocated for maximum occurances i.e. 600 * 999 even though max-size = 5
2) When the array is initialized, does it still take spaces?
Please let me know from the performance point of view if it's okay to have such size of internal array in COBOL.
Joined: 20 Oct 2006 Posts: 6970 Location: porcelain throne
2. depends on how you 'initialize' the COBOL INTERNAL TABLE.
what statements are you using to manipulate the COBOL Internal Table?
what will you use instead?
arrays in COBOL are host variables for db2.
you can continue to use the wrong terminology, but it will yield less results on searches.
the following makes no sense:
an internal array of 600 bytes of length which occurs 1 to 999 times with Occurs Depending On max-size
correctly stated would be:
a COBOL Internal Table with an item size of 600 bytes,
and an OCCURS clause that states 1 to 999.
the OCCURS DEPENDING ON (ODO) phrase is used for SEARCH and SEARCH ALL statements.
again, terminology is the key.
The COBOL Reference and the COBOL Programmers Guide have excellent descriptions/write-ups
about COBOL Internal Tables,
but say little about COBOL Internal ARRAYs - which actually don't exist.
there are COBOL Arrays and COBOL Internal Tables.
They are not the same.
Joined: 22 Apr 2006 Posts: 6258 Location: Mumbai, India
If you define an OCCURS DEPENDING ON in Working-Storage (Term, Internal Table, actually suggests that - but I'll ask?), the amount of storage is always allocated to the maximum number specified in the "TO". On the other hand, Dynamic Allocation in Linkage allows you to allocate enough storage, based upon the amount needed/requested.
So if the assumption about WS is correct - COBOL is a compiled-language, so there is no way that it can have "dynamic arrays" for WS ODO. In other words, if the COBOL Internal Table is defined in Working-Storage with the ODO (occurs depending on) phrase, it will always be mapped to max potential size.
However, if the ODO is in FILE SECTION or LINKAGE SECTION. For FILE SECTION variables, the length of the data read/ written will be determined by the ODO - and this does leave plenty of potential for problems. In my small experience, I've used them very rarely. And in LINKAGE SECTION, the ODO should reflect the actual number of occurrences passed by the calling program.
Said that - I'm not very sure about the performance question now...