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

what is mainframe? what is the mainframe software ? what is use in s/w field?

7 Answers   CSE,


Is it possible to mutliply a comp variable with an comp-3 variable. Will there be any error if i do it?

3 Answers   IBM, UST,


i declare a Table as OCCURS 2000 TIMES.If the input file has more than 2000 records will the COBOL program fail?

12 Answers  


how to code in cobol while using variable block file?

1 Answers  


What is difference between COBOL and VS COBOL II?.

1 Answers   Winsol Solutions,






how you read control card into array?

3 Answers   HCL,


What is the difference between Structured COBOL Programming and Object Oriented COBOL programming?

0 Answers   TryTechnicals Pvt Ltd,


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

0 Answers  


how do you reference the rrds file formats from cobol programs

0 Answers  


Why is it necessary that file needs to be opened in I-O mode for REWRITE?

0 Answers  


How do define Dymanic array in cobol how do u define single demensional arry and multidymensional arry in ur cobol.

4 Answers   Cap Gemini,


consider the following PROCEDURE DIVISION entry OPEN EXTEND IN-FILE identify the correct statement a.organization of IN-FILE is sequential and records can be added in the beginning b.organization of IN-FILE is sequential and records can be added in the end c.organization of IN-FILE is indexed and records can be added in the beginning d.organization of IN-FILE is indexed and records can be added in the end

3 Answers   TCS,


Categories