Thanks for replying so promptly Sri. I think I failed to make clear that the
header and trailer records have their key values in the same position as the F2
matching key, so I think the marking of the header and trailer are not needed.
I think the following (using your example) will get me what I need:
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//INA DD DISP=SHR,DSN=&&FB0040
//INB DD DISP=SHR,DSN=&&VB1000
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS F1=INA,FIELDS=(01,7,A) $ KEY
JOINKEYS F2=INB,FIELDS=(33,7,A) $ KEY
JOIN UNPAIRED,F2
REFORMAT FIELDS=(F2:1,4,?,F2:6)
INCLUDE COND=(5,1,CH,EQ,C'B',OR, $ MATCH KEYS
(34,7,CH,EQ,C'0000000',OR, $ HDROR
34,7,CH,EQ,C'9999999')) $ TRL
INREC BUILD=(1,4, $ RDW
6) $ DATA
/*
I'll report back on my results for the archives.
Thanks once again for your courteous and professional help.
Peter
-----Original Message-----
From: IBM Mainframe Discussion List [mailto:[email protected]] On Behalf
Of Sri h Kolusu
Sent: Monday, September 17, 2018 5:51 PM
To: [email protected]
Subject: Re: SORT JOIN help needed - matched F2 only plus unmatched F2 hdr/trlr?
EXTERNAL EMAIL
Peter,
You can get the unmatched header and trailer records from F2 file, but you
just need to handle it a bit differently. Since I don't have the input
data here is something that I made up. I assumed that the header is denoted by
all 0's in position 5 and trailer all 9's in position 5. Since you are matching
the keys the header and trailer may not be in their original positions, so in
order to preserve the position we need to tag the header as 0 and detail
records as 1 and the trailer record as 9.
//************************************************************
//* CREATE VB INPUT DATA WITH AN LRECL OF 1000 *
//************************************************************
//STEP0050 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
0000000 - HEADER RECORD
YYYYYYY
YYYYYYY
BBBBBBB
BBBBBBB
BBBBBBB
BBBBBBB
ZZZZZZZ
ZZZZZZZ
9999999 - TRAILER RECORD
//SORTOUT DD DSN=&&VB1000,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//SYSIN DD *
OPTION COPY
INREC OVERLAY=(996:X)
OUTFIL FTOV
//*
//************************************************************
//* CREATE FB INPUT DATA WITH AN LRECL OF 40 *
//************************************************************
//STEP0060 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
AAAAAAA
BBBBBBB
ZZZZZZZ
//SORTOUT DD DSN=&&FB0040,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//SYSIN DD *
OPTION COPY
INREC BUILD=(1,40)
//*
//************************************************************
//* RUN JOINKEYS TO PULL THE MATCHED DATA AND UNMATCHED *
//* HEADER AND TRAILER DATA *
//************************************************************
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//INA DD DISP=SHR,DSN=&&FB0040
//INB DD DISP=SHR,DSN=&&VB1000
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS F1=INA,FIELDS=(01,1,A, $ INDICATOR
02,7,A) $ KEY
JOINKEYS F2=INB,FIELDS=(05,1,A, $ INDICATOR
34,7,A) $ KEY
JOIN UNPAIRED,F2
REFORMAT FIELDS=(F2:1,4,?,F2:6)
INCLUDE COND=(5,1,CH,EQ,C'B',OR, $ MATCH KEYS
(5,1,CH,EQ,C'2',AND, $ IND = 2 AND
(6,7,CH,EQ,C'0000000',OR, $ HDROR
6,7,CH,EQ,C'9999999'))) $ TRL
INREC BUILD=(1,4, $ RDW
6) $ DATA
/*
//JNF1CNTL DD *
INREC BUILD=(C'1', $ DTL = 1
1,7) $ MATCHING KEY $ KEY
/*
//JNF2CNTL DD *
OPTION VLSHRT
INREC BUILD=(01,04, $ RDW
05,07,CHANGE=(1,C'0000000',C'0', $ HDR = 0
C'9999999',C'9'), $ TRL = 9
NOMATCH=(C'1'), $ DTL = 1
5) $ RECORD AS IS
/*
The output from this job is
0000000 - HEADER RECORD
BBBBBBB
BBBBBBB
BBBBBBB
BBBBBBB
ZZZZZZZ
ZZZZZZZ
9999999 - TRAILER RECORD
Hope this gives you the desired results you looking for
Thanks,
Kolusu
DFSORT Development
IBM Corporation
IBM Mainframe Discussion List <[email protected]> wrote on
09/17/2018 01:12:00 PM:
> From: "Farley, Peter x23353" <[email protected]>
> To: [email protected]
> Date: 09/17/2018 01:13 PM
> Subject: SORT JOIN help needed - matched F2 only plus unmatched F2
hdr/trlr?
> Sent by: IBM Mainframe Discussion List <[email protected]>
>
> Using the "Smart DFSORT Tricks" manual, section "No match, VB, key in
> different places, duplicates", I understand how to get the NOT matched
> records from file 2.
>
> I need to get the MATCHED records from file 2 plus the always-un-
> matched header and trailer records from file 2 in one output file.
>
> The basic task is matching a file of keys-to-be-included (F1) with a
> data file (F2) containing those keys in a different position with many
> possible duplicates. All duplicates in F2 are to be kept. The data
> file (F2) also contains a header (assume a key of all zeroes) and a
> trailer (assume a key of all 9's) that never match. Key length is 7
> bytes.
>
> This (modified) example from the PDF will get me the UN-matched F2
records:
>
> //JK8 EXEC PGM=SORT
> //SYSOUT DD SYSOUT=*
> //IN1 DD DSN=... input file1 (FB/40)
> //IN2 DD DSN=... input file2 (VB/1000) //SORTOUT DD DSN=... output
> file (VB/1000) //SYSIN DD * JOINKEYS F1=IN1,FIELDS=(1,7,A) JOINKEYS
> F2=IN2,FIELDS=(33,7,A) JOIN UNPAIRED,F2,ONLY OPTION COPY
> /*
>
> How do I get MATCHED records from F2 only plus unmatched header and
> trailer from F2 in one output file?
>
> TIA for any assistance you can offer.
>
> Peter
--
This message and any attachments are intended only for the use of the addressee
and may contain information that is privileged and confidential. If the reader
of the message is not the intended recipient or an authorized representative of
the intended recipient, you are hereby notified that any dissemination of this
communication is strictly prohibited. If you have received this communication
in error, please notify us immediately by e-mail and delete the message and any
attachments from your system.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN