Just for simplicity, i gave only 4 records.
IDENTIFICATION DIVISION.
PROGRAM-ID. REV.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT MYFILE1 ASSIGN TO MYCOB1
FILE STATUS IS WS-STAT.
SELECT MYFILE2 ASSIGN TO MYCOB2.
DATA DIVISION.
FILE SECTION.
FD MYFILE1
RECORDING MODE IS F.
01 REC1 PIC X(80).
FD MYFILE2
RECORDING MODE IS F.
01 REC2 PIC X(80) VALUE ZEROES.
WORKING-STORAGE SECTION.
01 WS-VAR1.
10 VAR1 PIC X(80) OCCURS 4 TIMES.
01 WS-I PIC 9(2) VALUE 1.
01 WS-STAT PIC 9(02).
PROCEDURE DIVISION.
OPEN INPUT MYFILE1.
OPEN OUTPUT MYFILE2.
PERFORM UNTIL WS-STAT = 10
READ MYFILE1 INTO VAR1(WS-I)
COMPUTE WS-I = WS-I + 1
END-PERFORM.
PERFORM UNTIL WS-I = 0
WRITE REC2 FROM VAR1(WS-I)
COMPUTE WS-I = (WS-I) - 1
END-PERFORM.
STOP RUN.
PROGRAM-ID. REV.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT MYFILE1 ASSIGN TO MYCOB1
FILE STATUS IS WS-STAT.
SELECT MYFILE2 ASSIGN TO MYCOB2.
DATA DIVISION.
FILE SECTION.
FD MYFILE1
RECORDING MODE IS F.
01 REC1 PIC X(80).
FD MYFILE2
RECORDING MODE IS F.
01 REC2 PIC X(80) VALUE ZEROES.
WORKING-STORAGE SECTION.
01 WS-VAR1.
10 VAR1 PIC X(80) OCCURS 4 TIMES.
01 WS-I PIC 9(2) VALUE 1.
01 WS-STAT PIC 9(02).
PROCEDURE DIVISION.
OPEN INPUT MYFILE1.
OPEN OUTPUT MYFILE2.
PERFORM UNTIL WS-STAT = 10
READ MYFILE1 INTO VAR1(WS-I)
COMPUTE WS-I = WS-I + 1
END-PERFORM.
PERFORM UNTIL WS-I = 0
WRITE REC2 FROM VAR1(WS-I)
COMPUTE WS-I = (WS-I) - 1
END-PERFORM.
STOP RUN.
When i run this code,I get the output file as first record is 04 10 ..and then the reversed records.
i cant understand why.
can someone help?