Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
Hi all,
I have a requirement as i need to compare two files based on a condition and I have to insert a field from second file to the first file,
Here is an example:
Input file 1:
Code:
S.No:1
Name: ABC
Age:20
Sex: male
Accnum: 12345
S.No:2
Name: DEF
Age:21
Sex: male
Accnum: 67890
S.No:3
Name: ZDE
Age:25
Sex: male
Accnum: 99945
Input file 2:
Code:
12345 QWE
67890 POI
56862 QWE
My output should be:
Code:
S.No:1
Name: ABC QWE
Age:20
Sex: male
Accnum: 12345
S.No:2
Name: DEF POI
Age:21
Sex: male
Accnum: 67890
S.No:3
Name: ZDE
Age:25
Sex: male
Accnum: 99945
here i have to match the Accnum field (in both the input files 1 and 2) and if matched insert it after Name field (in file 1). Can someone help on this.
Note: The position of Name field and Accnum field are constant.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
So you have a file which contains fields instead of records? I bet someone thought that was a great idea.
You didn't answer the recently recused's question fully - is the first file, the groups of fields, in Accnum order?
Is there a limit to the number of fields making up these "distributed" records?
If so, in Cobol, it is just a modified two-file-match, storing the "distributed" record in a table, knowing where the Name is and adding it from the second file and flushing the table in the order it was stored.
If the first file is not in Accnum order, make it so.
In Syncsort, I don't know. I don't have documentation even.
If you can fully describe the file 1, how the combinations might appear, minimum/maximum no of fields per group. LRECL and RECFM.
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
Bill,
Input File-1:
File-1 has records in group. I'm not sure how many it may be. The group of records will start with S.no and end with ENDMSG. And also it is not defined as only S.no, Name, Age, Sex, Accnum will be in the group (this group may vary with records), As shown below
Code:
S.No:1
Name: ABC
Age:20
Sex: male
Accnum: 12345
ENDMSG
S.No:2
Name: DEF
Age:21
Sex: male
Addr: <Unknown>
Accnum: 67890
City: XX
State: YY
ENDMSG
S.No:3
Name: ZDE
Age:25
Sex: male
Accnum: 99945
Company: III
Code:87944555
ENDMSG
this file is sorted based on S.no. LRECL=80 RECFM=FB.
Input FILE-2:
File-2 has Accnum and Extname as shown below,
Code:
12345 QWE
67890 POI
56862 QWE
this file is sorted based on Accnum. Lrecl=80 and Recf=fb
My output:
i have to merge these two datasets with Accnum as basis. Once the Accnum matches I have to write the Extname from File-2 in Name field of File-1 as shown below,
Code:
S.No:1
Name: ABC QWE
Age:20
Sex: male
Accnum: 12345
ENDMSG
S.No:2
Name: DEF POI
Age:21
Sex: male
Addr: <Unknown>
Accnum: 67890
City: XX
State: YY
ENDMSG
S.No:3
Name: ZDE
Age:25
Sex: male
Accnum: 99945
Company: III
Code:87944555
ENDMSG
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
I finally connected current questions back to this topic, and reminded myself of the three weeks I spent (on-and-off, about four days) to get this into one JOINKEYS step, by which time it was a bit stale.
Started again from scratch this evening, for practice: