MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Table manipulation to create an "outline" style re

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Mainframe Challenge
View previous topic :: View next topic  
Author Message
dtf
Beginner


Joined: 10 Dec 2004
Posts: 110
Topics: 8
Location: Colorado USA

PostPosted: Tue Dec 14, 2004 3:03 pm    Post subject: Table manipulation to create an "outline" style re Reply with quote

Assume that you have a table that is defined as

Code:
01 TABLE-AREA.
     05  TABLE-ELEMENT       PIC X(10)  OCCURS 100 TIMES
                                        INDEXED BY TE-INDEX. 


Now assume that you have the table loaded with data and you know the following:

1. The contents of the table contain a module call trace such that the first two
Characters will contain
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Dec 15, 2004 5:04 am    Post subject: Reply with quote

dtf,

Here is my solution:
Code:

       IDENTIFICATION DIVISION.                                       
       PROGRAM-ID.    CHALNG7.                                       
       AUTHOR.        PHANTOM.                                       
       DATE-WRITTEN.  DECEMBER 2004.                                 
      *                                                               
       ENVIRONMENT DIVISION.                                         
       CONFIGURATION SECTION.                                         
       SOURCE-COMPUTER. IBM-370.                                     
       OBJECT-COMPUTER. IBM-370.                                     
       DATA DIVISION.                                                 
      *                                                               
       WORKING-STORAGE SECTION.                                       
       01  TABLE-AREA.                                               
           05  TABLE-ELEMENT         PIC X(10)  OCCURS 100 TIMES     
                                                INDEXED BY TE-INDEX. 
       01  OUTPUT-LINE               PIC X(80).                       
       01  WS-LEADING-SPACES.                                         
           05  WS-LSPACES            PIC X(05)  OCCURS 0 TO 10       
                                     DEPENDING  ON WS-INDENT-CNT.   
       01  WS-PROGRAM-NAME.                                         
           05  ENTRY-RETURN-IND      PIC X(02).                     
           05  FILLER                PIC X(04).                     
           05  SEQ-NO                PIC 9(04).                     
       01  CNT                       PIC 9(04).                     
       01  WS-INDENT-CNT             PIC 9(04).                     
       PROCEDURE DIVISION.                                           
       0000-MAIN-ROUTINE.                                           
XXXXXX     PERFORM 0100-LOAD-TABLE  THRU 0100-EXIT                   
           PERFORM VARYING CNT FROM 1 BY 1 UNTIL CNT > 100 OR       
                                  TABLE-ELEMENT(CNT) = HIGH-VALUES   
                MOVE SPACES                  TO  OUTPUT-LINE         
                MOVE TABLE-ELEMENT(CNT)      TO  WS-PROGRAM-NAME     
                COMPUTE WS-INDENT-CNT        =   SEQ-NO - 1         
                MOVE SPACES                  TO  WS-LEADING-SPACES   
                STRING WS-LEADING-SPACES DELIMITED BY SIZE           
                WS-PROGRAM-NAME   DELIMITED BY SIZE INTO OUTPUT-LINE
                DISPLAY OUTPUT-LINE                                 
           END-PERFORM                                       
           STOP RUN.                                         
