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 utilization of copybook in cobol? Could we utilize a similar copybook?
how do you reference the esds vsam file formats from cobol programs
What is the difference between Call and a Link?
What is the default value(s) for an initialize? What keyword will allow for an override of the default?
Write some characteristics of cobol as means of business language.
how to move the records from file to array table. give with code example
Explain how will you differentiate between an internal and an external sort, the pros and cons, internal sort syntax etc
i want to learn mainframe..any websites and material to learn from basic..? my mail id : rajeswaribe2010@gmail.com
Write a cobol program making use of the redefine clause.
how do you reference the printer file formats from cobol programs
What is perform what is varying?
Have you used the sort in your project?for this type of questions any working on real time project give the eg. with real time scenario.
) how do u code after getting data?
i want a program using by if, evaluate , string, unstring, perform, occurs?
What is the utilization of copybook in cobol?