Author: ameetmund
Subject: Compare two files and subtract values
Posted: Fri Mar 31, 2017 3:35 pm (GMT 5.5)
I have a typical requirement. I have to compare two files File A & File B.Both the files are having lenght as 125.Only when the amount value is different for same key, then the output file should be written from File B. But before writing the record to output file, the amount value need to be subtracted and final value should be written to output file.
File A -
A123 1000.00
B123 1500.00
C123 4000.00
File B -
A123 500.00
B123 2500.00
C123 6000.00
O/P file -
A123 -500.00
B123 1000.00
C123 2000.00
I have used the following SORT card, where I am using first 4 characters as the key. I am trying to subtract the value of amount field which is at 75th position in my file. But it doesn't give me the desired value.
//SYSIN DD *
SORT FIELDS=COPY
JOINKEYS F1=IN1,FIELDS=(1,4,A)
JOINKEYS F2=IN2,FIELDS=(1,4,A)
JOIN UNPAIRED,F2,ONLY
REFORMAT FIELDS=(F2:1,125,F1:1,125)
OUTREC FIELDS=(1:1,74,
75:200,8,PD,SUB,75,8,PD,TO=PD,LENGTH=8,
83,43)
I referred IBM manual and other links to get information about it, but could not get the right information. Please suggest any idea to resolve this.
Subject: Compare two files and subtract values
Posted: Fri Mar 31, 2017 3:35 pm (GMT 5.5)
I have a typical requirement. I have to compare two files File A & File B.Both the files are having lenght as 125.Only when the amount value is different for same key, then the output file should be written from File B. But before writing the record to output file, the amount value need to be subtracted and final value should be written to output file.
File A -
A123 1000.00
B123 1500.00
C123 4000.00
File B -
A123 500.00
B123 2500.00
C123 6000.00
O/P file -
A123 -500.00
B123 1000.00
C123 2000.00
I have used the following SORT card, where I am using first 4 characters as the key. I am trying to subtract the value of amount field which is at 75th position in my file. But it doesn't give me the desired value.
//SYSIN DD *
SORT FIELDS=COPY
JOINKEYS F1=IN1,FIELDS=(1,4,A)
JOINKEYS F2=IN2,FIELDS=(1,4,A)
JOIN UNPAIRED,F2,ONLY
REFORMAT FIELDS=(F2:1,125,F1:1,125)
OUTREC FIELDS=(1:1,74,
75:200,8,PD,SUB,75,8,PD,TO=PD,LENGTH=8,
83,43)
I referred IBM manual and other links to get information about it, but could not get the right information. Please suggest any idea to resolve this.