Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Dynamic Table (Array) Definition similar to Micro Focus

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Dynamic Table (Array) Definition similar to Micro Focus
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Apr 02, 2009 10:22 pm    Post subject: Reply to: Dynamic Table (Array) Definition similar to Micro
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: 1239
Location: Richfield, MN, USA

PostPosted: Thu Apr 02, 2009 10:58 pm    Post subject:
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

Site Director


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

PostPosted: Fri Apr 03, 2009 12:28 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri Apr 03, 2009 1:32 am    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Fri Apr 03, 2009 1:33 am    Post subject:
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: 1239
Location: Richfield, MN, USA

PostPosted: Fri Apr 03, 2009 1:39 am    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Sat Apr 04, 2009 3:09 am    Post subject: Reply to: Dynamic Table (Array) Definition similar to Micro
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Dynamic array request/response contai... Suja.Sai CICS 2 Tue Jan 24, 2017 11:37 am
No new posts REXX DB2: Dynamic allocation of DB2.D... BHAS CLIST & REXX 3 Mon Dec 19, 2016 8:26 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Get system time in micro second or cl... lind sh CICS 11 Mon Sep 05, 2016 11:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us