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).
05 FILLER OCCURS 999999 TIMES.
10 WS-PLAN PIC X(08).
10 WS-MEMBER PIC 9(07).
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
MOVE WS-FILLER ( 1 : W-LENGTH-OF-FIRST-OCCURENCE )
TO WS-FILLER ( W-START-OF-REMAINING-TABLE : )