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)
Answers were Sorted based on User's Feedback
Answer / lakshmi
1) iN WORKING STORAGE SECTION, Declare 2 variables HOLD-REC
and PRV-REC Equal to length of file and initialize them to
spaces
2) In Procedure divison, use the below logic and at the end
of the file read, PRV-REC contains the record before the
last record
READ <INFILE>
NOT AT END
MOVE HOLD-REC TO PRV-REC
MOVE INREC TO HOLD-REC
AT END
MOVE 'Y' TO EOF
END-READ
| Is This Answer Correct ? | 8 Yes | 1 No |
Answer / mailid
1.Read the file sequentially
2.For every successful read, move the key field to temp variable
3.when EOF is reached, A separate section should be performed in which Key field should not be moved to temp variable, Now, the temp variable will have key of the previously read record.
Using this, we can do a keyed read on the file to fetch the last but one record.
| Is This Answer Correct ? | 5 Yes | 6 No |
Answer / 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 |
Answer / vijay kumar reddy
identification division.
program-id. -------
environment division.
file control.
select infile assign to disky.
organization is sequential.
acess mode is sequential.
select outfile assign to disky1.
organization is sequential.
acess mode is sequential.
data division.
file section.
fd 01 infile.
05 ---
05
fd 01 outfile.
05 ---
05
working-storager section.
77 ws-eof pic 9 value zero.
77 ws-buffer1 pic x(80) value spaces.
77 ws-buffer2 pic x(80) value spaces.
procedure division.
000-main-para.
100-open-para thru 100-exit-para.
200-read-para thru 200-exit-para until ws-eof=1.
300-close-para thru 300-exit-para.
stop run.
100-open-para.
open infile.
open outfile.
100-exit-para.
exit.
200-read-para.
at end.
move 1 to ws-eof.
display buffer1.
not at end.
move buffer2 to buffer1
read infile.
move inrec to buffer2.
read infile.
move inrec to buffer1.
200-exit-para.
exit.
300-close-para.
close infile.
close outfile.
300-exit-para.
exit.
| Is This Answer Correct ? | 1 Yes | 4 No |
Answer / krishna
<PROCEDURE DIVISION>
OPEN INPUT <INFILE>.
OPEN OUTPUT <OUTFILE>.
PERFORM <READ-PARA-NAME> UNTILL EOF='Y'.
PERFORM <CLOSE-PARA-NAME>.
================================
READ-PARA-NAME.
READ <INFILE> AT END MOVE 'Y' TO EOF
IF EOF NOT = 'Y'
MOVE INREC TO OUTREC
WRITE OUTREC.
================================
CLOSE-PARA-NAME.
CLOSE INFILE.
CLOSE OUTFILE.
STOP RUN.
| Is This Answer Correct ? | 4 Yes | 7 No |
Is it possible to mutliply a comp variable with an comp-3 variable. Will there be any error if i do it?
How can I find the maximum value of a field in a file while reading the file dynamically? without using sort function. Suppose i have a file with fields Timestamp, description, teamname, teamnumber.. i have read the file till end and find the maximun value of timestamp which is not in sorted order.. can we use function max(timestamp)?
When we code these comp,comp1,comp-2,comp-3 and comp4 values. I know the differnece.I mean when we will prefer if it is new program.Explain in detail with memory examples. Thanks in advance.
Why there is no questions in this column?
describe 805 error
level number 77 is used to define a)group data b)elementary data c)redefine d)none
without performing any operations on a file how can i know whether it contains data or not
In which area will you utilize 88 level items in cobol?
What is inspect in cobol ?
study the data discriptions and answer the questions given below i)01 ORDER RECORD 05 OUT-HEADER PIC X(50) 05 ITEM-COUNT PIC 99 05 OUT-ITEM PIC X(20) OCCURS 1 TO 20 DEPENDING ON ITEM-COUNT ii)01 NAME-AND-ADDRESS 05 N-AND-A-LINE OCCURES 5 05 LINE-LENGTH PIC P9 05 N-AND-A-CHAR PIC X OCCURS 1 TO 20 DEPENDING ON LINE-LENGTH iii)01 SALES-LIST 05 SALESMAN-COUNT PIC 99 05 SALES PIC 9(6) OCCURS 1 TO 100 DEPENDING ON SALESMAN-COUNT iv)01 ORDER-RECORD 05 NO-OF-BRANDS PIC 99 05 BRAND-PURCHASED OCCURS 1 TO 15 DEPENDING ON NO-OF-BRANDS which of the following is true? a.i) and iii) are valid b.i) and iv) are valid c.i) and iii) are not valid d.all are valid
u have passed sme charecters thru parm parameter in jcl. how do u code in cobol to recieve the values u gave in parm ?
I have a occurs for 100 times but it has executed 101 time what could be the reason?