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
 

 

initialize for subscript variables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
divya_maddi

New User


Joined: 03 Nov 2005
Posts: 33

PostPosted: Mon Jul 16, 2007 3:11 pm    Post subject: initialize for subscript variables
Reply with quote

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
View user's profile Send private message

William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Mon Jul 16, 2007 3:27 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Sandy Zimmer

Active Member


Joined: 13 Jun 2007
Posts: 826
Location: Wilmington, DE

PostPosted: Mon Jul 16, 2007 3:44 pm    Post subject:
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Mon Jul 16, 2007 6:59 pm    Post subject:
Reply with quote

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
View user's profile Send private message
IQofaGerbil

Active User


Joined: 05 May 2006
Posts: 183
Location: Scotland

PostPosted: Mon Jul 16, 2007 8:01 pm    Post subject: Re: initialize for subscript variables
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon Jul 16, 2007 9:28 pm    Post subject:
Reply with quote

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 icon_smile.gif ).
Back to top
View user's profile Send private message
IQofaGerbil

Active User


Joined: 05 May 2006
Posts: 183
Location: Scotland

PostPosted: Tue Jul 17, 2007 12:43 pm    Post subject: Re: initialize for subscript variables
Reply with quote

Thanks for the clarification Dick.
Like I said - long time ago!

Is that method more efficient than looping?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Jul 17, 2007 3:22 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Tue Jul 17, 2007 6:19 pm    Post subject:
Reply with quote

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 icon_redface.gif
Back to top
View user's profile Send private message
karthikumar1

New User


Joined: 03 May 2007
Posts: 1
Location: chennai

PostPosted: Wed Jul 18, 2007 4:54 pm    Post subject:
Reply with quote

yes,


thanks 4 ur reply...
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 DB2 9.1.0 not move values to Host-Var... Miguel Fernandez DB2 8 Wed Jan 25, 2017 8:24 pm
No new posts DB2 9.1.0 not move values to Host-Var... Miguel Fernandez DB2 0 Wed Jan 25, 2017 8:23 pm
No new posts DB2 9.1.0 not move values to Host-Var... Miguel Fernandez DB2 0 Wed Jan 25, 2017 8:21 pm
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts Is it possible to pass variables of s... Csongor CLIST & REXX 2 Fri Jun 10, 2016 7:33 pm


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