XXXXXX*                                                     
XXXXXX 0100-LOAD-TABLE.                                     
XXXXXX     SET TE-INDEX TO +1                               
XXXXXX     MOVE 'E-PROG0001' TO TABLE-ELEMENT(TE-INDEX)     
XXXXXX     SET TE-INDEX UP BY +1                             
XXXXXX     MOVE 'E-PROG0002' TO TABLE-ELEMENT(TE-INDEX)     
XXXXXX     SET TE-INDEX UP BY +1                             
XXXXXX     MOVE 'E-PROG0003' TO TABLE-ELEMENT(TE-INDEX)     
XXXXXX     SET TE-INDEX UP BY +1                             
XXXXXX     MOVE 'R-PROG0003' TO TABLE-ELEMENT(TE-INDEX)     
XXXXXX     SET TE-INDEX UP BY +1                             
XXXXXX     MOVE 'E-PROG0003' TO TABLE-ELEMENT(TE-INDEX)     
XXXXXX     SET TE-INDEX UP BY +1                             
XXXXXX     MOVE 'R-PROG0003' TO TABLE-ELEMENT(TE-INDEX)     
XXXXXX     SET TE-INDEX UP BY +1                             
XXXXXX     MOVE 'R-PROG0002' TO TABLE-ELEMENT(TE-INDEX)     
XXXXXX     SET TE-INDEX UP BY +1                             
XXXXXX     MOVE 'E-PROG0002' TO TABLE-ELEMENT(TE-INDEX)       
XXXXXX     SET TE-INDEX UP BY +1                               
XXXXXX     MOVE 'E-PROG0003' TO TABLE-ELEMENT(TE-INDEX)       
XXXXXX     SET TE-INDEX UP BY +1                               
XXXXXX     MOVE 'E-PROG0005' TO TABLE-ELEMENT(TE-INDEX)       
XXXXXX     SET TE-INDEX UP BY +1                               
XXXXXX     MOVE 'R-PROG0005' TO TABLE-ELEMENT(TE-INDEX)       
XXXXXX     SET TE-INDEX UP BY +1                               
XXXXXX     MOVE 'R-PROG0003' TO TABLE-ELEMENT(TE-INDEX)       
XXXXXX     SET TE-INDEX UP BY +1                               
XXXXXX     MOVE 'R-PROG0002' TO TABLE-ELEMENT(TE-INDEX)       
XXXXXX     SET TE-INDEX UP BY +1                               
XXXXXX     MOVE 'R-PROG0001' TO TABLE-ELEMENT(TE-INDEX)       
XXXXXX     SET TE-INDEX UP BY +1                               
XXXXXX     MOVE HIGH-VALUES  TO TABLE-ELEMENT(TE-INDEX).       
XXXXXX 0100-EXIT. EXIT.                                       


Note: In the above code, the lines with tag 'XXXXXX' should not be considered since they are used to load your TABLE and you said we need to assume that the table is already loaded.

So, eliminating the Table-Loading code, I think I have completed the request in 27 lines (Working Storage + Procedure Div).

Thanks,
Phantom
Back to top
View user's profile Send private message
dtf
Beginner


Joined: 10 Dec 2004
Posts: 110
Topics: 8
Location: Colorado USA

PostPosted: Wed Dec 15, 2004 8:59 am    Post subject: Reply with quote

Phantom,

Yes a workable solution -- good job!

Don't know if I am supposed to give hints or not but I beleive there is what I think is a more "elegant" which involves no use of STRING or ODO but rather uses manipulation of indexes. It is something that I stumbled on many years ago quite by accident. The downside of my solution which I will post tomorrow, is that it appears on the surface to be incorrect, and requires some documentation for understanding. Given that, some will think it a poor solution. The upside of it though is that when you understand how it works, you gain a clear understanding of the inner workings of COBOL indexes. Smile
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Thu Dec 16, 2004 6:31 am    Post subject: Reply with quote

dtf,

Code:

Yes a workable solution -- good job!


Thank U.

Code:

The upside of it though is that when you understand how it works, you gain a clear understanding of the inner workings of COBOL indexes


Excellent. I'm eager to see your solution.

Thanks,
Phantom
Back to top
View user's profile Send private message
dtf
Beginner


Joined: 10 Dec 2004
Posts: 110
Topics: 8
Location: Colorado USA

PostPosted: Thu Dec 16, 2004 10:37 am    Post subject: Reply with quote

Code:

       IDENTIFICATION DIVISION.                                       
       PROGRAM-ID.    CHALNG7.                                       
       AUTHOR.        DTF.                                           
       DATE-WRITTEN.  DECEMBER 2004.                                 
      *                                                               
       ENVIRONMENT DIVISION.                                         
       CONFIGURATION SECTION.                                         
       SOURCE-COMPUTER. IBM-370.                                     
       OBJECT-COMPUTER. IBM-370.                                     
       DATA DIVISION.                                                 
      *                                                               
       WORKING-STORAGE SECTION.                                       
