How to initialize the array/table in cobol ?

Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

How to initialize the array/table in cobol ?

Postby gauthamnagpur18 » Tue Aug 30, 2011 3:44 pm

Hi ,

I came across following code in production .

PERFORM VARYING I FROM 1 BY 1 UNTIL I > 999999
MOVE SPACES TO WS-PLAN(I)
MOVE ZEROES TO WS-MEMBER(I)
END-PERFORM.

Is there any alternate way to initialise ? so we can reduce cpu consumption. :)

Regards,
Gautham

These users thanked the author gauthamnagpur18 for the post:
vvkswm
gauthamnagpur18
 
Posts: 68
Joined: Sat Oct 23, 2010 1:28 pm

Re: How to initialize the array/table in cobol ?

Postby BillyBoyo » Tue Aug 30, 2011 5:39 pm

Is this known to be consuming lots of time?

What are the data definitions for the table?

Is the "idiotically named" "I" an Index?

How many times is this done in the program per run?

There are some alternatives, if you can answer the above.

These users thanked the author BillyBoyo for the post:
vvkswm
BillyBoyo
Global moderator
 
Posts: 2904
Joined: Tue Jan 25, 2011 12:02 am

Re: How to initialize the array/table in cobol ?

Postby gauthamnagpur18 » Wed Aug 31, 2011 7:30 am

Hi Billlyboyo ,

Ya it's consuming more than 5 mins of CPu time. :o

Declaration :

01 WS-FILLER.
05 FILLER OCCURS 999999 TIMES. :roll:
10 WS-PLAN PIC X(08).
10 WS-MEMBER PIC 9(07).

Thanks,
Gautham
gauthamnagpur18
 
Posts: 68
Joined: Sat Oct 23, 2010 1:28 pm

Re: How to initialize the array/table in cobol ?

Postby dick scherrer » Wed Aug 31, 2011 8:22 am

Hello,

You might consider the following:

Code: Select all
01  WS-FILLER-INIT.
    05 FIRST-ITEM.
       10 FILLER    PIC X(8) VALUE SPACES.
       10 FILLER    PIC 9(7) VALUE ZEROS.
    05 THE-REST-OF-THE-ITEMS PIC X(15) OCCURS 999998 TIMES.

01 WS-FILLER REDEFINES WS-FILLER-INIT.
    05 FILLER OCCURS 999999 TIMES. 
       10 WS-PLAN PIC X(08).
       10 WS-MEMBER PIC 9(07).

PROCEDURE DIVISION.
MOVE WS-FILLER-INIT TO THE-REST-OF-THE-ITEMS.


I've not done this for a while, but it has worked for many years - hopefully, it still will ;)

The cpu usage for the initialization will practically disappear. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am

Re: How to initialize the array/table in cobol ?

Postby BillyBoyo » Wed Aug 31, 2011 12:10 pm

Just first check that you are not doing the initialisation more often than required.

Also, why PIC 9(7)? If you are not calculating with it, why not X(7). If you are calculating with it, why not COMP-3?

Dick's is the technique I used for many years. I used a slightly different data definition, but the effects are identical.

Here, I have tried to "rework" the code to "modernise" it a bit, using "reference modification".

Unfortunately, I am unable to test it. Fortunately, it is very easy to test (use your existing loop, but include a test for each element for space or zero as appropriate).

The point in using the reference modification in this way it to avoid the problem with the other technique, which is someone changes the sizes of the table or items in it, and doesn't change the initialisation. This way, it should be automatic, and you can test that as well. It won't work automatically for adding a new field to the table :-), but then it is not magic!

Code: Select all
       
        01  W-DISPLAY-WHEN-COMPILED PIC X(8)BX(8).
        01  W-LENGTH-OF-FIRST-OCCURENCE COMP PIC S9(8).
        01  W-START-OF-REMAINING-TABLE COMP PIC S9(8).
        01 WS-FILLER.
           05 FILLER OCCURS 999999 TIMES. 
              10 WS-PLAN PIC X(08).
              10 WS-MEMBER PIC 9(07).
        PROCEDURE DIVISION.
            MOVE WHEN-COMPILED TO W-DISPLAY-WHEN-COMPILED
            DISPLAY "yourprogramnamehere " W-DISPLAY-WHEN-COMPILED

