so my second example is the right one.
The DD-Statement "SORTOUT" will contain all records of the combined ED- and BX-files.
After that you could make three SORT-Steps or a ICETOOL-Step with three SORTs within it like I already posted before.
With the code I wrote here I think you already can begin to try out, if the results do match your needs.
I will try to sum up what I posted before, but I am currently at home (in my time zone it's nearly 7:00 pm), so I could not test anything of it and cannot guarantee that I did no mistakes
1. Build three temporary output files in dividing your driver-file:
//STEP1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//L1 DD DISP=SHR,DSN=USERID.VSAM.IN5
//BS DD DISP=OLD,DSN=USERID.VSAM.OUT1
//ED DD DISP=OLD,DSN=USERID.VSAM.OUT2
//NA DD DISP=OLD,DSN=USERID.VSAM.OUT3
//TOOLIN DD *
COPY FROM(L1) TO(BS) USING(CTL1)
COPY FROM(L1) TO(ED) USING(CTL2)
COPY FROM(L1) TO(NA) USING(CTL3)
/*
//CTL1CNTL DD *
SORT FIELDS=COPY
INCLUDE COND=(17,2,CH,EQ,C'BS')
/*
//CTL2CNTL DD *
SORT FIELDS=COPY
INCLUDE COND=(17,2,CH,EQ,C'ED')
/*
//CTL3CNTL DD *
SORT FIELDS=COPY
INCLUDE COND=(17,2,CH,EQ,C'NA')
/*
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//L1 DD DISP=SHR,DSN=USERID.VSAM.IN5
//BS DD DISP=OLD,DSN=USERID.VSAM.OUT1
//ED DD DISP=OLD,DSN=USERID.VSAM.OUT2
//NA DD DISP=OLD,DSN=USERID.VSAM.OUT3
//TOOLIN DD *
COPY FROM(L1) TO(BS) USING(CTL1)
COPY FROM(L1) TO(ED) USING(CTL2)
COPY FROM(L1) TO(NA) USING(CTL3)
/*
//CTL1CNTL DD *
SORT FIELDS=COPY
INCLUDE COND=(17,2,CH,EQ,C'BS')
/*
//CTL2CNTL DD *
SORT FIELDS=COPY
INCLUDE COND=(17,2,CH,EQ,C'ED')
/*
//CTL3CNTL DD *
SORT FIELDS=COPY
INCLUDE COND=(17,2,CH,EQ,C'NA')
/*
2. Join your BX and ED files:
//JOIN1 EXEC PGM=SORT
//SYMNAMES DD *
ED12KEY,1,19
BX12KEY,21,19
//SYSOUT DD SYSOUT=*
//ED12 DD DSN=USERID.VSAM.IN1,DISP=SHR
DD DSN=USERID.VSAM.IN2,DISP=SHR
//BX12 DD DSN=USERID.VSAM.IN3,DISP=SHR
DD DSN=USERID.VSAM.IN4,DISP=SHR
//SORTOUT DD DSN=USERID.VSAM.EDBXJOIN,DISP=OLD
//SYSIN DD *
OPTION COPY
JOINKEYS F1=ED1,FIELDS=(ED12KEY,A)
JOINKEYS F2=ED2,FIELDS=(BX12KEY,A)
/*
//SYMNAMES DD *
ED12KEY,1,19
BX12KEY,21,19
//SYSOUT DD SYSOUT=*
//ED12 DD DSN=USERID.VSAM.IN1,DISP=SHR
DD DSN=USERID.VSAM.IN2,DISP=SHR
//BX12 DD DSN=USERID.VSAM.IN3,DISP=SHR
DD DSN=USERID.VSAM.IN4,DISP=SHR
//SORTOUT DD DSN=USERID.VSAM.EDBXJOIN,DISP=OLD
//SYSIN DD *
OPTION COPY
JOINKEYS F1=ED1,FIELDS=(ED12KEY,A)
JOINKEYS F2=ED2,FIELDS=(BX12KEY,A)
/*
3. With your three driver files and some INREC FIELDS-Commands build whatever you want out of it
a) DFSORT
//BSDRIVER EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=USERID.BS.DRIVER.FILE,DISP=SHR
//SORTOUT DD DSN=USERID.FINAL.OUTPUT,DISP=(NEW,CATLG,DELETE)
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
//* Do the same for 'ED' and 'NA'
//EDDRIVER EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=USERID.ED.DRIVER.FILE,DISP=SHR
//SORTOUT DD DSN=USERID.FINAL.OUTPUT,DISP=MOD
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
//NADRIVER EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=USERID.NA.DRIVER.FILE,DISP=SHR
//SORTOUT DD DSN=USERID.FINAL.OUTPUT,DISP=MOD
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=USERID.BS.DRIVER.FILE,DISP=SHR
//SORTOUT DD DSN=USERID.FINAL.OUTPUT,DISP=(NEW,CATLG,DELETE)
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
//* Do the same for 'ED' and 'NA'
//EDDRIVER EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=USERID.ED.DRIVER.FILE,DISP=SHR
//SORTOUT DD DSN=USERID.FINAL.OUTPUT,DISP=MOD
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
//NADRIVER EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=USERID.NA.DRIVER.FILE,DISP=SHR
//SORTOUT DD DSN=USERID.FINAL.OUTPUT,DISP=MOD
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
b) ICETOOL
With ICETOOL you can make this in one step:
//BSDRIVER EXEC PGM=ICETOOL
//SYSOUT DD SYSOUT=*
//BSIN DD DSN=USERID.BS.DRIVER.FILE,DISP=SHR
//EDIN DD DSN=USERID.BS.DRIVER.FILE,DISP=SHR
//NAIN DD DSN=USERID.BS.DRIVER.FILE,DISP=SHR
//OUT1 DD DSN=USERID.FINAL.OUTPUT,DISP=(NEW,CATLG,DELETE)
//OUT2 DD DSN=USERID.FINAL.OUTPUT,DISP=MOD
//SYSIN DD *
COPY FROM(BSIN) TO(OUT1) USING(CTL1)
COPY FROM(EDIN) TO(OUT2) USING(CTL2)
COPY FROM(NAIN) TO(OUT2) USING(CTL3)
/*
//CTL1CNTL DD *
SORT FIELDS=COPY
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
//CTL2CNTL DD *
SORT FIELDS=COPY
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
//CTL3CNTL DD *
SORT FIELDS=COPY
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
//SYSOUT DD SYSOUT=*
//BSIN DD DSN=USERID.BS.DRIVER.FILE,DISP=SHR
//EDIN DD DSN=USERID.BS.DRIVER.FILE,DISP=SHR
//NAIN DD DSN=USERID.BS.DRIVER.FILE,DISP=SHR
//OUT1 DD DSN=USERID.FINAL.OUTPUT,DISP=(NEW,CATLG,DELETE)
//OUT2 DD DSN=USERID.FINAL.OUTPUT,DISP=MOD
//SYSIN DD *
COPY FROM(BSIN) TO(OUT1) USING(CTL1)
COPY FROM(EDIN) TO(OUT2) USING(CTL2)
COPY FROM(NAIN) TO(OUT2) USING(CTL3)
/*
//CTL1CNTL DD *
SORT FIELDS=COPY
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
//CTL2CNTL DD *
SORT FIELDS=COPY
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*
//CTL3CNTL DD *
SORT FIELDS=COPY
INREC FIELDS=(C'D,',1,8,C',',9,4, ..... and so on)
/*