sample code for read a 2nd record from last in flatfile how
can do?

Answers were Sorted based on User's Feedback



sample code for read a 2nd record from last in flatfile how can do?..

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

sample code for read a 2nd record from last in flatfile how can do?..

Answer / abhijit

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

sample code for read a 2nd record from last in flatfile how can do?..

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

sample code for read a 2nd record from last in flatfile how can do?..

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

Post New Answer

More COBOL Interview Questions

How to read records in reverse order in flat file? I know we can do it by reading all records into an array.... Then read records in reverse order by using subscript or index but can any body give me the exact code.

5 Answers   TCS,


If my file contains 100,000 records and job abended at 55,000th records processing then how can i restart job from that record onward by ignoring that record. I can not edit the file as file size is big and it is getting browse substituted?

5 Answers   TCS,


i was faced one question- i have value -00001234.56 Suppress the zeroes and the output should be -1234.56 But Not - 1234.56 spaces should not be available after suppressing the zeroes. logic in jcl and cobol?

0 Answers  


I have one ps file in which there are 3 fileds emp_no,emp_name and leave_app.this ps file information give the detail of employee which is going to apply for leave.suppose emp_no=113430,emp_name=ajay,leave_app=1 that means he is going to apply for 1 day leave.and accordingling the table in db2 will be updated means if he has that no of leave in his account then he will get dat leave and updated acc. in table(leave_balance=previous leave present in table-leave_app).Now i want to check whther the updated result is correct or not by comparing the two ps file using IEBCOMPARE or icetool so what is going to be the two ps file and how its is going to be compare.

0 Answers   Cap Gemini,


maximum of how many screens we can open in emulator

2 Answers  






What is the difference between write & move in COBOL?

3 Answers   CSC, HHB,


1.What is the limit of linkage section?

4 Answers  


Name the divisions, which are available in a cobol program?

0 Answers  


What is amode(24), amode(31), rmode(24) and rmode(any) (applicable to only mvsesa enterprise server) ?

0 Answers  


period is missing in the cobol program which error we getting

5 Answers   TCS, Tesco,


what is redefines? where it can be effectively use for the purpose of memory utilization? give an example?

4 Answers   IBM,


How many times the loop runs here 01 a pic 9(2) value 10. perform para1 a times stop run. para1: move 20 to a.

3 Answers  


Categories