sample code for read a 2nd record from last in flatfile how
can do?
Answers were Sorted based on User's Feedback
Answer / nsingh
ADD SEQUENCE NUMBER
SORT FIELDS=COPY
OUTREC FIELDS = (1,80,SEQNUM,ZD,A)
NOW SORT SEQ NUM IN DESCENDING ORDER
SORT FIELDS=(81,4,ZD,D)
INCLUDE ONLY 2ND LAST REC
SORT FILEDS = COPY
INCLUDE COND = (81,4,ZD,EQ,0002')
REMOVE SEQ NUM FROM FILE & THIS REC IS SELECTED
SORT FIELDS =COPY
OUTREC FIELDS = (1,80)
| Is This Answer Correct ? | 1 Yes | 0 No |
Suppose file has 100 Record
1,2,3.........................100
a) Read the file and Count the number of records into a variable
Suppose CNT_VAR = 100
b) Suppose you want to read 2nd record from Last
So Set N = 2
c) Now to find the search variable compute the below
SRC_VAR = CNT_VAR - N i.e (100 - 2)
SRC_VAR = 98
d) Now Read the file to pick 98th record from top
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / sunilkumar
First open the file in reverse order using OPEN command
OPEN FILE file-name REVERSE
Then read twice to get the 2nd last record.
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / santhosh vayathuri
for this we need to do fallowing steps
1) read all the records and store into an array and count
value store into an var
2) from that array subtract count var by 1 we will get last
2nd record
ex :: array(count-1) == last 2nd rec
| Is This Answer Correct ? | 1 Yes | 6 No |
TYPES OF SORTINGS. which is more prefarable.
What are 77 levels used for?
Can we redefine the field of x(200) to less than 200?
Using string statement.Is coding three destination string from one source string possible in one code?or three codes for every destination string of one source string.?thank you
what is sort? whis is internal & external sort ?when do u go for inter sort & external sort? tell about some sort utilites?
What is the problem of ordered sequential files access?
If a sub program is called from mainprogram.I have opened cursor in main program and Fetch the result in subprogram ,Is it possible ?If yes please tell me the reason.
Explain sorting techniques in cobol program? Provide the sort file definition, the sort statement, its syntax and meaning
what is a load module ?
What is the difference between working storage copybook and linkage section copybook?
In COBOL "BEFORE" advancing is there or not ?
Hai friends why we need to read a file before re-write a record?