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

When the working storage variables get allocated? a.At Compile time b.At starting of the run time c.At end of the run time. d.None of these

6 Answers   Wipro,


WORKING-STORAGE SECTION. 01 VAR1 COMP-2 VALUE 0. PROCEDURE DIVISION. MOVE 10.2115 TO VAR1. DISPLAY 'VAR1 =' VAR1. GOBACK. 10.2115 is stored as .10211499999999996E 02 in OS VS Cobol 10.2115 is stored as .10211500000000000E 02 in ecobol. Any reason why?

3 Answers   TCS,


what is the default print format? in cobol

3 Answers   HSBC,


can you please let me know if there is any walkins for COBOL/PLI/DB2/IMS/JCL in pune other than IBM and ITC infotech

0 Answers  


Describe the difference between subscripting and indexing ?

2 Answers  






can we print comp 3 stmts how ?

3 Answers   Accenture, TCS,


Explain call by context by comparing it to other calls.

1 Answers  


how to run sub programs using static and dynamic call ...

3 Answers   TCS,


I have one column say 'X' defined as VARCHAR Can anyone tell me What are the different ways to update this column thru COBOL-DB2 program?

5 Answers  


The disposition parameter in the jcl is share ( DISP+SHR ) and the program opens file in extend mode what will happen?

6 Answers   Cognizant,


can we use go to statement inline-perform?

7 Answers   IBM,


Is it possible that the redefines clause has different picture clauses compared to the one it redefined?

0 Answers  


Categories