adspace
I need to compare 3 variables(dates) and do some processing
based on the earliest date. There could be more then 1 date
record in any of the 3 fields. What is the best way to code
this?
Answer Posted / Man Mohan
In COBOL, you can use a sort-merge technique to compare three sets of dates and find the earliest one. Here's an example:
01 DATE-RECORD.
05 DATE-FIELD PIC X(8) VALUE ZEROS.
... (define other variables as needed)
87 SORT-AND-MERGE.
MOVE ALL DATE-RECORDS FROM START TO END OF FILE TO WORKING-STORAGE 01 LIST.
CALL 'SORT' USING LIST WITH GIVEN SORT ROUTINE. (You will need to define a sort routine for dates)
SET LAST-DATE TO THE FIRST ELEMENT IN LIST.
PERFORM VARYING LAST-INDEX FROM 2 BY 1 UNTIL LAST-INDEX <= LIST-SIZE.
IF DATE-FIELD IN LIST(LAST-INDEX) IS LESS THAN LAST-DATE THEN SET LAST-DATE TO DATE-FIELD IN LIST(LAST-INDEX).
END-PERFORM.
MOVE LAST-DATE TO RESULT.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers