Cobol code query

suruchi
Posts: 3
Joined: Fri Jun 18, 2010 5:48 pm
Skillset: COBOL
JCL
DB2
Referer: Google

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

Robert Sample
Global moderator
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
Referer: other forum
Location: Dubuque, Iowa, USA

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

Code: Select all

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.


  • Similar Topics
    Replies
    Views
    Last post