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

Internal table: Occurs depending on Clause


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

New User


Joined: 25 Apr 2008
Posts: 2
Location: Frankfurt

PostPosted: Mon Apr 28, 2008 12:48 pm
Reply with quote

There are two possibilities :

01 AG-ANZ PIC 9(05).
01 AG-DATEN OCCURS 0 TO 50000 DEPENDING ON AG-ANZ.

or
01 AG-ANZ PIC 9(05).
01 AG-DATEN OCCURS 50000.

Do i have a benefit, using the depending on clause ?
What are the differences using the two possibilities ?


greetings, Stefan Ludwig
Back to top
View user's profile Send private message
vasanthkumarhb

Active User


Joined: 06 Sep 2007
Posts: 275
Location: Bang,iflex

PostPosted: Mon Apr 28, 2008 1:07 pm
Reply with quote

Hi,

Take a look here.
Quote:

The COBOL OCCURS:
Problems with COBOL Occurs?
We know how to handle them!
COBOL files can have "tables". A table is a field or group that occurs multiple times. The number of times it repeats is specified by the OCCURS clause, like this:
05 MONTHLY-SALES OCCURS 12 TIMES PIC S9(5)V99.

This creates 12 fields in the record, each with a PIC S9(5)V99.

OCCURS can also be applied to a group, such as this example:

05 LINE-ITEMS OCCURS 25 TIMES.
10 QUANTITY PIC 9999.
10 DESCRIPTION PIC X(30).
10 UNIT-PRICE PIC S9(5)V99.

This creates 25 groups, each of which contains the three fields QUANTITY, DEXCRIPTION, and UNIT-PRICE, for a total of 75 fields.

The COBOL OCCURS DEPENDING ON:
COBOL also permits tables that occur a variable number of times, depending on the value in some other field. This is similar to the COBOL OCCURS clause, except the number of times it occurs varies from record to record. This causes the records to vary in size depending on the number of occurrences in any given record. Consequently, data within the table, and any data following the table will appear in varying locations in different records.

The invoice record fragment from above could be modified as follows:

05 LINE-ITEM-COUNT PIC 99.
05 LINE-ITEMS OCCURS 0 TO 25 TIMES
DEPENDING ON LINE-ITEM-COUNT.
10 QUANTITY PIC 9999.
10 DESCRIPTION PIC X(30).
10 UNIT-PRICE PIC S9(5)V99.

The table LINE-ITEMS contains three fields (QUANTITY, DESCRIPTION, UNIT-PRICE) which make up one line on an invoice. Each invoice can have from 0 to 25 line items. The actual number of line items on a particular invoice, and therefore in the record, is given by the field LINE-ITEM-COUNT.

One instance of the table occupies 41 bytes, and the table may occur from 0 to 25 times, so the total space occupied by the table LINE-ITEMS in the record varies from 0 bytes to 1025 bytes. If there are any fields after this table, their position in the record will shift, depending on the number of occurrences of the table.

There is a more complete description of OCCURS and OCCURS DEPENDING ON in the "Tables and Occurs" section of our Reading COBOL Layouts tutorial
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Apr 28, 2008 1:45 pm
Reply with quote

Benefit depends upon usage.

if you are using the table for look-ups (binary searches - search all) then you should have a sorted table (based on your ascending or descending phrase) and the ODO will allow you to search effeciently.

you can use ODO for variable record creation.
Back to top
View user's profile Send private message
Stelud

New User


Joined: 25 Apr 2008
Posts: 2
Location: Frankfurt

PostPosted: Mon Apr 28, 2008 1:51 pm
Reply with quote

Hi Dirk,

for efficient searching i can user occurs indexed by.
I ask me, whether the occurs depending on b. e. saves memory ?
The program is running in an IMS message region.

greetings, Stefan
Back to top
View user's profile Send private message
mytags

New User


Joined: 28 Apr 2008
Posts: 63
Location: US

PostPosted: Mon Apr 28, 2008 2:31 pm
Reply with quote

Hi Dick,
Please explain more about ODC variable record creation.
With Greetings,
Hari
Back to top
View user's profile Send private message
mytags

New User


Joined: 28 Apr 2008
Posts: 63
Location: US

PostPosted: Mon Apr 28, 2008 2:34 pm
Reply with quote

Excuse me am asking about ODO
Regards
Hari
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Apr 28, 2008 3:41 pm
Reply with quote

Stefan,

there is no difference in memory allocation for a cobol internal table. both are allocated the max occurs size.

using indexes is always faster than sub-scripts. (less code generated)
literal occurance numbers are the fastest. (less code generated).
Back to top
View user's profile Send private message
Satheesh S

