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?



I need to compare 3 variables(dates) and do some processing based on the earliest date. There coul..

Answer / 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

More COBOL Interview Questions

what happens if we dont close cursor in db2-cobol pgm?

6 Answers  


I am getting S00F abend when i try to compare two variable of different pic class,one variable is of 9(09) and another is S9(09) comp-3. First i moved the data from S9(09) comp-3 to 9(09), but no luck. So i tried to move the data from S9(09) comp-3 to X (09) and move to 9(09). I am getting same error message, Please help me to find solution for this ptoblem. ERROR MESSAGE - "The system or user abend S00F R=NULL was issued."

1 Answers  


how to transfer the file from pc to mainframe??

4 Answers  


how to pass 100 to s9(4) how r they inserted ?

3 Answers   TCS,


Move Zeroes to I move 5 to j perform para1 varying I from 10 by -2 until I = 0 display j. para1. Add 5 to j. What’ll be the value after execution of display stmt. A) 35 B) 40 C) 30 D) 25 please explain how?

5 Answers  


What is reference modification? What is UNION in sql and syntax? What is the difference between GDGS and VSAM? Which is prefer one? What is processing groups in endevor?

1 Answers   Kuwait Oil Company,


What is the difference between PIC 9.99 and PIC9v99?

1 Answers  


what is sysncpoint?

1 Answers   IBM,


In an EVALUTE statement is the order of the WHEN clauses significant?

4 Answers  


In the JCL, how do you define the files referred to in a subroutine ?

2 Answers  


which is faster either static call or dynamic call ? and specify the reasons for it ? reply fast

1 Answers  


how to access the file from prodution from changeman tool and to submit a file to production

2 Answers   IBM,


Categories