i have a file which contains records like
10,30,90,50,20,40,80,60,70
i want to display these records in reverse order like
70,60,80,40,20,50,90,30,10
please give me the cobol code (do not sort the records)

Answers were Sorted based on User's Feedback



i have a file which contains records like 10,30,90,50,20,40,80,60,70 i want to display these rec..

Answer / preethi

Declare table , and a index variable in the working storage section.

Procedure Division.

Open file1.
perform para1 thru para1-exit until end-of-file.
perform display-para thru display-para-exit.
close file1.
go back.
Para1.
read file1 into ws-file1
at end
end-of-file
set index-diff to index
not at end
move ws-file1-num to table-num(index)
set index up by 1
end-read.
para1-exit.
exit.

Display-para.
subtract 1 from index-diff.
perform until index-diff = 0
display table-num(index-diff)
set index-diff down by 1
end-perform.

display-para-exit.
exit.

Is This Answer Correct ?    5 Yes 3 No

i have a file which contains records like 10,30,90,50,20,40,80,60,70 i want to display these rec..

Answer / ch.ranveer singh gurjar

you can try its give you 100% exact output...
above solution for file its for no
NOTE:USE RIGHT JCL AND RIGHT FORMAT INPUT AND OUTPUT FILE

by
CH. RANVEER SINGH GURJAR(ACS A XEROX)

IDENTIFICATION DIVISION.
PROGRAM-ID. 'OCCURS'.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE ASSIGN TO DD1.
SELECT OUTFILE ASSIGN TO DD2.
DATA DIVISION.
FILE SECTION.
FD INFILE.
01 INREC.
05 IN-NUM PIC X(2).
05 FILLER PIC X(78).
FD OUTFILE.
01 OUTREC.
05 OUT-NUM PIC X(2).
05 FILLER PIC X(78).
WORKING-STORAGE SECTION.
01 WS-COUNT PIC 9(4).
01 EOF PIC X(1) VALUE 'N'.
01 ARRAY1.
05 ARREC OCCURS 1 TO 50 TIMES DEPENDING ON WS-COUNT.
10 AR-NUM PIC X(5).
PROCEDURE DIVISION.
MOVE 1 TO WS-COUNT.
OPEN INPUT INFILE.
OPEN OUTPUT OUTFILE.
PERFORM MOVE-RECORD UNTIL EOF = 'Y'.
PERFORM PARA1 UNTIL WS-COUNT = ZEROS
CLOSE INFILE.
CLOSE OUTFILE.
STOP RUN.
MOVE-RECORD.
READ INFILE AT END MOVE 'Y' TO EOF
NOT AT END
MOVE INREC TO ARREC(WS-COUNT)
DISPLAY WS-COUNT
ADD 1 TO WS-COUNT.
PARA1.
MOVE ARREC(WS-COUNT) TO OUTREC
WRITE OUTREC
SUBTRACT 1 FROM WS-COUNT.

Is This Answer Correct ?    3 Yes 1 No

i have a file which contains records like 10,30,90,50,20,40,80,60,70 i want to display these rec..

Answer / ch.ranveer singh gurjar

ou can try this i will give 100% exact output...by
CH. RANVEER SINGH GURJAR





IDENTIFICATION DIVISION.
PROGRAM-ID. 'OCCURS'.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE ASSIGN TO DD1.
SELECT OUTFILE ASSIGN TO DD2.
DATA DIVISION.
FILE SECTION.
FD INFILE.
01 INREC.
05 IN-EMP-ID PIC X(5).
05 IN-EMP-NAME PIC X(10).
05 FILLER PIC X(65).
FD OUTFILE.

01
OUTREC.
05 OUT-EMP-ID PIC X(5).

05 OUT-EMP-NAME PIC X(10).

05 FILLER PIC X(65).

WORKING-STORAGE
SECTION.
01 WS-COUNT PIC 9(4) VALUE ZEROS.

01 EOF PIC X(1) VALUE 'N'.



01ARRAY1.
05 ARREC OCCURS 1 TO 50 TIMES DEPENDING ON WS-COUNT.

10 AR-EMP-ID PIC X(5).

10 AR-EMP-NAME PIC X(10).

PROCEDURE
DIVISION.
OPEN INPUT
INFILE.
OPEN OUTPUT
OUTFILE.
PERFORM MOVE-RECORD UNTIL EOF = 'Y'.

PERFORM PARA1 UNTIL WS-COUNT = ZEROS

CLOSE
INFILE.
CLOSE OUTFILE.
STOP RUN.
MOVE-RECORD.
READ INFILE AT END MOVE 'Y' TO EOF
NOT AT END
MOVE INREC TO ARREC(WS-COUNT)
ADD 1 TO WS-COUNT.
PARA1.
MOVE ARREC(WS-COUNT) TO OUTREC
WRITE OUTREC
SUBTRACT 1 FROM WS-COUNT.

Is This Answer Correct ?    2 Yes 7 No

Post New Answer

More COBOL Interview Questions

consider the following piece of code 01 GROSS-PAY 05 BASIC-PAY PIC 9(5) 05 ALLOWENCES PIC 9(3) if BASIC-PAY has a value 1000 and ALLOWENCES has a value of 250,what will be displayed by the statement DISPLAY GROSS-PAY a.1250 b.01000250 c.01250 d.1.250

3 Answers   TCS,


can we use variable picture clause as xx.99 in cobol.

3 Answers  


when iam reading a flat file which has 100 records through cobol program when iam reading 50th records it gets abends .. so when i run the program again it should read from 50th record .where it got abened ? how it is possible

1 Answers   Patni,


What are the two search techniques ?

2 Answers   iGate,


What does the initialize statement do ?

2 Answers  






if a dataset is already created with fixed length but after that i want to change fixed length to variable length then how is it possible

3 Answers   IBM,


88 level entry is used for (a) data items in WORKING-STORAGE SECTION (b) items with RENAMES clause (c) condition-names (d) None of the above

5 Answers   TCS,


what are the utilities for load and unload the DB2 tables

1 Answers   L&T,


In a COBOL II PERFORM statement, when is the conditional tested, before or after the perform execution?

3 Answers  


What will happen if a variable is declared as below.. Explain with an example? Working storage section:- 01 WS-VARX PIC X(10) VALUE 'ABCDEFGHIJ'. 01 WS-VARN REDEFINES WS-VARX PIC 9(5) VALUE '12345'. What will happen I want Display WS-VARX and WS-VARN?

3 Answers   Xansa,


77 I pic 99 value 5 Perorm para-A I times. Para -A. move 10 to I. How many times the para-A will be executed.?

9 Answers   TCS,


when COMP-3 is preferrable?

3 Answers   Patni,


Categories