New User


Joined: 25 Apr 2008
Posts: 9
Location: Chennai

PostPosted: Mon Apr 28, 2008 10:36 pm
Reply with quote

Hi,

If you use index, I guess the search will fail if you have more than 32767 entries in the table Please test the program with more than 32767 entries before you use the program.

Thanks,
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Apr 28, 2008 11:00 pm
Reply with quote

Hello,

Quote:
If you use index, I guess the search will fail if you have more than 32767 entries in the table

Please post the info from the COBOL manual that says this.
Back to top
View user's profile Send private message
Satheesh S

New User


Joined: 25 Apr 2008
Posts: 9
Location: Chennai

PostPosted: Mon Apr 28, 2008 11:28 pm
Reply with quote

Hi,

The internal representation of an index is s9(4) COMP. So it will use 2 bytes. ie 15 bits for storing the values and 1 bit for sign. So maximum value that can be stored in an index is 2 to the power of 15 -1 = 32767

I guess, this would substantiate my point.

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

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Tue Apr 29, 2008 12:46 am
Reply with quote

Quote:
I ask me, whether the occurs depending on b. e. saves memory ?

No.
But if ODO used to describe file record structure and you write record, it will save you bytes on DASD, not in memory.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Tue Apr 29, 2008 1:07 am
Reply with quote

Satheesh S wrote:
Hi,

The internal representation of an index is s9(4) COMP. So it will use 2 bytes. ie 15 bits for storing the values and 1 bit for sign. So maximum value that can be stored in an index is 2 to the power of 15 -1 = 32767

I guess, this would substantiate my point.

Thanks,

Dude, you really need to read the manual. icon_lol.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Apr 29, 2008 1:33 am
Reply with quote

Hello,

Was curious, so i ran a little test.

Using:
Code:
 77  A-COMP PIC S9(8) COMP VALUE ZERO.
*                                                       
 01  AN-ARRAY.                                         
     05 AN-ITM PIC 99999 OCCURS 50000 INDEXED BY AN-INX.
*
     SET AN-INX TO 40000.               
     MOVE 40000 TO AN-ITM(AN-INX).       
     DISPLAY AN-ITM(AN-INX).             
     SET A-COMP TO AN-INX.               
     DISPLAY A-COMP.                     
     GOBACK.                             

gives:
Code:
40000     
00040000 

Unless i missed something, the 40000th entry works. . .

Also, there were no diagnostic messages in the compile.
Back to top
View user's profile Send private message
sreenigacc

New User


Joined: 16 Oct 2007
Posts: 15
Location: bangalore

PostPosted: Sun Oct 11, 2009 2:41 pm
Reply with quote

dick scherrer wrote:
Hello,

Was curious, so i ran a little test.

Using:
Code:
 77  A-COMP PIC S9(8) COMP VALUE ZERO.
*                                                       
 01  AN-ARRAY.                                         
     05 AN-ITM PIC 99999 OCCURS 50000 INDEXED BY AN-INX.
*
     SET AN-INX TO 40000.               
     MOVE 40000 TO AN-ITM(AN-INX).       
     DISPLAY AN-ITM(AN-INX).             
     SET A-COMP TO AN-INX.               
     DISPLAY A-COMP.                     
     GOBACK.                             

gives:
Code:
40000     
00040000 

Unless i missed something, the 40000th entry works. . .

Also, there were no diagnostic messages in the compile.


hi,

thank you very much for your test scenario
then what is the datatype and picture clause in your test scenario for
index AN-INX.

thanks in advance
sreenivasulu G
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sun Oct 11, 2009 3:44 pm
Reply with quote

sreenivasulu G,

to quote a year-and-a-half old post:
Quote:
Dude, you really need to read the manual
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1248
Location: Richfield, MN, USA

PostPosted: Sun Oct 11, 2009 10:33 pm
Reply with quote

See the definition of Index-name in the Language Reference Manual. All will be revealed to the diligent. icon_smile.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Oct 12, 2009 10:35 pm
Reply with quote

Hello,

Quote:
then what is the datatype and picture clause in your test scenario for index AN-INX
It is not defined in my code - it is defined internally by the compiler.

As others have mentioned, some time in the documentation would be well spent. Both the COBOL Language Reference and Programming Guide are available via the "IBM Manuals" link at the top of the page.

If you find something in the manual that is not clear, post what you found and your doubt. Someone here will be able to clarify.
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 Unload and Load ISPF Table TSO/ISPF 4
No new posts ISPF Table to add a new column TSO/ISPF 1
No new posts Inserting into table while open selec... DB2 1
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top