Page 1 of 1

Cobol code query

PostPosted: Fri Jun 25, 2010 1:49 pm
by suruchi
There's one input file and three output file. How to write the records in input file through cobol code so that there is equal number of records in each output.
For e.g.
case 1
input file = 60 recs
ouput files:
File 1= 20 recs
File 2=20 recs
File 3= 20 recs
Case 2
input file = 61 recs
ouput files:
File 1= 21 recs
File 2=20 recs
File 3= 20 recs
Case 2
input file = 62 recs
ouput files:
File 1= 21 recs
File 2=21 recs
File 3= 20 recs

So on and so forth....
Number of records in the input file is not known.

This question was faced by me in an interview.

Pls let me know the solution to above query

Re: Cobol code query

PostPosted: Fri Jun 25, 2010 4:24 pm
by Robert Sample
Create a flag variable and initialize it to 1.
After you do your read of the input flag, your code will look like
EVALUATE FLAG-VAR
WHEN 1
     WRITE OUTPUT-RECORD-1 FROM INPUT-RECORD
     ADD 1 TO FLAG-VAR
WHEN 2
     WRITE OUTPUT-RECORD-2 FROM INPUT-RECORD
     ADD 1 TO FLAG-VAR
WHEN 3
     WRITE OUTPUT-RECORD-3 FROM INPUT-RECORD
     MOVE 1 TO FLAG-VAR
END-EVALUATE.
Since nothing was mentioned about ordering, this is the easiest way to accomplish the given task.