|
View previous topic :: View next topic
|
| Author |
Message |
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
Hi, I have input file with group of records. Group started with HDR word. Within group the word CTL indicate control. :
| Code: |
000001 HDR 1234 <----FIRST GROUP
000002 INF 1111
000003 INF 2222
000004 CTL AAAA CONTROL
000005 INF 1111
000006 HDR 0034 <----SECOND GROUP
000007 INF 1111
000008 INF 1111
000009 INF 2222
000010 CTL BBBB CONTROL
000011 INF 1111
000012 INF 1111 |
I need to add info from Control record to each record in the group:
Input file:
| Code: |
000001 HDR 1234
000002 INF 1111
000003 INF 2222
000004 CTL AAAA
000005 INF 1111
000006 HDR 0034
000007 INF 1111
000008 INF 1111
000009 INF 2222
000010 CTL BBBB
000011 INF 1111
000012 INF 1111 |
Output file:
| Code: |
000001 HDR 1234 AAAA
000002 INF 1111 AAAA
000003 INF 2222 AAAA
000004 CTL AAAA AAAA
000005 INF 1111 AAAA
000006 HDR 0034 BBBB
000007 INF 1111 BBBB
000008 INF 1111 BBBB
000009 INF 2222 BBBB
000010 CTL BBBB BBBB
000011 INF 1111 BBBB
000012 INF 1111 BBBB
|
File is FB 80 . Is it possible by sort/icetool? Thanks. |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Does 'HDR' start in position 1 or in position 8 (are the sequence numbers really in the input file)?
Is there only one CTL record per group? |
|
| Back to top |
|
 |
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
| Hi Frank, HDR is in position 1, CTL is only one per group, groups may be more than 100, there is no numering in the file, it is from Edit panel |
|
| Back to top |
|
 |
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
Actuaally I've tried to use this:
| Code: |
//STEP020 EXEC PGM=SORT,PARM='SIZE(MAX)'
//SORTIN DD *
HDR 1234
INF 1111
INF 2222
CTL AAAA
INF 1111
HDR 0034
INF 1111
INF 1111
INF 2222
CTL BBBB
INF 1111
INF 1111
//SORTOUT DD DSN=IS.SOUT,DISP=OLD
//BAD DD DSN=IS.SEXT,DISP=OLD
//FIN DD DSN=IS.SFIN,DISP=OLD
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'HDR'),
PUSH=(60:ID=4))
OUTFIL FNAMES=BAD,INCLUDE=(1,3,CH,EQ,C'CTL')
JOINKEYS F1=SORTOUT,FIELDS=(60,4,A)
JOINKEYS F2=BAD,FIELDS=(60,4,A)
REFORMAT FIELDS=(F1:1,80,F2:1,80)
OUTFIL FNAMES=FIN,BUILD=(1,10,X,86,4,80:X)
// |
but looks like the code :
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'HDR'),
PUSH=(60:ID=4))
OUTFIL FNAMES=BAD,INCLUDE=(1,3,CH,EQ,C'CTL') |
was not executed. If code above is in separate step it run ok |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, you can't do it exactly like that. The INREC etc would operate after the JOIN and you can't create the file for the join like that.
What you need is JNFnCNTL datasets for additional control cards, one for each dataset:
//JNF1CNTL DD *
//JNF2CNTL DD *
You can then do a GROUP for each file (you specify, in this type of case, your dataset name on each input to the join) and establish an ID which you will match on.
In one JNF1CNTL add (OVERLAY) a number to your "record" when you identify your control record. BUILD just the data you want to add, the ID and the "1" and SUM on the ID. Out of this CNTL you'll get all IDs with data if present and either 0 or 1.
On the other CNTL just output your record with the ID. This CNTL you don't need to let do the SORT, so put SORTED,NOSEQCK (check spelling of last) on the JOINKEYS. Overlay the ID at the end (if fixed records).
Do the join on the IDs.
REFORMAT to include all of the whole file and the data and 0/1 from the other file.
Interrogate the 0/1, update current record, if a 1, use the data, else don't.
Should be about there if you want a hack at it. |
|
| Back to top |
|
 |
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
| wow... looks complicated for me ... maybe I will stay with 2 steps. Thanks |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
It isn't complicated and it won't look that way, really it won't :-)
Search the DFSORT forum for JOINKEYS by user Skolusu, you'll find examples of the "matching a file to itself" and see what they look like.
If you just sit around anyway, you may get a solution later, of course. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You could look at this.
The requirement was more complex than yours. |
|
| Back to top |
|
 |
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
| Thank you |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
anatol,
It isn't that complicated. Assuming you ALWAYS have 1 and ONLY CTL record per group , the following DFSORT JCL will give you the desired results. The trick here is to use the same file twice and from the second file pick only the CTL records and attach a seqnum which will be matched with the GROUP ID from file 1. Since we are building the match key , we know it is sorted so you can join the records as if you are copying.
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//INA DD *
HDR 1234
INF 1111
INF 2222
CTL AAAA
INF 1111
HDR 0034
INF 1111
INF 1111
INF 2222
CTL BBBB
INF 1111
INF 1111
//INB DD *
HDR 1234
INF 1111
INF 2222
CTL AAAA
INF 1111
HDR 0034
INF 1111
INF 1111
INF 2222
CTL BBBB
INF 1111
INF 1111
//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
REFORMAT FIELDS=(F1:1,10,F2:6,4,F1:15,66)
//*
//JNF1CNTL DD *
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'HDR'),PUSH=(81:ID=8))
//*
//JNF2CNTL DD *
INCLUDE COND=(1,3,CH,EQ,C'CTL')
INREC OVERLAY=(81:SEQNUM,8,ZD)
//* |
|
|
| Back to top |
|
 |
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
| Thank you... great trick |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|