how to fetch the record before the last record in a cobol
file( its a huge file and if the key field is not known)
Answer Posted / logeshwaran ravi
DATA DIVISION.
FILE SECTION.
FD WS-INFILE.
01 WS-INREC.
.
.
.
.
FD WS-OUTFILE.
01 WS-OUTREC.
.
.
.
.
WORKING-STORAGE SECTION.
77 INFS PIC XX.
77 OUTFS PIC XX.
77 CONT PIC 9(3).
77 NUM PIC 9(3).
PROCEDURE DIVISION.
001-OPEN-PARA.
OPEN INPUT WS-INFILE.
OPEN OUTPUT WS-OUTFILE.
002-READ-PARA.
READ WS-INFILE AT END PERFORM 003-WRITE-PARA.
COMPUTE CONT = CONT + 1.
003-WRITE-PARA.
COMPUTE CONT = CONT - 1.
READ WS-INFILE AT END PERFORM 009-CLOSE-PARA.
NUM = NUM + 1.
IF NUM = CONT THEN
MOVE WS-INREC TO WS-OUTREC
WRITE WS-OUTFILE
PERFORM 009-CLOSE-PARA
END-IF.
009-CLOSE-PARA.
CLOSE WS-INFILE WS-OUTFILE.
STOP RUN.
| Is This Answer Correct ? | 2 Yes | 5 No |
Post New Answer View All Answers
What is the LINKAGE SECTION used in COBOL?
What kind of error is trapped by on size error option?
Why would you use find and get rather than to obtain?
What is the default value(s) for an initialize and what keyword allows for an override of the default?
what is the difference between COBOL2 AND COBOL390?
What are the pertinent COBOL commands?
How do you reference the fixed block file formats from cobol programs
What are the different types of condition in cobol and write their forms.
What is comp-1 and comp-2?
What is length is cobol?
How do you code cobol to access a parameter that has been defined in jcl? And do you code the parm parameter on the exec line in jcl?
What are literals?
Name the divisions, which are available in a cobol program?
What is the difference between perform … with test after and perform … with test before?
What do you understand by psb and acb?