Use of ODO - occurs depending on.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Thomas Anthony
New Member
Posts: 8
Joined: Sun May 04, 2014 12:25 pm

Use of ODO - occurs depending on.

Post 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. :? :?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1900
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Use of ODO - occurs depending on.

Post 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.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Use of ODO - occurs depending on.

Post 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.
Thomas Anthony
New Member
Posts: 8
Joined: Sun May 04, 2014 12:25 pm

Re: Use of ODO - occurs depending on.

Post 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?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1900
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Use of ODO - occurs depending on.

Post 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.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Use of ODO - occurs depending on.

Post 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.
Thomas Anthony
New Member
Posts: 8
Joined: Sun May 04, 2014 12:25 pm

Re: Use of ODO - occurs depending on.

Post by Thomas Anthony »

Thanks. It means as far as memory allocation i concerned ODO is not 'dynamic', right?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1900
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Use of ODO - occurs depending on.

Post 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.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Use of ODO - occurs depending on.

Post 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).
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”