Joined: 02 Dec 2002 Posts: 620 Topics: 173 Location: Stockholm, Sweden
Posted: Wed Jun 03, 2020 12:12 am Post subject: Sort file, keys in different position for different layouts
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
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
Posted: Wed Jun 03, 2020 4:19 am Post subject:
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.
Joined: 02 Dec 2002 Posts: 620 Topics: 173 Location: Stockholm, Sweden
Posted: Wed Jun 03, 2020 11:59 am Post subject:
Hmmmm, that seems like a simple, good idea.
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
Joined: 26 Nov 2002 Posts: 12367 Topics: 75 Location: San Jose
Posted: Wed Jun 03, 2020 1:13 pm Post subject:
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
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
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
Posted: Wed Jun 03, 2020 2:09 pm Post subject:
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.
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