Page 1 of 1
Use of ODO - occurs depending on.
Posted: Wed Oct 29, 2014 3:10 pm
by Thomas Anthony
Hi,
As we know that the COBOL is a compiled language. We also know that "ODO" is known as "dynamic array declaration" in COBOL. The question is when we use the ODO in a program the maximum occurence of the table is already allocoated then in what context it's dynamic? It confuses me.
Re: Use of ODO - occurs depending on.
Posted: Wed Oct 29, 2014 6:45 pm
by Robert Sample
ODO usage will be dynamic in two cases -- when the ODO is defined in LINKAGE SECTION, and when the ODO is defined as part of an 01 under an FD. In both of these cases, COBOL cannot determine in advance how much memory to allocate since the storage in both cases is coming from outside the COBOL program (from the calling program for LINKAGE SECTION and from the operating system for the file). When defined in WORKING-STORAGE SECTION, an ODO will be allocated with the maximum number of occurrences to ensure the memory will be available.
Re: Use of ODO - occurs depending on.
Posted: Wed Oct 29, 2014 8:21 pm
by William Collins
We don't know that odo is dynamic array declaration in COBOL. Can you provide a link for that?
Enterprise COBOL V5.1 does offer an unbounded table, in the LINKAGE SECTION, otherwise, unless you do storage acquisition and management, through Language Environment, or Assembler sub-routines and not use compiler option SSRANGE, odo always has a limit, which is that of the number on the TO in the definition coded.
Re: Use of ODO - occurs depending on.
Posted: Wed Nov 19, 2014 8:27 pm
by Thomas Anthony
Possibly I've heard it wrong but then this is what everybody says here about "ODO" that it's a dynamic allocation of tables in COBOL. But I think that impression is wrong. It's not dynamic in a sense of memory allocation.
But as Robert says that under FD at 01 it can be dynamic, but is not it that maximum (TO value) is aleady allocated?
Re: Use of ODO - occurs depending on.
Posted: Wed Nov 19, 2014 9:40 pm
by Robert Sample
In an FD, the BUFFER is allocated to the maximum memory size. However, the actual number of occurrences determines how long the record is. If you attempt to go past the record length (via reference modification or using an occurrence of the ODO that is higher than the count variable), you usually wind up reading data from the next record -- even though the buffer is set to the maximum memory size, not all the bytes will necessarily be used.
For an output file, if you change the count variable then the number of bytes output with the WRITE statement will change. Of course, you do need to ensure that there is data in the occurrences.
Re: Use of ODO - occurs depending on.
Posted: Wed Nov 19, 2014 9:45 pm
by William Collins
No definition which is subordinate to an FD defines storage.
In the WORKING-STORAGE/LOCAL-STORAGE, storage is defined as the TO value (0 TO 10 TIMES means you get 10 entries defined, and you can use any between 0 and 10).
In the LINKAGE SECTION no storage is defined - until you get to the Unbounded Tables of Enterprise COBOL V5.1.
So, unless you have V5.1 and you are using the unbounded tables your ODOs are entirely static in the amount of storage defined.
If you want dynamic, you have to acquire storage yourself and manage it yourself. Which is what the unbounded tables replace.
Unless you can get other than blank looks from your colleagues when you ask them to explain, I think you'll get no further down this route.
Re: Use of ODO - occurs depending on.
Posted: Fri Nov 21, 2014 3:47 pm
by Thomas Anthony
Thanks. It means as far as memory allocation i concerned ODO is not 'dynamic', right?
Re: Use of ODO - occurs depending on.
Posted: Fri Nov 21, 2014 6:15 pm
by Robert Sample
If you are asking about run-time allocation of memory for an ODO structure, the answer is definitely NO -- memory allocation size is set during the compile. COBOL is not like C and other such languages that allow strings to be defined and resized at run time.
Re: Use of ODO - occurs depending on.
Posted: Fri Nov 21, 2014 6:51 pm
by William Collins
The only exception to what Robert has said is when you get to Enterprise COBOL V5.1. Have a look at the Language Reference and Programming Guide for that version, and you'll find the new support for "unbounded" tables (only bounded by the value that the ODO item itself can hold).