Page 1 of 1

File Comparision Using SORT

PostPosted: Fri Dec 02, 2011 4:33 pm
by Vineet
Hi All,

I am having 2 Sequential Files Say File A (LRECL = 500) & File B(LRECL = 300). I need to Compare 2 Files based on Item Number. For File A Item Number Start Position is 01 & Item Field Length is 06, Where as for File B Start Position of Item Number is 13 And Item Field Length is 06. We need to Write all Records from File A to The Output File (File C).Output File is Having Same Attribute as File A. Before Writing Records to Output File C, We need to Check, If Item Number is > 499999, Then we Need to Move Spaces to a Specific Field which is of Length 2 Bytes with Start Position as 25. If Item Number is < 499999 thn what ever value it is Having need to be Passed. If Item Number is > 499999 Present in File A but Not in File B, No Need to Move Space to the Field Start at Position 25. Below is the Example.

File A:

123456|ABCDE12345|12|XYZ..........
111111|XYZAB44444|20|ABC..........
599999|WQZX55555|30|OPQ..........
699999|ABCDE12345|12|XYZ..........

File B:
123456|ABCDE12345|12|XYZ..........
111111|XYZAB44444|20|ABC..........
599999|WQZX55555|30|OPQ..........

File C: (Output File)
123456|ABCDE12345|12|XYZ.......... Item 123456 Present in File A & File B, But < 499999, O/P File to Have 12.
111111|XYZAB44444|20|ABC.......... Item 111111 Present in File A & File B, But < 499999, O/P File to Have 20.
599999|WQZX55555| |OPQ.......... Item 599999 Present in File A & File B, But > 499999, O/P File to Have Space Instead of 30 (File A).
699999|ABCDE12345|12|XYZ.......... Item Present in File A But Not in File B. But Item Number > 499999. O/P Should have 12 Instead of Space.

Note: O/P Record Count To Be Equal to File A Record Count.

Thanks
Kind Rgds

Vineet Anand

Re: File Comparision Using SORT

PostPosted: Fri Dec 02, 2011 6:42 pm
by Vineet
Missed Out One Info. Both Files having Recfm = FB.

Re: File Comparision Using SORT

PostPosted: Sat Dec 03, 2011 12:38 am
by Frank Yaeger
Your rules seem a bit incomplete. You don't say what to do if the item = 499999, and you don't say what to do if the item is only in FileA but is less than 499999 (I'll assume you want blanks in 25-26 in that case). Anyway, here's a DFSORT job that should give you the idea of how to do this. Modify as needed.

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//IN1 DD DSN=...  input file1 (FB/500)
//IN2 DD DSN=...  input file2 (FB/300)
//SORTOUT DD DSN=...  output file (FB/500)
//SYSIN DD *
  JOINKEYS F1=IN1,FIELDS=(1,6,A)
  JOINKEYS F2=IN2,FIELDS=(13,6,A)
  JOIN UNPAIRED,F1
  REFORMAT FIELDS=(F1:1,508,?)
  INREC IFTHEN=(WHEN=(509,1,CH,EQ,C'B',AND,1,6,ZD,GT,499999),
    OVERLAY=(25:2X)),
   IFTHEN=(WHEN=(509,1,CH,EQ,C'1',AND,1,6,ZD,LE,499999),
    OVERLAY=(25:2X))
  SORT FIELDS=(501,8,ZD,A)
  OUTREC BUILD=(1,500)
/*

Re: File Comparision Using SORT

PostPosted: Sat Dec 03, 2011 1:42 am
by Vineet
Thank Frank. for the 2 Queries U have Raised Reply is . If Item in File A & File B & Item Number = 499999 Or Item is Only in File A & = 49999, No Need to Overlay with Spaces. We Need to Over Lay Position 25-26 2ith Spaces If and Only If Item present in Both Files and Item Number > 499999. In All Other Condition We Don't Need to Overlay.

If ANy Query Concer please do let me know.

Thanks
Rgds.

Re: File Comparision Using SORT

PostPosted: Sat Dec 03, 2011 2:21 am
by Frank Yaeger
Do you still need help with this?

If so, please show a better example of input and expected output that includes all of the possibilities your rules cover.