View previous topic :: View next topic
Author
Message
HameedAli Active User Joined: 16 Apr 2009Posts: 151 Location: India
Hi,
I have 2 files (File 1 and File 2).
I want to prepare File 3, based on the priority from File 1.
File1 - Priority File
Code:
----+----1
03
04
02
01
File2 - Details File
Code:
----+----1
ASDNASL01
ASDNASL02
ASDNASL03
ASDNASL04
KDVNLKN02
KDVNLKN04
In this case
I want to extract the row with the order of highest Priority
File3 - ExtractedDetails File
Code:
----+----1
ASDNASL03
KDVNLKN04
How to achieve this
Back to top
enrico-sorichetti Superior Member Joined: 14 Mar 2007Posts: 10873 Location: italy
when asking question it would be better to use a <neuter> terminology...
it makes easier for the people answering to interpret correctly Your question
since we take time to understand Your problem and providing a solution
the minimum You should do it is to spare us the time to translate Your organization jargon ....
how many records in file 1 ???
Back to top
HameedAli Active User Joined: 16 Apr 2009Posts: 151 Location: India
Will do so going forward.
Thanks for the advice.
File 1 contains max of 4 records (4 unique values).
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
Is file2 in sequence on the first nine bytes?
Back to top
HameedAli Active User Joined: 16 Apr 2009Posts: 151 Location: India
Yes, 7 (field 1) + 2 (field 2)
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
OK, the first step just takes file 1 and turns it into a symbol/SYMNAME for the later INCLUDE.
Produces:
Code:
REQUIRED-PRIORITY,C'01'
REQUIRED-PRIORITY,C'01,04'
REQUIRED-PRIORITY,C'01,04,03'
REQUIRED-PRIORITY,C'01,04,03,02'
Depending on the number of records on file 1 (the order does not matter, although you could "optimise" the order if you know which priority occurs the most to least on file 2).
The generated symbols from SORTOUT (temporary dataset) go into the SYMNAMES DD in the second step. SYMNOUT in that step will list the particular values used.
ICETOOL's SELECT operator is used to chose the LAST record of the key, The CTL1 contains the INCLUDE using the symbol generated, and uses COPY so the data does not get sorted by default.
Code:
//STEP0050 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD DSN=&&SYMNM,DISP=(,PASS),UNIT=SYSDA,SPACE=(TRK,1)
//SYSIN DD *
OPTION COPY,STOPAFT=4
INREC IFTHEN=(WHEN=INIT,OVERLAY=(20:SEQNUM,2,ZD,C'''',C',',80:X)),
IFTHEN=(WHEN=GROUP,BEGIN=(20,2,CH,EQ,C'01'),
PUSH=(3:1,2,22,1)),
IFTHEN=(WHEN=GROUP,BEGIN=(20,2,CH,EQ,C'02'),
PUSH=(5:23,1,1,2,22,1)),
IFTHEN=(WHEN=GROUP,BEGIN=(20,2,CH,EQ,C'03'),
PUSH=(8:23,1,1,2,22,1)),
IFTHEN=(WHEN=GROUP,BEGIN=(20,2,CH,EQ,C'04'),
PUSH=(11:23,1,1,2,22,1))
OUTFIL REMOVECC,NODETAIL,
TRAILER1=(C'REQUIRED-PRIORITY,C''',3,12)
//SORTIN DD *
01
04
03
//STEP0100 EXEC PGM=ICETOOL
//IN DD *
ASDNASL01
ASDNASL02
ASDNASL03
ASDNASL04
KDVNLKN02
KDVNLKN04
XYZAAAA01
XYZAAAA02
//OUT DD SYSOUT=*
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//SYMNOUT DD SYSOUT=*
//SYMNAMES DD DSN=&&SYMNM,DISP=(OLD,DELETE)
//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(1,7,CH) LAST USING(CTL1)
//CTL1CNTL DD *
SORT FIELDS=COPY
INCLUDE COND=(8,2,SS,EQ,REQUIRED-PRIORITY)
The output from the above is
Code:
ASDNASL04
KDVNLKN04
XYZAAAA01
Note that for XYZAAAA 01 and 02 exist, but 02 was not a selected "priority" so 01 is extracted (the 02 got ignored by the INCLUDE).
There are a couple of other ways of finding the "last" record for a key. If you file 2 is large, you might want to try all three to see which is the most effective for your data.
Back to top
HameedAli Active User Joined: 16 Apr 2009Posts: 151 Location: India
Thanks Bill
But the precedence should be given to
ASDNASL03 over ASDNASL04 as in my first example.
Whereas in your logic, only the last record is being extracted as ASDNASL04
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
Perhaps you didn't explain it so well.
Are you saying, "if 03 exists, give me that, else if 04 exists, give me that, else if 02 exists, give me that, else if 01 exists, give me that"?
File one is not "priorities", but shows the priority that you want the values to be applied in?
Back to top
HameedAli Active User Joined: 16 Apr 2009Posts: 151 Location: India
Exactly, as you mentioned.
The precedence is as follows.
For
ASDNASL01
ASDNASL02
ASDNASL03
ASDNASL04
ASDNASL03 should be extracted
For
ASDNASL01
ASDNASL02
ASDNASL04
ASDNASL04 should be extracted
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
Will there always be four records on file 1? You say both a "max" of four and "four unique values"?
Back to top
HameedAli Active User Joined: 16 Apr 2009Posts: 151 Location: India
Yes, max 4 and 4 unique values.
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
HameedAli,
Please don't just repeat what has already confused me.
A "maximum" implies that there is a "minimum".
Do you have four records on file 1, no more, no less?
You stress uniqueness, is that to be tested for? Otherwise not relevant.
Back to top
HameedAli Active User Joined: 16 Apr 2009Posts: 151 Location: India
Sorry to test your patience.
Quote:
Do you have four records on file 1, no more, no less?
yes
Quote:
You stress uniqueness, is that to be tested for? Otherwise not relevant.
Please ignore this
Back to top
Skolusu Senior Member Joined: 07 Dec 2007Posts: 2205 Location: San Jose
Use the following DFSORT JCL which will give you the desired results. I assumed that your extract file 1 has RECFM=FB and LRECL=80
Code:
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//INA DD *
----+----1----+----2----+----3----+----4-
ASDNASL01
ASDNASL02
ASDNASL03
ASDNASL04
KDVNLKN02
KDVNLKN04
//INB DD *
03
04
02
01
//SORTOUT DD SYSOUT=*
//SYSIN DD *
JOINKEYS F1=INA,FIELDS=(8,2,A)
JOINKEYS F2=INB,FIELDS=(1,2,A)
REFORMAT FIELDS=(F1:1,80,F2:3,1)
SORT FIELDS=(1,7,CH,A,81,1,CH,A)
OUTFIL REMOVECC,NODETAIL,BUILD=(80X),
SECTIONS=(1,7,HEADER3=(1,80))
//*
//JNF2CNTL DD *
OPTION STOPAFT=4
INREC OVERLAY=(3:SEQNUM,1,ZD)
//*
Back to top
HameedAli Active User Joined: 16 Apr 2009Posts: 151 Location: India
Skolusu,
Thanks a lot, it is working as expected.
Would you please explain how this works.
I am not able to understand the File2 manipulation.
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
It is very simple to try
Code:
JOINKEYS F1=INA,FIELDS=(8,2,A)
JOINKEYS F2=INB,FIELDS=(1,2,A)
REFORMAT FIELDS=(F1:1,80,F2:3,1,1,2)
If you run this, you will be able to see what has been "added" to the F2 record. Note that I've added the final '1,2' just so you can see which record gets which addition.
Back to top
Please enable JavaScript!