View previous topic :: View next topic
|
Author |
Message |
Chris Chapel
New User
Joined: 11 Sep 2007 Posts: 10 Location: Marshfield, WI
|
|
|
|
Without declaring a "variable-length" table via the ODO clause, does IBM Enterprise COBOL offer a construct similar to the Micro Focus COBOL code-block below. Essentially the "78" level definition is similar to an EQU in IBM HLASM.
Thanks for any assistance.
Regards,
Chris Chapel
Below is some code from Micro Focus that really makes coding like this easy. If the size changes, you change in one place vs. having to look all over the program to see where it’s used!!!
Code: |
*-----------------------------------------------------
* TABLE: SOURCE CODES...
*-----------------------------------------------------
78 MAX-TBL-SIZE VALUE 10000.
01 TABLE-SOURCE-CODES.
05 TBL-SRCE-CDS OCCURS MAX-TBL-SIZE TIMES
INDEXED BY SRCE-INX.
10 TBL-SRCE-CD PIC X(20).
10 TBL-CNT PIC S9(9) COMP-3 VALUE 0.
...
IF NBR-OF-TBL-ENTRIES > MAX-TBL-SIZE
DISPLAY 'TABLE OVERFLOW ENCOUNTERED '
MOVE 2000 TO WS2-ABEND-CODE
PERFORM 9999-ABEND
END-IF |
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
If you hard-code the maximum OCCURS, you can dynamically calculate MAX-TBL-SIZE by issuing -
Code: |
COMPUTE MAX-TBL-SIZE = (LENGTH OF TABLE-SOURCE-CODES /
LENGTH OF TBL-SRCE-CDS (1)).
|
Regards, |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Chris,
If you're seeing programs where the 10000 is hard-coded all over the procedure division, you're looking at poor coding practices, not a defect of COBOL. Use the method illustrated by Bill. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello Chris and welcome to the forum,
As has been mentioned, there should not be a hard-coded value
"all over the code".
To do what you want, simply change the 78 to a 77 with a value of 10000.
Code: |
77 MAX-TBL-SIZE VALUE 10000.
|
Then change the array to something like:
Code: |
01 TABLE-SOURCE-CODES.
05 TBL-SRCE-CDS OCCURS n1 TO n2 TIMES
DEPENDING ON MAX-TBL-SIZE
INDEXED BY SRCE-INX.
10 TBL-SRCE-CD PIC X(20).
10 TBL-CNT PIC S9(9) COMP-3 VALUE 0.
|
Possibly there is something i've misunderstood? |
|
Back to top |
|
|
Chris Chapel
New User
Joined: 11 Sep 2007 Posts: 10 Location: Marshfield, WI
|
|
|
|
Dick,
I believe this is the implementation that I was searching for. I've never used 77-level declarations in IBM Enterprise COBOL. Assuming this code snippet will work in my environment (I have no doubt), are there inheirent inefficiencies with the ODO versus static array (static at compile-time based on Micro Focus's 78-level declaration)?
Thank you all for your time, knowledge and patience.
Regards,
Chris. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
You're welcome
Quote: |
are there inheirent inefficiencies with the ODO |
Not that i'm aware of. The object/load module will be allocated at the max possible size (static) which might make it larger but on today's systems a bit of extra working-storage is not an issue. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Chris,
Be aware that in Dick's example, the compiler will set aside program memory to allow for n2 entries no matter what value is in MAX-TBL-SIZE. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Also, using Bill's calculation, MAX-TBL-SIZE doesn't even need an initial value, so the only value that needs to change when changing the size of the table is the value in the occurs clause. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
For the most efficient method, define MAX-TBL-SIZE as a binary-fullword as well as add SRCE-INX-MAX (as a second index) to the array definition.
After calculating MAX-TBL-SIZE, set SRCE-INX-MAX to this binary-fullword and you're done.
Regards, |
|
Back to top |
|
|
|