Page 1 of 1

modify date conditionally

Posted: Wed Oct 24, 2012 1:44 pm
by bernix
My file has a header record containing a date and data records. My task is to modify the date in the data records to current-date but only if the date is the same as in the header record. As that is a little confusing I will give an example
00 is the header record
01 are the data records
today is 20121024

input
00 20121018XYZ
01 20121018XYZ
01 20121016XYZ

output
00 20121018XYZ
01 20121024XYZ
01 20121016XYZ

header record remains unchanged
record 1: 20121018 is changed to 20121024 (current date) because it has the same date as header record
record 2: remains unchanged because the date is not equal header record

any solution for my problem

Posted: Wed Oct 24, 2012 2:33 pm
by Anuj Dhawan
This pseudo code should be handy:

Code: Select all

If header-date=detail-date
   ACCEPT ws-date FROM DATE
   move ws-date to detail-date
END-IF
In above pseudo- code "DATE" is a 'conceptual data items' and has the implicit PICTURE 9(6) and the sequence of data elements (from left to right) would be: 2 digits for the year, 2 digits for the month, 2 digits for the day.

As you have a four-digit year, you can consider to use intrinsic function CURRENT-DATE. However, how do you make use of the working-storage definitions in using DATE and CURRENT-DATE, I leave it you for experiment.

Posted: Wed Oct 24, 2012 3:44 pm
by bernix
thanks but i dont need a program code, i'd like to have a DFSORT solution :D

Posted: Wed Oct 24, 2012 3:51 pm
by William Collins
Please post the ICE201I message from any Sort step so we can see what level of the product you have.

It should be simple with a IFTHEN=(WHEN=GROUP on the header record, and PUSH the date from the header. Then you have functions for the current date (consult the manual) if you want all the confusion of "before midnight or after midnight" and problems with re-running/testing.

Posted: Wed Oct 24, 2012 5:21 pm
by bernix
William Collins wrote:Please post the ICE201I message from any Sort step so we can see what level of the product you have.

It should be simple with a IFTHEN=(WHEN=GROUP on the header record, and PUSH the date from the header. Then you have functions for the current date (consult the manual) if you want all the confusion of "before midnight or after midnight" and problems with re-running/testing.
ICE201I H RECORD TYPE IS V - DATA STARTS IN POSITION 5

Posted: Wed Oct 24, 2012 6:08 pm
by bernix
thank you william, your hint (WHEN=GROUP) was sufficient to assemble the statements that performed the job. i considered the manual and BINGO!

Posted: Wed Oct 24, 2012 8:35 pm
by William Collins
Good for you. The "H" in the message says you are reasonably up-to-date, but now I don't need to know that :-)

Posted: Fri Oct 26, 2012 2:17 pm
by Anuj Dhawan
I'm sorry, I thought it was in COBOL Part of the Forum -- however, as they say if it ends well, all is well. :)