Page 1 of 1
Joining two files with SORT.
Posted: Tue Sep 06, 2016 2:29 pm
by Roohi N
Hi,
I have two files which have just one-one record each. I need to combine them in a specific way. I shall try to explain them with example:
Let's say file one is: my.input.file1 with data 12345
file second is: my.input.file2 with data abcdef09876543
I want my output file should be as: 12345abcdef09876543
Can I do this using some SORT card?
Re: Joining two files with SORT.
Posted: Tue Sep 06, 2016 2:36 pm
by Roohi N
The files are both of logical length 80 and and fixed blocked.
I might get these files as variable block, can we still do it in SORT with variable block file?
Re: Joining two files with SORT.
Posted: Tue Sep 06, 2016 8:33 pm
by Magesh_j
Roohi,
what is the output LRECL ?
Whether fields you have are in fixed length or length varies ?
Assuming output LRECL=80 and All the fields have fixed length then use the below code and
you have only one record in each file.
File 1(1,5) and File2 (1,14)
Code: Select all
//SORT010 EXEC PGM=SORT
//SORTIN DD DSN=YOUR FIRST FILE
// DD DSN=YOUR SECOND IFLE
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY,STOPAFT=2
INREC IFTHEN=(WHEN=GROUP,RECORDS=2,PUSH=(81:1,5,SEQ=1))
OUTFIL INCLUDE(86,1,CH,EQ,C'2'),BUILD=(81,5,1,14,80:X)
/*
On you next question on Variable file, what is the maximum length of input record ? And what is the maximum length of output record ?
Re: Joining two files with SORT.
Posted: Tue Sep 06, 2016 9:37 pm
by nicc
There are NO files. They are data sets.
Re: Joining two files with SORT.
Posted: Tue Sep 06, 2016 9:39 pm
by Magesh_j
Nic,
Mistake, agreed Datasets.
Thanks
Magesh
Re: Joining two files with SORT.
Posted: Thu Sep 08, 2016 3:17 pm
by Roohi N
Magesh_j wrote: what is the output LRECL ?Whether fields you have are in fixed length or length varies ?Assuming output LRECL=80 and All the fields have fixed length then use the below code and you have only one record in each file.File 1(1,5) and File2 (1,14)
The datasets are both of logical length 80 and and fixed blocked.
Length of field is fixed for my case but the dataset's can be of RECFM=VB (this is a condiction we are expecting but as of now they are FB. THat's why I'm thimking for VB soluction too).
For VB, adding (1,4) should work but I'm still to get a VB file. Please advise.
Re: Joining two files with SORT.
Posted: Thu Sep 08, 2016 5:38 pm
by nicc
But what is the output dataset LRECL?
Re: Joining two files with SORT.
Posted: Thu Sep 08, 2016 7:42 pm
by zprogrammer
Roohi,
I would suggest : Overlay sequence numbers in both files and then do a join keys
Re: Joining two files with SORT.
Posted: Thu Sep 08, 2016 8:13 pm
by Magesh_j
zprogrammer wrote: Roohi,
I would suggest : Overlay sequence numbers in both files and then do a join keys
Joinkey consumes three pass. where the solution which i have provided consume only two pass.
For this situation join key is not at all recommended.
Roohi N.
For VB yes, you should use 1,4 (RDW), Also you need to know the maximum record length.
Re: Joining two files with SORT.
Posted: Thu Sep 08, 2016 8:51 pm
by zprogrammer
Magesh_j wrote: For this situation join key is not at all recommended.
Could you please prove it

Re: Joining two files with SORT.
Posted: Thu Sep 08, 2016 8:57 pm
by Magesh_j
zprogrammer,
Check the spool for Joinkey, you will see three outputs.
JNF1 => 1 Pass.
JNF2 => 1 Pass.
After Join => 1 pass.
ideally any DFSORT Joinkey will have three pass irrespective of JNF1CNTL/JNF2CNTL statements.
Also test my solution and you will see only one SYSOUT( ideally one pass) but since it is two file we concatenate it is considered as two pass solution.
Regards,
Magesh
Re: Joining two files with SORT.
Posted: Thu Sep 08, 2016 9:09 pm
by zprogrammer
Magesh_j,
You are yet to answer my question => why is Join keys not recommended for this situation ?
Re: Joining two files with SORT.
Posted: Thu Sep 08, 2016 9:30 pm
by Magesh_j
zprogrammer,
Because three pass is unnecessary, where something can be achieved in two pass which would be an optimal solution.
thanks
Magesh
Re: Joining two files with SORT.
Posted: Thu Sep 08, 2016 9:39 pm
by enrico-sorichetti
the TS stated clearly that
I have two files which have just one-one record each.