RotorBalls
MIS
Appreciat your help on the last prgram. Got it working ok. This is a the second part to this program using I/O proc. I think there's something wrong with the compute statement or the compute routine. I've moved the compute statement before the IF and get a strange error on MF cobol. The way I have it listed here I get a run time error: "Illegal character in numeric field." I don't see where or if I redefined a numeric char to anything else. They all look ok to me. Any help would be appreciated. Thanks
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG3B.
AUTHOR. .
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SALES-FILE ASSIGN TO 'A:\ASSIGN3B.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SORT-FILE ASSIGN TO SORTWORK.
SELECT SORTED-FILE ASSIGN TO 'A:\SALESB.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
*
DATA DIVISION.
FILE SECTION.
FD SALES-FILE.
01 SALES-RECORD-IN.
05 SR-ACCOUNT-NUMBER PIC 9(6).
05 PIC X.
05 SR-NAME-IN PIC X(15).
05 SR-SALES PIC 9(4).
05 PIC XX.
05 SR-COMMISSION-PERCENT PIC V99.
05 PIC XX.
05 SR-LOCATION-IN PIC X(15).
05 SR-REGION-IN PIC X(11).
SD SORT-FILE.
01 SORT-REC.
05 COMMISSION-OUT PIC S9(4).
05 SR-REGION-OUT PIC X(11).
05 SR-LOCATION-OUT PIC X(15).
05 SR-NAME-OUT PIC X(15).
FD SORTED-FILE.
01 SORTED-REC PIC X(80).
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
*
PROCEDURE DIVISION.
100-MAIN-MODULE.
SORT SORT-FILE
ON DESCENDING KEY COMMISSION-OUT
INPUT PROCEDURE 200-PROCESS-RTN
OUTPUT PROCEDURE 300-COMMISSION-RTN
STOP RUN.
200-PROCESS-RTN.
OPEN INPUT SALES-FILE
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
READ SALES-FILE
AT END
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 300-COMMISSION-RTN
END-READ
END-PERFORM
CLOSE SALES-FILE.
300-COMMISSION-RTN.
OPEN OUTPUT SORTED-FILE
IF COMMISSION-OUT IS > 100
MOVE COMMISSION-OUT TO COMMISSION-OUT
COMPUTE COMMISSION-OUT = SR-SALES * SR-COMMISSION-PERCENT
ELSE
MOVE SR-REGION-IN TO SR-REGION-OUT
MOVE SR-LOCATION-IN TO SR-LOCATION-OUT
MOVE SR-NAME-IN TO SR-NAME-OUT
RELEASE SORT-REC
END-IF.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG3B.
AUTHOR. .
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SALES-FILE ASSIGN TO 'A:\ASSIGN3B.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SORT-FILE ASSIGN TO SORTWORK.
SELECT SORTED-FILE ASSIGN TO 'A:\SALESB.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
*
DATA DIVISION.
FILE SECTION.
FD SALES-FILE.
01 SALES-RECORD-IN.
05 SR-ACCOUNT-NUMBER PIC 9(6).
05 PIC X.
05 SR-NAME-IN PIC X(15).
05 SR-SALES PIC 9(4).
05 PIC XX.
05 SR-COMMISSION-PERCENT PIC V99.
05 PIC XX.
05 SR-LOCATION-IN PIC X(15).
05 SR-REGION-IN PIC X(11).
SD SORT-FILE.
01 SORT-REC.
05 COMMISSION-OUT PIC S9(4).
05 SR-REGION-OUT PIC X(11).
05 SR-LOCATION-OUT PIC X(15).
05 SR-NAME-OUT PIC X(15).
FD SORTED-FILE.
01 SORTED-REC PIC X(80).
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
*
PROCEDURE DIVISION.
100-MAIN-MODULE.
SORT SORT-FILE
ON DESCENDING KEY COMMISSION-OUT
INPUT PROCEDURE 200-PROCESS-RTN
OUTPUT PROCEDURE 300-COMMISSION-RTN
STOP RUN.
200-PROCESS-RTN.
OPEN INPUT SALES-FILE
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
READ SALES-FILE
AT END
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 300-COMMISSION-RTN
END-READ
END-PERFORM
CLOSE SALES-FILE.
300-COMMISSION-RTN.
OPEN OUTPUT SORTED-FILE
IF COMMISSION-OUT IS > 100
MOVE COMMISSION-OUT TO COMMISSION-OUT
COMPUTE COMMISSION-OUT = SR-SALES * SR-COMMISSION-PERCENT
ELSE
MOVE SR-REGION-IN TO SR-REGION-OUT
MOVE SR-LOCATION-IN TO SR-LOCATION-OUT
MOVE SR-NAME-IN TO SR-NAME-OUT
RELEASE SORT-REC
END-IF.