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 

Sort file, keys in different position for different layouts

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 620
Topics: 173
Location: Stockholm, Sweden

PostPosted: Wed Jun 03, 2020 12:12 am    Post subject: Sort file, keys in different position for different layouts Reply with quote

Since I'm working (or not) as a consultant without a contract at the moment, I'm not able to even try testing this on the mainframe. I'm sure an answer is out there, but I've googled phrases such as "dfsort sort key variable position" without success. Okay, here's what I would like to sort.

Assume I've done an unload of a DL/1 database (using a Cobol program and not a utility) containing segments A, B and C.
A is the root segment and B and C are children to A.
Assume the key field in A is account (number), and that the unload (via a Cobol program rather than an IMS utility) has ensured that the account from A has ALSO been written to
segment records B and C. The resulting file might look something like this:-

Code:

A       00001      ACCOUNT4
B       00002                     ACCOUNT4
B       00003                     ACCOUNT4
C       00004                                    ACCOUNT4
C       00005                                    ACCOUNT4
A       00006      ACCOUNT1
B       00007                     ACCOUNT1


The account number positions above will thus be 20 for segment A, 35 for segment B
and 50 for segment C.

In the text shown above, column 1-8 contains the segment name, 9-13 contains a simple sequence number for each
successive record written to disk (not actually sure if I need that in fact).

What I want to do is to be able to sort the records in segment name order.
WITHIN segment names, the individual records should be sorted in ascending account number order.

The end result would be:-

Code:

A       00001      ACCOUNT1
A       00006      ACCOUNT4
B       00007                     ACCOUNT1
B       00002                     ACCOUNT4
B       00003                     ACCOUNT4
C       00004                                    ACCOUNT4
C       00005                                    ACCOUNT4


The file is VB, so what I believe I'm saying is that I want to sort the file
in positions 5-12 (?), if pos 5-12 contains an A, THOSE should be sorted based on
position 24, if a B, then sorted on position 39, and finally, if a C, then on position 54.

How would I go about this?
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Wed Jun 03, 2020 4:19 am    Post subject: Reply with quote

As it is an extract and not an unload why not have the extract add an extra field at the beginning of each record to hold the account number, sort on that and remove it in the output phase of sort?
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 620
Topics: 173
Location: Stockholm, Sweden

PostPosted: Wed Jun 03, 2020 11:59 am    Post subject: Reply with quote

Hmmmm, that seems like a simple, good idea. Smile

The logic behind it is that I want to be able to perform regression testing in a DL/1 to DB2 conversion where both databases are updated by the same transaction. On that basis, I want to be able "dump" the DL/1 segments in such a manner that they "resemble" the dumped DB2 rows (I'll leave it at that without going into more details, since that would probably only muddy the waters).

Thanks Nic. (sometimes you can't see the wood for the trees)

If I ever get a new contract and can test it, I will.
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Wed Jun 03, 2020 1:13 pm    Post subject: Reply with quote

misi01,

It is quite simple. All you have to do is checking for the segment name and put the sorting key in a common place. Since the input is a VB file, you cannot add the temp field at the end of the record as it will ruin the Varible length concept.

We would overcome that issue by adding the temp fields right after the RDW. So by doing that we actually moved the contents to the right by the size of the key. In this case I assumed the account number to be 8 bytes.

I added temp field(8 spaces) using WHEN=INIT right after the RDW and by doing so the original contents are moved to position 13.

For "A" type records the account number would be at 24+8 = 32
For "B" type records the account number would be at 39+8 = 47
For "C" type records the account number would be at 54+8 = 62

Now using WHEN=A we overlay position 5 with contents from position 32.

Similarly you do the same for other types.

Now it is just a matter of SORTING the keys on the SEGMENT and Account number at position 5.

After SORTING you remove the temp sort field and build the record from position 13 so that you retain the original Variable length records as is

The following is a DFSORT JCL which will give you the desired results
Code:

//STEP0100 EXEC PGM=SORT                                             
//SYSOUT   DD SYSOUT=*                                               
//SORTIN   DD DISP=SHR,DSN=Your Input VB IMS Unload file
//SORTOUT  DD SYSOUT=*                                               
//SYSIN    DD *                                                       
                                                                     
  INREC IFTHEN=(WHEN=INIT,                                           
         BUILD=(01,04,                    $ RDW                       
                8X,                       $ SPACES FOR SORT KEY       
                5)),                      $ RECORD AS IS             
                                                                     
        IFTHEN=(WHEN=(13,1,CH,EQ,C'A'),   $ IF A                     
       OVERLAY=(05:32,08)),               $ SORTKEY = POSITION 32     
                                                                     
        IFTHEN=(WHEN=(13,1,CH,EQ,C'B'),   $ IF B                     
       OVERLAY=(05:47,08)),               $ SORTKEY = POSITION 47     
                                                                     
        IFTHEN=(WHEN=(13,1,CH,EQ,C'C'),   $ IF C                     
       OVERLAY=(05:62,08))                $ SORTKEY = POSITION 62     
                                                                     
  SORT FIELDS=(13,08,CH,A,                $ SEGMENT                   
               05,08,CH,A),               $ ACCOUNT                   
               EQUALS                     $ RETAIN DUP ORDER         
                                                                     
  OUTREC BUILD=(01,04,                    $ RDW                       
                13)                       $ RECORD AS IS             
/*   



Nic,

You really don't have to add the key at the beginning and then remove it. You can do it all in a single pass.
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Wed Jun 03, 2020 2:09 pm    Post subject: Reply with quote

Kolusu

I was suggesting adding it in the program that created the data in the first place so it would be one pas of both programs as is your solution.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 620
Topics: 173
Location: Stockholm, Sweden

PostPosted: Wed Jun 03, 2020 2:48 pm    Post subject: Reply with quote

Hey guys, I'm grateful for both suggestions.

Nic's because it was so simple and Kolusu's because I'm damn sure I'll need the concept at some time in the future.
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities 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