000001 01  TABLE-AREA.                                               
000002     05  TABLE-ELEMENT                    OCCURS 100 TIMES     
000003                                          INDEXED BY TE-INDEX. 
000004         10  FILLER            PIC XX.                         
000005             88  UPON-ENTRY    VALUE 'E-'.                     
000006         10  FILLER            PIC X(08).                       
000007     05  PIC X(05)  OCCURS 1   INDEXED BY OE-INDEX.             
000008 01  OUTPUT-LINE.                                                 
000009     05  OUTPUT-ELEMENT        PIC X(10)  OCCURS 8.               
       PROCEDURE DIVISION.                                             
       0000-MAIN-ROUTINE.                                               
XXXXXX     PERFORM 0100-LOAD-TABLE  THRU 0100-EXIT                     
000010     SET OE-INDEX TO 1                                           
000011     SET OE-INDEX DOWN BY 1                                       
000012     PERFORM VARYING TE-INDEX FROM 1 BY 1 UNTIL TE-INDEX > 100 OR
000013                            TABLE-ELEMENT(TE-INDEX) = HIGH-VALUES
000014          MOVE SPACES                  TO  OUTPUT-LINE           
000015          IF UPON-ENTRY(TE-INDEX)                                 
000016             SET OE-INDEX UP BY 1                                 
000017          END-IF                                                 
000018          MOVE TABLE-ELEMENT(TE-INDEX) TO OUTPUT-ELEMENT(OE-INDEX)
000019          IF NOT UPON-ENTRY(TE-INDEX)                             
000020             SET OE-INDEX DOWN BY 1                               
000021          END-IF                                                 
000022          DISPLAY OUTPUT-LINE                                     
000023     END-PERFORM                                                 
            STOP RUN.                                           
 XXXXXX*                                                       
 XXXXXX 0100-LOAD-TABLE.                                       
 XXXXXX     MOVE 'E-PROG0001' TO TABLE-ELEMENT(01)             
 XXXXXX     MOVE 'E-PROG0002' TO TABLE-ELEMENT(02)             
 XXXXXX     MOVE 'E-PROG0003' TO TABLE-ELEMENT(03)             
 XXXXXX     MOVE 'R-PROG0003' TO TABLE-ELEMENT(04)             
 XXXXXX     MOVE 'E-PROG0003' TO TABLE-ELEMENT(05)             
 XXXXXX     MOVE 'R-PROG0003' TO TABLE-ELEMENT(06)             
 XXXXXX     MOVE 'R-PROG0002' TO TABLE-ELEMENT(07)             
 XXXXXX     MOVE 'E-PROG0002' TO TABLE-ELEMENT(08)             
 XXXXXX     MOVE 'E-PROG0003' TO TABLE-ELEMENT(09)             
 XXXXXX     MOVE 'E-PROG0005' TO TABLE-ELEMENT(10)             
 XXXXXX     MOVE 'R-PROG0005' TO TABLE-ELEMENT(11)             
 XXXXXX     MOVE 'R-PROG0003' TO TABLE-ELEMENT(12)             
 XXXXXX     MOVE 'R-PROG0002' TO TABLE-ELEMENT(13)             
 XXXXXX     MOVE 'R-PROG0001' TO TABLE-ELEMENT(14)             
 XXXXXX     MOVE HIGH-VALUES  TO TABLE-ELEMENT(15).             
 XXXXXX 0100-EXIT. EXIT.                                       


The interesting thing here is the use of "OE-INDEX". There may be a problem if you have the compile option set that does range checking since at one point the index gets set to zero, and it also gets set to values exceeding its definition. This could be avoided by using some kind of first time flag since it is only set to zero for a "first time" task, and actually redefining the output table and giving the OE-INDEX 16 occurrences.

What is really fascinating is that what ever the length of the field is associated with the index is what determines the displacement. So for instance if you change that FILLER length to 2, you'd end up with offsets of 2 instead of 5 when you ran the program.

As I said, I found this out several years ago by making a mistake of using the wrong index for a table item. The results of that intrigued me, and I actually ended up using it in a tool that I wrote that does something similar to the call trace in this sample problem.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Mainframe Challenge All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group