* this block of code initialises a table at "one shot". It may be put in a prargraph/section and performed as often as needed.

            MOVE SPACE TO WS-PLAN ( 1 )
            MOVE ZERO TO WS-MEMBER ( 1 )

            COMPUTE W-LENGTH-OF-FIRST-OCCURENCE = LENGTH OF WS-PLAN
                                                + LENGTH OF WS-MEMBER
            COMPUTE W-START-OF-REMAINING-TABLE
                       = W-LENGTH-OF-FIRST-OCCURENCE
                       + 1

            MOVE WS-FILLER ( 1 : W-LENGTH-OF-FIRST-OCCURENCE )
                            TO WS-FILLER ( W-START-OF-REMAINING-TABLE : )
BillyBoyo
Global moderator
 
Posts: 2904
Joined: Tue Jan 25, 2011 12:02 am

Re: How to initialize the array/table in cobol ?

Postby BillyBoyo » Wed Aug 31, 2011 12:26 pm

Just thought, although you can't initialise automatically if someone adds an item to the table, you can discover that it has happened.

I'll leave you to do the code, from this:

Give your FILLER OCCURS a (meaningful) name.
Find the length of that new item.
Compare it to the length calculated for the first occurence by adding-up your fields.
If they are not equal, produce a diagnostic message and stop/abend.
BillyBoyo
Global moderator
 
Posts: 2904
Joined: Tue Jan 25, 2011 12:02 am

Re: How to initialize the array/table in cobol ?

Postby BillyBoyo » Wed Aug 31, 2011 2:50 pm

One last, thing. You can also look at the INITIALIZE verb in Cobol. It used to generate a loop to do it, but maybe worth checking for these days.

With the above technique, as with any of them, you don't have to initialise to space/zero, you can do it for any starting value.

Another posibility, with the chance that things are still slow, is to "initialise as you need". Initialise only the first occrence. Then when putting something in the first, you initilise the next. I don't think you'll need to use this, as the above should perform well enough, and makes it clear when you are looking at a dump that all the data belongs to the current situation. Doing "as you need" means leaving "old" data in place. Obviously your current subscript/index should never point to the old data, but in the dump you might start to wonder.

Also, were you using a subscript in your loop? If so, how was it defined?
BillyBoyo
Global moderator
 
Posts: 2904
Joined: Tue Jan 25, 2011 12:02 am

Re: How to initialize the array/table in cobol ?

Postby gauthamnagpur18 » Fri Sep 02, 2011 1:23 am

Hi Billyboyo ,

Thanks for detailed explaination . I will try out and let you know .

I also referred http://publib.boulder.ibm.com/infocenter/wdzinfo/v7r0/index.jsp?topic=/com.ibm.ent.cbl.zos.doc/topics/tpbeg10.htm in which they explained about initialisation of table. Hope it would be useful .

Thanks ,
Gautham :ugeek:

These users thanked the author gauthamnagpur18 for the post:
vvkswm
gauthamnagpur18
 
Posts: 68
Joined: Sat Oct 23, 2010 1:28 pm

Re: How to initialize the array/table in cobol ?

Postby wicherc » Tue Sep 04, 2012 12:56 am

Hi BillyBoyo!
I was looking for a solution to this problem and found this post.
May be an error in the sentence you wrote?

MOVE WS-FILLER ( 1 : W-LENGTH-OF-FIRST-OCCURENCE )
TO WS-FILLER ( W-START-OF-REMAINING-TABLE : )

I supose the subscript in the variable ws-filler is incomplete, isn´t it?
Thanks for your response.
wicherc
 
Posts: 7
Joined: Tue Sep 04, 2012 12:36 am

Re: How to initialize the array/table in cobol ?

Postby BillyBoyo » Tue Sep 04, 2012 1:23 am

Well, for a start, it is not subscripts that are being used... Have a look at the ":". Find out what it means.

You could test it yourself as well.
BillyBoyo
Global moderator
 
Posts: 2904
Joined: Tue Jan 25, 2011 12:02 am

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post