I am working on a SORT card and have come to a point where I would need some advise to proceed further.
Also I did some searching within the forum but could not find a topic addressing my query. Althouhg threre were quite a few with very close requirement.
Requirement:
- Eliminate records/header/trailer under header not equal to '01'
- Retain just the first header, if there are multiple header = '01' sets.
- Sum up position 15,5 and 20,6 in the trailer record for header = '01' and create a new trailer record.
- Final output should be sorted on (1,1,CH,A,2,10,CH,A)
Input file attributes: LRECL = 40 and FB
Jcl (with input file and attempted sort card is below):
Code:
//STEP1 EXEC PGM=SORT
//SORTIN DD *
01(HEADEY)
1C(DETAILS OF 1ST FILE - REC1)
1D(DETAILS OF 1ST FILE - REC2)
1A(DETAILS OF 1ST FILE - REC3)
99XTRAILER 00003000410
02(HEADEO)
11(DETAILS OF 2ND FILE - REC1)
11(DETAILS OF 2ND FILE - REC2)
99XTRAILER 00002000345
02(HEADEO)
11(DETAILS OF 3RD FILE - REC1)
11(DETAILS OF 3RD FILE - REC2)
11(DETAILS OF 3RD FILE - REC3)
99XTRAILER 00002000345
01(HEADEY)
1B(DETAILS OF 4TH FILE - REC1)
1E(DETAILS OF 4TH FILE - REC2)
1G(DETAILS OF 4TH FILE - REC3)
99XTRAILER 00003000510
01(HEADEY)
1F(DETAILS OF 5TH FILE - REC1)
1H(DETAILS OF 5TH FILE - REC2)
1I(DETAILS OF 5TH FILE - REC3)
99XTRAILER 00003000710
/*
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,1,CH,A,
2,10,CH,A)
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'01'),
END=(1,2,CH,EQ,C'99'),
PUSH=(41:ID=1)),
IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'99',AND,41,1,ZD,NE,1),
PUSH=(42:15,11))
The sort card was perfect and works for my query. Thanks !!
I just had to change the first OMIT cond a bit.
It would be "AND,41,<4>,ZD,NE,1 " as your id was of 4 byte long. I am sure that was just a typo.
In parallel I was working working on improving my approach as well and had come up with a better version what I posted initially, but it ain't perfect yet.
In the outfil statement I am trying to construct a new trailer using the data from the other "qualifying" trailers and then omit the individual "qualifying" trailer to retain just the new one created.
But, the problem is when OMIT is used along with TRAILER1, it seems OMIT happens first and as a result the new TOT function in the trailer is returning zero as the sum.
Output:
Code:
01(HEADEY)
1A(DETAILS OF 1ST FILE - REC3)
1B(DETAILS OF 4TH FILE - REC1)
1C(DETAILS OF 1ST FILE - REC1)
1D(DETAILS OF 1ST FILE - REC2)
1E(DETAILS OF 4TH FILE - REC2)
1F(DETAILS OF 5TH FILE - REC1)
1G(DETAILS OF 4TH FILE - REC3)
1H(DETAILS OF 5TH FILE - REC2)
1I(DETAILS OF 5TH FILE - REC3)
99XTRAILER 00000000000
Any suggestion how to make this approach work. Just want to know for my learning.
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
yuvrajdutta wrote:
Hello Arun,
The sort card was perfect and works for my query. Thanks !!
You're welcome. Good to hear it worked for you. I assumed that there may be duplicates on 1,11 for at least some detail records and had a separate counter to handle it.
I would like to appreciate your effort that you have tried something yourself. As you have already figured out, the OMIT happens first and you would not have those "qualifying" trailers to build a final TRAILER1.
I encountered another scenario while working on creating this sort card and thought would discuss it here.
I had a slight change in requirement, where the count and hash total values of the trailer falls in line with the file key (1,11).
New Input file:
Code:
01(HEADEY)
1C(DETAILS OF 1ST FILE - REC1)
1D(DETAILS OF 1ST FILE - REC2)
1A(DETAILS OF 1ST FILE - REC3)
1K(DETAILS OF 1ST FILE - REC4)
99X00004000410
02(HEADEO)
11(DETAILS OF 2ND FILE - REC1)
11(DETAILS OF 2ND FILE - REC2)
99X00002000345
02(HEADEO)
11(DETAILS OF 3RD FILE - REC1)
11(DETAILS OF 3RD FILE - REC2)
11(DETAILS OF 3RD FILE - REC3)
99X00002000345
01(HEADEY)
1B(DETAILS OF 4TH FILE - REC1)
1E(DETAILS OF 4TH FILE - REC2)
1G(DETAILS OF 4TH FILE - REC3)
99X00003000510
01(HEADEY)
1F(DETAILS OF 5TH FILE - REC1)
1H(DETAILS OF 5TH FILE - REC2)
1I(DETAILS OF 5TH FILE - REC3)
99X00003000710
In this case, if the the trailer record count (column 4 through 8) of the files
are different, the present sort card is unable to 'SUM' the fields as the key fields become different. Below is the output.
Output:
Code:
01(HEADEY)
1A(DETAILS OF 1ST FILE - REC3)
1B(DETAILS OF 4TH FILE - REC1)
1C(DETAILS OF 1ST FILE - REC1)
1D(DETAILS OF 1ST FILE - REC2)
1E(DETAILS OF 4TH FILE - REC2)
1F(DETAILS OF 5TH FILE - REC1)
1G(DETAILS OF 4TH FILE - REC3)
1H(DETAILS OF 5TH FILE - REC2)
1I(DETAILS OF 5TH FILE - REC3)
1K(DETAILS OF 1ST FILE - REC4)
99X00006001220
99X00004000410
To fix the issues I changed the sort card as below.
I am copying col 1 - 11 at the end of the file at position 64, then making this column identical (11C'9') for the trailer records to SUM up on the file key, which sitting at the end of the file after modification through INREC statement.
Output comes out as desired:
Code:
01(HEADEY)
1A(DETAILS OF 1ST FILE - REC3)
1B(DETAILS OF 4TH FILE - REC1)
1C(DETAILS OF 1ST FILE - REC1)
1D(DETAILS OF 1ST FILE - REC2)
1E(DETAILS OF 4TH FILE - REC2)
1F(DETAILS OF 5TH FILE - REC1)
1G(DETAILS OF 4TH FILE - REC3)
1H(DETAILS OF 5TH FILE - REC2)
1I(DETAILS OF 5TH FILE - REC3)
1K(DETAILS OF 1ST FILE - REC4)
99X00010001630
But, in doing so I end up coding file key(s) which are beyond the file LRECL of 40. From the perspective of achieving the end result the solution is fine, however I was just wondering if there is a workaround to still include the file key 1,11 for sorting in the changed scenario.