|
View previous topic :: View next topic
|
| Author |
Message |
sthirumalai
New User
.jpg)
Joined: 14 Aug 2007 Posts: 14 Location: Chennai
|
|
|
|
Hi
I got a requirement which is explained below
File1: My input file looks like this
| Code: |
XX000100.10
XX000500.34
XX000678.23
XX000099.42
YY000578.98
YY000728.00
ZZ000356.89
ZZ178728.90 |
Requirement:
When the first two byte code breaks(i.e. changes from XX to YY) a tag 'EC' need to be inserted on the last XX record.
after the logic my file should look like
| Code: |
XX000100.10
XX000500.34
XX000678.23
XX000099.42EC
YY000578.98
YY000728.00EC
ZZ000356.89
ZZ178728.90EC |
Is there a way to do this in DFSORT?
Your help is appreciated.
Code'd |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
sthirumalai,
Use the following DFSORT JCL which will give you the desired results. The trick here is to use the same file twice and match on the seqnum.
I assumed that your input is RECFM=FB and LRECL=80
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//INA DD *
XX000100.10
XX000500.34
XX000678.23
XX000099.42
YY000578.98
YY000728.00
ZZ000356.89
ZZ178728.90
//INB DD *
XX000100.10
XX000500.34
XX000678.23
XX000099.42
YY000578.98
YY000728.00
ZZ000356.89
ZZ178728.90
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS F1=INA,FIELDS=(81,8,A),SORTED,NOSEQCK
JOINKEYS F2=INB,FIELDS=(81,8,A),SORTED,NOSEQCK
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:1,80,F2:1,2,?)
INREC IFOUTLEN=80,
IFTHEN=(WHEN=(1,2,CH,NE,81,2,CH,OR,83,1,ZD,EQ,1),OVERLAY=(12:C'EC'))
//*
//JNF1CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD)
//*
//JNF2CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD,START=0)
//* |
The output from this is
| Code: |
XX000100.10
XX000500.34
XX000678.23
XX000099.42EC
YY000578.98
YY000728.00EC
ZZ000356.89
ZZ178728.90EC
|
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
This is worth fully understanding, rather than just poking it into production cos it works.
It took me some time to get it, so here's what I came to. Hope I got it all :-)
Don't be confused by all the 81s. There are two different sets of them.
The two JNFnCNTL files add a sequence number to each record, but the sequence number is "off by one" between the two files. The main file (F1) has the larger sequence number (default start for sequence number is one), and that is important.
The JOINKEYS matches on the sequence number.
After that point, forget the sequence number, it is irrelevant.
The REFORMAT takes the whole F1 record and the first two bytes of the F2 record, the key.
These two bytes on the REFORMAT record start at position 81.
Now the single REFORMAT record contains "current" record and "next" record key. When "current" and "next" keys are different, the "current" is the last of that key.
Everything goes smoothly until the last record on F1, which doesn't match to a sequence number on F2. No problem, that is what the UNPAIRED,F1 is for. The ? match marker will have a value of "1", which will indicate end of group, and indeed end-of-file if that is required.
Thanks Kolusu, that is useful, not only in itself, but also for thinking about how to do other things. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Partly so that interested parties get to see the edits, I'll add that the technique has also been used to keep running-totals for records by key and a somewhat esoteric "delete duplicates without sorting" (which can be done with ICETOOL anyway).
For anything which requires the presence of data/keys at the same time from consecutive records, this technique can be considered. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|