In COBOL, 01 level takes more memory?
-
ajinkya123
- New Member
- Posts: 2
- Joined: Wed Jan 28, 2015 11:40 am
In COBOL, 01 level takes more memory?
Hi,
One of my colleague said that he has heard that 01 level in Cobol takes more memory and hence arrays cant be declared in 01 level. I am not convinced by this but I could not also find a reference to prove that it is not this way. But then how exactly it is? How internally Cobol stores all these levels information?
One of my colleague said that he has heard that 01 level in Cobol takes more memory and hence arrays cant be declared in 01 level. I am not convinced by this but I could not also find a reference to prove that it is not this way. But then how exactly it is? How internally Cobol stores all these levels information?
Last edited by Anuj Dhawan on Sat Nov 14, 2015 9:38 pm, edited 1 time in total.
Reason: Typo: conceived to convinced
Reason: Typo: conceived to convinced
- Robert Sample
- Global Moderator

- Posts: 1905
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: In COBOL, 01 level takes more memory?
An 01 level takes no more memory than any other level. The reason arrays cannot be declared at the 01 level is that COBOL requires each variable be able to be uniquely defined and an 01-level array violates that requirement. Variables (other than 01 level) in COBOL can have the same name and still be referenced AS LONG AS there is a unique variable name at a lower level number to uniquely qualify the variable -- DUP-VAR IN UNIQUE-VAR is the way it is referenced.
Internally, COBOL doesn't really store level information -- it uses the level information to organize variable in memory. If your program gets a dump, you won't find the level numbers in the dump (unless you have Abend-Aid providing the COBOL variable structure, in which case you're not really using a pure memory dump).
Internally, COBOL doesn't really store level information -- it uses the level information to organize variable in memory. If your program gets a dump, you won't find the level numbers in the dump (unless you have Abend-Aid providing the COBOL variable structure, in which case you're not really using a pure memory dump).
-
William Collins
- Global Moderator

- Posts: 487
- Joined: Sun Aug 25, 2013 7:24 pm
Re: In COBOL, 01 level takes more memory?
In the past, an 01-level would always be allocated storage in multiples of eight bytes (a double-word). If your 01 was not a multiple of eight, there would be one to seven "slack bytes" following the last byte of your data.
In the past, a 77-level only defined the actual storage which was needed (subject to SYNC). So eight PIC X fields defined as 77s would take eight (consecutive) bytes of storage, and the equivalent 01-levels would have eight bytes of storage, intersperse and succeeded each by seven slack-bytes. So 64 bytes in total.
There days, with Enterprise COBOL, there is no difference in how 77s or 01s are allocated, they are both allocated how 01s used to be allocated.
So, it used to be true that an 01-level could require more storage than the length of the field but a 77 (except for SYNC) would not.
It is no longer true.
In the past, a 77-level only defined the actual storage which was needed (subject to SYNC). So eight PIC X fields defined as 77s would take eight (consecutive) bytes of storage, and the equivalent 01-levels would have eight bytes of storage, intersperse and succeeded each by seven slack-bytes. So 64 bytes in total.
There days, with Enterprise COBOL, there is no difference in how 77s or 01s are allocated, they are both allocated how 01s used to be allocated.
So, it used to be true that an 01-level could require more storage than the length of the field but a 77 (except for SYNC) would not.
It is no longer true.
- Akatsukami
- Global Moderator

- Posts: 122
- Joined: Tue Oct 20, 2015 3:20 am
- Location: Bloomington, IL
- Contact:
Re: In COBOL, 01 level takes more memory?
Of course; the first example specifies eight fields of one byte each, whilst the second specifies only seven.
"I come to the conclusion that, men loving according to their own will and fearing according to that of the prince, a wise prince should establish himself on that which is in his own control and not in that of others." -- Niccolò Machiavelli
-
William Collins
- Global Moderator

- Posts: 487
- Joined: Sun Aug 25, 2013 7:24 pm
Re: In COBOL, 01 level takes more memory?
Seven 77's of PIC X used to take less space than your seven 05s, because you have one slack byte :-) Now they take the same amount of space as seven 01-levels of PIC X (56 bytes).
The question is also making a link between storage used by 77- and 01-levels and tables (OCCURS), which makes no sense because neither a 77 nor an 01 can have OCCURS.
So, an 01-level does not take more space than a 77-level. Neither can have an OCCURS.
The question is also making a link between storage used by 77- and 01-levels and tables (OCCURS), which makes no sense because neither a 77 nor an 01 can have OCCURS.
So, an 01-level does not take more space than a 77-level. Neither can have an OCCURS.
-
William Collins
- Global Moderator

- Posts: 487
- Joined: Sun Aug 25, 2013 7:24 pm
Re: In COBOL, 01 level takes more memory?
More memory than 77s. I don't see anything else which makes much sense. An 01 takes more (or less) memory than another 01? Certainly possible, even wildly common.
Also, for fun:
Which "takes more memory" now?
Also, for fun:
Code: Select all
LINKAGE SECTION.
01 A PIC X.
01 B.
05 FILLER PIC X(7).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