Joining two files with SORT.
Joining two files with SORT.
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?
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?
Last edited by Anuj Dhawan on Tue Sep 06, 2016 10:14 pm, edited 2 times in total.
Reason: Added code tags.
Reason: Added code tags.
Re: Joining two files with SORT.
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?
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.
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)
On you next question on Variable file, what is the maximum length of input record ? And what is the maximum length of output record ?
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)
/*
Re: Joining two files with SORT.
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.
-
- Global Moderator
- Posts: 588
- Joined: Wed Nov 20, 2013 11:53 am
- Location: Mars
Re: Joining two files with SORT.
Roohi,
I would suggest : Overlay sequence numbers in both files and then do a join keys
I would suggest : Overlay sequence numbers in both files and then do a join keys
zprogrammer
Re: Joining two files with SORT.
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.
-
- Global Moderator
- Posts: 588
- Joined: Wed Nov 20, 2013 11:53 am
- Location: Mars
Re: Joining two files with SORT.
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
Check the spool for Joinkey, you will see three outputs.
Code: Select all
SYSOUT
JNF1JMSG
JNF2JMSG
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
-
- Global Moderator
- Posts: 588
- Joined: Wed Nov 20, 2013 11:53 am
- Location: Mars
Re: Joining two files with SORT.
Magesh_j,
You are yet to answer my question => why is Join keys not recommended for this situation ?
You are yet to answer my question => why is Join keys not recommended for this situation ?
zprogrammer
Re: Joining two files with SORT.
zprogrammer,
Because three pass is unnecessary, where something can be achieved in two pass which would be an optimal solution.
thanks
Magesh
Because three pass is unnecessary, where something can be achieved in two pass which would be an optimal solution.
thanks
Magesh
- enrico-sorichetti
- Global Moderator
- Posts: 843
- Joined: Wed Sep 11, 2013 3:57 pm
Re: Joining two files with SORT.
the TS stated clearly that
I have two files which have just one-one record each.
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute