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
Can you please let me know the centre name of INS certification in Kolkata.
Define cobol?
Can we change the password using ALTER? anyone tried and changed?
Explain about different table spaces.
What is the use of intialize verb?
What is the difference between external and global variables in COBOL?
What is the problem of ordered sequential files access?
can anybody post me about file-aid and changemen tools pls and give me reference if any mainframe guys are there
What is the difference between goback, stop run and exit program in cobol?
how do you define single dimensional array and multidimensional array in your cobol?
What is the difference between PIC 9.99 and PIC9v99?
What is the Purpose of Pointer in the string?
Name the sections present in data division.
What is an in line perform? When would you use it? Anything else you wish to say about it.
What happens when we move a comp-3 field to an edited (say z (9). Zz-)?