Posted: Thu Jul 01, 2021 11:31 am Post subject: Merging two files into one file at different positions
Hi All,
I have two files as below
File1: Rec len - 300
key1 - 1,5
File2; Rec len - 200
key2 - 6,5
I want to have single file as below. no matching need to be done.
Output file structure:
1st byte - A - for file1 record/B for file2 record
2 to 4 - AAA if Key1 is 111 for file1 record(mutiple keys and mapping is there)/BBB if Key2 for file2(mutiple keys and mapping is there)
5 to 304 - Place file 1 records in this position
305 to 504 - Place file 2 records in this position.
to explain the process first file1 records need to be written into output file
with
1 - A
2 to 4 - AAA
5 to 304 - file1 record
305 to 504 - spaces
then file2 records need to be written into output file as below
1 - B
2 to 4 - BBB
5 to 304 - spaces
305 to 504 - file2 record.
Please help me with suitable job if this can be done in SORT.
Sorry if this is duplicate post and similar problem is already answered, please guide me to the post, I already searched but couldn't find any such.
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Thu Jul 01, 2021 12:54 pm Post subject: Re: Merging two files into one file at different positions
psmadhusudhan wrote:
Hi All,
I want to have single file as below. no matching need to be done.
Output file structure:
1st byte - A - for file1 record/B for file2 record
2 to 4 - AAA if Key1 is 111 for file1 record(mutiple keys and mapping is there)/BBB if Key2 for file2(mutiple keys and mapping is there)
5 to 304 - Place file 1 records in this position
305 to 504 - Place file 2 records in this position.
psmadhusudhan,
Your requirement does NOT make any sense. You preface your requirement with NO matching need to be done, but then your desired output mentions that you need a single Long file of 504 bytes with contents from file 1 + File-2
Output record = 504
Code:
file-1 data | file-2 data
So without a MATCHING how do you plan to append the file-1 record to file-2 record?
is the match on record by record basis? ie. 1st record of file-1 will be merged with 1st record of file-2 and 2nd with 2nd record and so on?
or do you merge every record of file-1 with every record of file-2 which will result in a Cartesian join? like file-1 has 10 records and file-2 has 10 records then the output will be 10 X 10 = 100 records.
You initially specify a key but then it is not used any where. Do you need to match on key?
What is the RECFM of File-1 and file-2 ?
Can you also show an sample input and desired output? _________________ Kolusu
www.linkedin.com/in/kolusu
I am sorry Kolusu if my wordings didn't explain my requirments clearly.
So I am writing control cards below through which I haave achieved the results but in 3 steps,
these can give an idea about my requirement.
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Fri Jul 02, 2021 10:08 am Post subject:
psmadhusudhan,
Sigh ! I sincerely wish you paid attention to the questions posted earlier. I asked about the RECFM of the file and a sample data, however you did not provide either of them.
Either way use the following DFSORT JCL which will give you the results assuming that the input files have RECFM=FB
Code:
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//INA DD DISP=SHR,DSN=Your Input file of LRECL 300
//INB DD DISP=SHR,DSN=Your Input file of LRECL 200
//SORTOUT DD DSN=Your output file LRECL 510,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(CYL,(X,Y),RLSE)
//SYSIN DD *
OPTION COPY
JOINKEYS F1=INA,FIELDS=(1,2,A),SORTED,NOSEQCK
JOINKEYS F2=INB,FIELDS=(1,2,A),SORTED,NOSEQCK
JOIN UNPAIRED
REFORMAT FIELDS=(F1:001,305, $ FILE-1 RECORD
F2:001,205, $ FILE-2 RECORD
?) $ MATCH IND
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum