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

efficient table copy in COBOL


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

Active User


Joined: 31 Oct 2006
Posts: 131
Location: brisbane

PostPosted: Sun May 26, 2013 4:32 am
Reply with quote

Hi,

I need to initialize a 64x64 table with constant values, each being in range 00 to 63. My target data structure (which I CAN'T change) looks like:

Code:
01  OUT-GROUP-MULT-1-0001RG.
    03 OUT-GROUP-MULT-1-0001MA   PIC S9(4)
    03 OUT-GROUP-MULT-1-0001MX   REDEFINES
       OUT-GROUP-MULT-1-0001MA   PIC X(4).
    03 OUT-GROUP-MULT-1-0001   OCCURS 64.
       05 OUT-GROUP-MULT-1-0001AC  PIC X(1).
       05 OUT-GROUP-MULT-2-0002RG.
         07  OUT-GROUP-MULT-2-0002MA PIC S9(4).
         07  OUT-GROUP-MULT-2-0002MX REDEFINES
                OUT-GROUP-MULT-2-0002MA PIC X(4).
         07  OUT-GROUP-MULT-2-0002  OCCURS 64.
            09  OUT-GROUP-MULT-2-0002AC  PIC X(1)
            09  OUT-GROUP-MULT-ITEM-0001EV.
               11  IEF-SUPPLIED-0001ET.
                  13 COUNT-0001AS  PIC X(1).
                  13 COUNT-0001   PIC S9(9). <====THIS IS WHERE THE VALUES GO.
                  13 COUNT-0001XX REDEFINES COUNT-0001 PIC X(9).



this table get's initialized, and then i need to map the constant values into count-0001.


my approach is do initialize a simpler structure, then copy from this to the target. Eg use something like:


Code:
       01  RS1-TABLE.
* there will be 128 filler rows
            05  FILLER   PIC X(32)     VALUE "14323555......3223".
            05  FILLER   PIC X(32)     VALUE "01020304......6565".
            05  FILLER   PIC X(32)     VALUE "84854954......6544".
...   
            05  FILLER   PIC X(32)     VALUE "01020366......0910".
        01  RS2-TABLE REDEFINES RS1-TABLE
            05  RS2-ROW OCCURS 64 TIMES.
                10  RS2-COL OCCURS 64 TIMES.
                    15  RS2-VALUE  PIC 99.



This will probably work OK, but is there a more elegant / more efficient solution?

Code'd and aligned somewhat
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sun May 26, 2013 1:21 pm
Reply with quote

Please use the Code tags to preserve space, use the Preview button to review until correct before posting. Do not use tabs.

All three tables are different lengths. The values that you have are for what purpose? I may be being dense, but I don't see how anything in your second table (except OCCURS 64) relates to your first table.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sun May 26, 2013 6:34 pm
Reply with quote

In COBOL, you can intiialize a table manually (which in your case would require 4096 MOVE statements per variable), or use VALUE statements as you have posted, or you can read the table values from a file and load them into the table. Your posted solution is as good as the other two.

Quote:
This will probably work OK, but is there a more elegant / more efficient solution?
Elegance is in the eye of the beholder, so that part of your question is not answerable. And in this time of mainframes running tens of millions to hundreds of millions of COBOL statements per second of CPU time, why would you even think of efficiency at this point? The ONLY time you should EVER be concerned with efficiency is if the program is not completing within the amount of time it has for execution -- period.
Back to top
View user's profile Send private message
AntonioS

New User


Joined: 27 Mar 2012
Posts: 8
Location: EU

PostPosted: Sun May 26, 2013 7:07 pm
Reply with quote

As Bill already stated, in the code you posted, the field formats do not match. This means that you would fill your array element by element at its lowest level which I find neither elegant nor efficient. :-)

My approach would be to use loop to fill the first 64 inner elements, then move the first outer element to the remainder of the array, like so:

Code:
 
repeat varying i-inner from 1 by 1
until i-inner > 64
  compute COUNT-0001 (1 i-inner) = i-inner - 1
end-repeat

repeat varying i-outer from 2 by 1
until i-outer > 64
  move OUT-GROUP-MULT-2-0002 (1) to OUT-GROUP-MULT-2-0002 (i-outer)
end-repeat



An additional structure would not necessarily be required for this. Of course, if you need to do the initialization multiple times, it may be advisable to use an additional structure, so the first loop needs to be executed only once.

HTH!
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 Replace each space in cobol string wi... COBOL Programming 2
No new posts Load new table with Old unload - DB2 DB2 6
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top