I have PS flat file with 14 records. I want to read from
4th to 9th record and want to write those 6 records (4th
record to 9th record) to another PS file (output file).
there is no key defined in the input file. I just want read
a certain Consecutive records. can any one please give me
the procedure division Coding for this. I have coded the
below coding but the READ-PARA is performing only 1 time
even though I have 14 records in my input file (i.e FILE-1):
PROCEDURE DIVISION.
A000-SECTION.
MOVE 0 TO I.
OPEN INPUT FILE-1.
IF CHECK-KEY1 > 0
DISPLAY "OPEN ERROR FOR FILE-1, CODE IS:" CHECK-KEY1
END-IF.
OPEN EXTEND NEWFILE-1
IF CHECK-KEY3 > 0
DISPLAY "OPEN ERROR FOR NEWFILE-1 COD IS" CHECK-KEY3
END-IF.
PERFORM READ-PARA THRU EXIT-PARA UNTIL EOF-REC = 'YES'.
DISPLAY " FINALLY OUT OF LOOP"
CLOSE FILE-1
CLOSE NEWFILE-1
STOP RUN.
READ-PARA.
ADD 1 TO I
READ FILE-1
AT END MOVE 'YES' TO EOF-REC
IF I > 3 AND < 10
PERFORM WRITE-PARA
ELSE
DISPLAY "NOT IN RANGE"
END-IF.
EXIT-PARA.
EXIT.
WRITE-PARA.
WRITE NEW-REC FROM FILE1-REC.
Answer Posted / satishk
HI FRIENDS,
AS U MENTIONED THAT, IT WAS A PS-FILE,SO IN UR COBOL
PROGRAM, U HAVE DECLARED AN KEY-VARIABLE IN INPUT-PS-FILE.
WELL, SO, YOUR WAY OF APPROACH WAS WRONG.
HERE IS THE RIGHT CONCEPT:
In a PS-FILE, you cannot use any key-variable. only record-
number if you have defined for a particular record can be
moved, so that,a particular record can be moved with its
record-number.
In order to move your choice of records to be moved to any
other file, try to make use of VSAM-Files, which enables
you to define your own set of records to be moved from one
dataset to other, by using either IDCAMS utility, SKIP AND
COUNT in your JCL, (OR) making your cobol code using the
key-variables set to your fixed number of choice of record-
index between the range of your choice of records.
well, these are the only possibilities to move records from
one file to other file.
| Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
In which area will you utilize 88 level items in cobol?
How arrays can be defined in COBOL?
What is the difference between perform … with test after and perform … with test before?
How to use the same COBOL program in Batch and CICS on lines? explain with an example
How to print 10 to 1 if the input have only 10 digit number?
I have to write to a outfile where the number of records in that file should be the header of that file using IMS.. can anyone help me in this issue
What is the default value(s) for an initialize? What keyword will allow for an override of the default?
how do you reference the fixed unblock file formats from cobol programs
how can i see junk values in dclgen or in hostvariable of comp ?
What is the use of intialize verb?
What are all the divisions of a COBOL program?
What is Pic 9v99 Indicates in COBOL?
What is the difference between comp and comp-3 usage?
What is amode(24), amode(31), rmode(24) and rmode(any) (applicable to only mvsesa enterprise server) ?
Program A (Normal COBBAT) calling a B Program (DB2COBOL, COBBATDB which is using a VSAM file. its a dynamic call. How we will handle VSAM file decleration in our from JCL from where we are running A PGM. And should we have PLAN for A pGM also. if possible can some one post a sample JCL. Thanks for help in advance.