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

Dynamic Table (Array) Definition similar to Micro Focus


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

New User


Joined: 11 Sep 2007
Posts: 10
Location: Marshfield, WI

PostPosted: Thu Apr 02, 2009 9:48 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Apr 02, 2009 10:22 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


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

PostPosted: Thu Apr 02, 2009 10:58 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Apr 03, 2009 12:28 am
Reply with quote

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
View user's profile Send private message
Chris Chapel

New User


Joined: 11 Sep 2007
Posts: 10
Location: Marshfield, WI

PostPosted: Fri Apr 03, 2009 1:25 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Apr 03, 2009 1:32 am
Reply with quote

Hello,

You're welcome icon_smile.gif
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
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Fri Apr 03, 2009 1:33 am
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


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

PostPosted: Fri Apr 03, 2009 1:39 am
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sat Apr 04, 2009 3:09 am
Reply with quote

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
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 Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top