Cobol code query



Cobol code query

Postby suruchi » Fri Jun 25, 2010 1:49 pm

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
suruchi
 
Posts: 3
Joined: Fri Jun 18, 2010 5:48 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Cobol code query

Postby Robert Sample » Fri Jun 25, 2010 4:24 pm

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.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to Interview Questions

 


  • Related topics
    Replies
    Views
    Last post