View previous topic :: View next topic
|
Author |
Message |
divya_maddi
New User
Joined: 03 Nov 2005 Posts: 33
|
|
|
|
I have the following declarations:
Code: |
10 DSC-TBL-MAX-SIZE PIC 9(5) VALUE 2000 COMP-3.
10 T-DSC-PKG.
12 T-DSC-PKG-TABLE.
15 T-DSC-TABLE OCCURS 2000 TIMES
ASCENDING T-DSC-PKG-ID
INDEXED BY T-DSC-NDX.
20 T-DSC-KEY.
25 T-DSC-PKG-ID PIC X(04).
20 T-DSC-DATA.
25 T-DSC-TIER-CTR PIC 9(05) COMP-3.
25 T-DSC-BIE-CTR PIC S9(05) COMP-3.
25 T-DSC-OVR-CTR PIC S9(05) COMP-3. |
We are performing the following loop for some thousands of records.
Code: |
PERFORM VARYING SUB1 FROM 1 BY 1
UNTIL SUB1 > DSC-TBL-MAX-SIZE
MOVE HIGH-VALUES TO T-DSC-KEY (SUB1)
MOVE ZERO TO T-DSC-TIER-CTR (SUB1)
MOVE ZERO TO T-DSC-BIE-CTR (SUB1)
MOVE ZERO TO T-DSC-OVR-CTR (SUB1)
END-PERFORM.
|
Is there any other way of initializing without using the perform so that the CPU time usage is reduced? Let me know. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Code: |
MOVE HIGH-VALUES TO T-DSC-KEY (1)
MOVE ZERO TO T-DSC-TIER-CTR (1)
MOVE ZERO TO T-DSC-BIE-CTR (1)
MOVE ZERO TO T-DSC-OVR-CTR (1)
SET T-DSC-NDX TO 1
PERFORM DSC-TBL-MAX-SIZE TIMES
MOVE T-DSC-TABLE (1)
TO T-DSC-TABLE (T-DSC-NDX)
SET T-DSC-NDX UP BY 1
END-PERFORM. |
|
|
Back to top |
|
|
Sandy Zimmer
Active Member
Joined: 13 Jun 2007 Posts: 826 Location: Wilmington, DE
|
|
|
|
I like subscripts much better than an index - easier to find in a dump too.
Code: |
10 DSC-TBL-MAX-SIZE PIC s9(5) COMP-3 value 2000.
10 TBL-SUB PIC s9(5) COMP-3 value zero.
10 TBL-ENTRIES PIC s9(5) COMP-3 value zero.
10 T-DSC-PKG.
12 T-DSC-PKG-TABLE.
15 T-DSC-TABLE OCCURS 0 to 2000 TIMES
DEPENDING ON TBL-Entries
20 T-DSC-KEY.
25 T-DSC-PKG-ID PIC X(04).
20 T-DSC-DATA.
25 T-DSC-TIER-CTR PIC 9(05) COMP-3.
25 T-DSC-BIE-CTR PIC S9(05) COMP-3.
25 T-DSC-OVR-CTR PIC S9(05) COMP-3. |
So, the table initially is empty. It will only take up the space for the actual number of entries. You will perform your routine checking your subscript against table entries. If you only have 5 entries, that is the number of times you perform your routine. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
If you have the flexiblity to change, you can make the COMP-3s COMPs. Then move low values to T-DSC-PKG-TABLE to init the table.
The downside: you get low vals in your PIC X and spend 8 bytes instad of 5 for your numerics. |
|
Back to top |
|
|
IQofaGerbil
Active User
Joined: 05 May 2006 Posts: 183 Location: Scotland
|
|
|
|
It's a long time since I coded Cobol tables but I seem to recall that we would set up the initial values in a separate group
eg
Code: |
01 T-DSC-PKG-INIT.
20 T-DSC-KEY.
25 T-DSC-PKG-ID-INIT PIC X(04) VALUE HIGH-VALUES.
20 T-DSC-DATA.
25 T-DSC-TIER-CTR-INIT PIC 9(05) COMP-3 VALUE ZEROS.
25 T-DSC-BIE-CTR-INIT PIC S9(05) COMP-3 VALUE ZEROS.
25 T-DSC-OVR-CTR-INIT PIC S9(05) COMP-3 VALUE ZEROS.
|
then simply do one move statement which initialised the entire table.
eg
Code: |
MOVE T-DSC-PKG-INIT TO T-DSC-TABLE
|
does that not work anymore? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
MOVE T-DSC-PKG-INIT TO T-DSC-TABLE |
I believe that will pad the table with blanks after the first occurrence.
What we did was quite similar, though.
Code: |
01 THE-WHOLE-WORKS.
10 I-DSC-PKG-INIT.
20 I-DSC-KEY.
25 I-DSC-PKG-ID-INIT PIC X(04) VALUE HIGH-VALUES.
20 I-DSC-DATA.
25 I-DSC-TIER-CTR-INIT PIC 9(05) COMP-3 VALUE ZEROS.
25 I-DSC-BIE-CTR-INIT PIC S9(05) COMP-3 VALUE ZEROS.
25 I-DSC-OVR-CTR-INIT PIC S9(05) COMP-3 VALUE ZEROS.
10 THE-ACTUAL-TABLE.
15 T-DSC-TABLE OCCURS 2000 TIMES
ASCENDING T-DSC-PKG-ID
INDEXED BY T-DSC-NDX.
20 T-DSC-KEY.
25 T-DSC-PKG-ID PIC X(04).
20 T-DSC-DATA.
25 T-DSC-TIER-CTR PIC 9(05) COMP-3.
25 T-DSC-BIE-CTR PIC S9(05) COMP-3.
25 T-DSC-OVR-CTR PIC S9(05) COMP-3. |
Then
Code: |
MOVE THE-WHOLE-WORKS TO THE-ACTUAL-TABLE |
should initialize all of the table entries. This works whether the code uses an index or a subscript.
It works because of the way the MOVE operates - one byte at a time (unless that has somehow been changed ). |
|
Back to top |
|
|
IQofaGerbil
Active User
Joined: 05 May 2006 Posts: 183 Location: Scotland
|
|
|
|
Thanks for the clarification Dick.
Like I said - long time ago!
Is that method more efficient than looping? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Dick,
If you meant
MOVE THE-WHOLE-WORKS TO THE-ACTUAL-TABLE
rather than
MOVE THE-WHOLE-WORKS TO THE-TABLE,
I'll agree, the right to left overlapping move will do it.
Kinda slick, I've used overlapping moves to clear storage in assembler but never thought of the COBOL application.
One warning though, this will only (mostly) work on 360 type mainframes....
I've got an old war story about an innocent overlapping move in a COBOL program that was being converted to a System/3....Took a long time to identify that bug.... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Is that method more efficient than looping? |
Yes, especially if these counters have to be re-initialized many times in a run. The suggestion i posted uses only 1 move statement - other approaches require multiple instructions per iteration.
Thanks Bill - the type is fixed - fingers took a nap |
|
Back to top |
|
|
karthikumar1
New User
Joined: 03 May 2007 Posts: 1 Location: chennai
|
|
|
|
yes,
thanks 4 ur reply... |
|
Back to top |
|
|
|