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

COMP field occupy ?

2 Answers  


What guidelines should be followed to write a structured cobol prgm?

0 Answers  


Why did you choose to work with ibm mainframe cobol programming?

0 Answers  


a. Can the OPTIONAL clause in COBOL only be coded for input files? b. If it is coded for files opened in OUTPUT, I-O or EXTEND mode, will it give a compilation error? c. If there are no compilation errors and if such files are not coded in the JCL, will the OPEN statement run fine when these files are opened? d. How will a WRITE statement work for the above files?

2 Answers  


a pic s9(4) comp b pic s9(4) comp-3 c ???????????????? d ???????????????? move a to c add a+B giving d. what is ur declaration for c,d?

4 Answers  






What is tne need to use sub programs in Cobol?

3 Answers   HSBC,


What is the difference between CONTINUE & NEXT SENTENCE ?

2 Answers  


What is the LINKAGE SECTION used for?

4 Answers  


In my table having 3000 Records. How can I delete the 500th row? (we don't know what is data inside the table)

3 Answers   Keane India Ltd,


Hi All, how is sign is stored in S9(17) comp-3 variable. Answer with an Example will be of great help.

5 Answers   EDS,


what is subscript in cobol?give realtime example?

2 Answers   Wipro,


In file1 have 80 records are like d1,d2,d3......D80. File2 have 1000records are like a1d1,a1d2,a3d3.....Etc. I want matching records in file3 ? Plse tell me the matching logic???I want answer only in cobol ?Not using any tool or jcl?

1 Answers   CSC,


Categories