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

If I want to increase the Limit in GDG. What should I do?

2 Answers   IBM,


What are declaratives and what are their uses in cobol?

0 Answers  


why do u need inspect verb?

3 Answers   Patni,


what modification we need to do in jcl if we use sort in cobol? I mean whether we need to include tempary file used for sorting in assign statement?

3 Answers   TCS,


how do you reference the variable block file formats from cobol programs

0 Answers  






How does IDMS communicate with CICS?

1 Answers   Covansys, Satyam,


A paragraph PARA-X is to be executed when none of the data names A, B and C have value of 1. Which of the following will achieve this ? (a) IF A NOT = 1 OR B NOT = 1 OR C NOT = 1 PERFORM PARA-X (B) IF NOT A= 1 AND B= 1 AND C = 1 PERFORM PARA-X (C) IF A NOT =1 IF NOT B = 1 OR C= 1 PERFORM PARA-X (C) IF A NOT = 1 AND B NOT = 1 AND C NOT = 1 PERFORM PARA-X

3 Answers   TCS,


What is Alternate Index ? How is it different from regular index ?

2 Answers  


have in 100 records in a flat file i want to move records like 1,3,5,7,9,11,.. to Output file1 and 2,4,6,8,10,12,14 .. records moved to Output file2..Pls Provide real time answer..

5 Answers   TCS,


What is comp-1 and comp-2?

0 Answers  


What is the difference between binary search and sequential search?

0 Answers  


The hierarchy of the execution of logical operators is (a) NOT AND OR (b) AND OR NOT (c) OR AND NOT (d) OR NOT AND

10 Answers   Huawei, IBM, TCS,


Categories