IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

why we shouldn't use occur clause in 01 group level item ?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Sat May 05, 2007 11:36 am
Reply with quote

why we shouldn't use occur clause in 01 group level item ?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sat May 05, 2007 12:30 pm
Reply with quote

You're kidding, right?
It's not "shouldn't", it's "can't".
That's the Rules.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat May 05, 2007 9:02 pm
Reply with quote

I think the reason is that an 01 is the highest group level allowed and the table itself is treated as a group; that would have to be a higher level than the 01s it contains.

But if the OCCURS appears at some lower level than 01, there's always a higher level to define the table as a whole.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sat May 05, 2007 9:28 pm
Reply with quote

Actually it is because of the guarantee provided by COBOL that 01 levels in working storage are doubleword aligned.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat May 05, 2007 9:41 pm
Reply with quote

Hi Will,

I used to think that but now I'm not so sure. What makes you think so?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sun May 06, 2007 1:09 am
Reply with quote

Enterprise COBOL Language Reference, SYNCHRONIZED clause, just before "Slack Bytes":
Quote:
In the file section, the compiler assumes that all level-01 records that contain SYNCHRONIZED items are aligned on doubleword boundaries in the buffer. You must provide the necessary slack bytes between records to ensure alignment when there are multiple records in a block.
In the working-storage section, the compiler aligns all level-01 entries on a doubleword boundary.
For the purposes of aligning binary items in the linkage section, all level-01 items are assumed to begin on doubleword boundaries. Therefore, if you issue a CALL statement, such operands of any USING phrase within it must be aligned correspondingly.
I'm sure it's there, but I didn't find the reference to 77 levels.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun May 06, 2007 7:02 am
Reply with quote

I know all that, but how does it prevent the compiler from generating the appropriate code to process the table?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sun May 06, 2007 11:37 am
Reply with quote

The FM wrote:
The OCCURS clause cannot be specified in a data description entry that:
v Has a level number of 01, 66, 77, or 88.
v Describes a redefined data item.

William Thompson wrote:
That's the Rules.
But since the compiler can account for and handle slack bytes caused by syncronized entries within the occuring entries, I haven't come up with a good reason why it shouldn't be able to....
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun May 06, 2007 10:22 pm
Reply with quote

That's why I gave up on it.

On the otherhand, it's nice to have a level above the OCCURS level to do things like move the table; init the table with "MOVE ALL X'FF' TO table-level; pass the table to a subpgm, etc..
Back to top
View user's profile Send private message
rz061m

New User


Joined: 03 Mar 2006
Posts: 48
Location: Chennai

PostPosted: Mon May 07, 2007 3:18 pm
Reply with quote

Hi all,

By declaring OCCURS in 01 level you are actually trying to repeat a record from N number of times. This is not possible or actually does not make sense.

***** Rather you can only try to repeat a field in a record for N times not the record itself. *****

EXAMPLE:

01 STUDENT.
05 SUB1 PIC X(3) 10 TIMES.

Here you can have mulitple subjects for a single student. But not the other way round.

Thanks,
RZ061M
Back to top
View user's profile Send private message
amiya_mf

New User


Joined: 01 Mar 2005
Posts: 18

PostPosted: Mon May 07, 2007 4:08 pm
Reply with quote

Hi RZ061M,

Your are absolutely right. Repeatation is only ment for fields not for record.

This is the reason 01 does not allow occurs clause.

rz061m wrote:
Hi all,

By declaring OCCURS in 01 level you are actually trying to repeat a record from N number of times. This is not possible or actually does not make sense.

***** Rather you can only try to repeat a field in a record for N times not the record itself. *****

EXAMPLE:

01 STUDENT.
05 SUB1 PIC X(3) 10 TIMES.

Here you can have mulitple subjects for a single student. But not the other way round.

Thanks,
RZ061M
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Mon May 07, 2007 5:43 pm
Reply with quote

Since the language was defined (by committee nonetheless!) before the various COBOL compilers were written, and without regard to the architecture of the many machines it would run on, I think that answers to questions like this relate more to what inspires good programming practices than technical data storage requirements.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon May 07, 2007 10:15 pm
Reply with quote

Hello,

Where did "the record" come in?
Quote:
Your are absolutely right. Repeatation is only ment for fields not for record.


The rule applies to all level 01s regardless of whether they are a record definition or not. . . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to load to DB2 with column level ... DB2 6
No new posts ISRSUPC search utility - using high l... TSO/ISPF 2
No new posts To search DB2 table based on Conditio... DB2 1
No new posts Compare latest 2 rows of a table usin... DB2 1
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
Search our Forums:

Back to Top