I have two input files F1 and F2, each having LRECL=2000 and RECFM=FB
Now I need to compare them and if records matches on keys from both files then we need to use condition: if the date field in F1 is older than date field in F2 by 365 days then overlay the first field of F2 with char 'D' else replace the F2 date with F1 date.
Basically I am not sure how to write the WHEN condition here in IFTHEN statement. Could anyone please help me out to write the correct statement.
Key in both i/p file (2,3)
Date in both i/p file (5,8)
Note in F2 file, date will always be current date.
So, you could add, or subtract, 365 days (or one year, depending on what you really want) to one of the dates, and then compare. CCYYMMDD is fine for comparison in that case.
You need to use syntax which exists, so look in the manual for how a WHEN=(logicalexpression) can be constructed. You can temporarily extend the record to include additional data (the amended date) and use that.
Since you just want the difference, DATEDIFF is even better. Perhaps. Think hard (ask) about what that 365 means. Is it literal, or is it "a year" or what?
There are other date functions as well. Take this opportunity to become aware of them.
Do you really want 365 days of 1 year difference? Run below job and observe the difference in output by yourself? Either way this should give you a very good idea on how to use the function itself.