View previous topic :: View next topic
|
Author |
Message |
Stelud
New User
Joined: 25 Apr 2008 Posts: 2 Location: Frankfurt
|
|
|
|
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 |
|
|
vasanthkumarhb
Active User
Joined: 06 Sep 2007 Posts: 275 Location: Bang,iflex
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Stelud
New User
Joined: 25 Apr 2008 Posts: 2 Location: Frankfurt
|
|
|
|
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 |
|
|
mytags
New User
Joined: 28 Apr 2008 Posts: 63 Location: US
|
|
|
|
Hi Dick,
Please explain more about ODC variable record creation.
With Greetings,
Hari |
|
Back to top |
|
|
mytags
New User
Joined: 28 Apr 2008 Posts: 63 Location: US
|
|
|
|
Excuse me am asking about ODO
Regards
Hari |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Satheesh S
New User
Joined: 25 Apr 2008 Posts: 9 Location: Chennai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Satheesh S
New User
Joined: 25 Apr 2008 Posts: 9 Location: Chennai
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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:
Unless i missed something, the 40000th entry works. . .
Also, there were no diagnostic messages in the compile. |
|
Back to top |
|
|
sreenigacc
New User
Joined: 16 Oct 2007 Posts: 15 Location: bangalore
|
|
|
|
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:
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
sreenivasulu G,
to quote a year-and-a-half old post:
Quote: |
Dude, you really need to read the manual |
|
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
See the definition of Index-name in the Language Reference Manual. All will be revealed to the diligent. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|