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
Cobol code query
-
- 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
Create a flag variable and initialize it to 1.
After you do your read of the input flag, your code will look likeSince nothing was mentioned about ordering, this is the easiest way to accomplish the given task.
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.
-
- Similar Topics
- Replies
- Views
- Last post
-
- 1
- 3865
-
by NicC
View the latest post
Tue Sep 15, 2020 5:37 pm
-
- 7
- 11858
-
by AusZosGuy
View the latest post
Fri Sep 10, 2021 6:40 pm
-
- 0
- 2575
-
by JIMDOOEY
View the latest post
Tue Mar 01, 2022 8:48 am
-
- 1
- 2513
-
by enrico-sorichetti
View the latest post
Fri Apr 02, 2021 6:56 pm
-
- 0
- 3143
-
by enrico-sorichetti
View the latest post
Fri Apr 01, 2022 6:00 pm