下面是我的文件和输出文件的代码。最后四个计算给我带来了最大的麻烦,主要是 DISCNT PRCNT。
我没有得到disnt percnt的正确输出;试图弄清楚如何在列中显示它;如果购买数量高于数量折扣水平,则该费率乘以总金额 = 折扣金额。
ENVIRONMENT DIVISION.
******************************************************************
* DEFINES THE EXTERNAL FILES - INPUT & OUTPUT FILES *
******************************************************************
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
*
SELECT TRANSACTION-FILE
ASSIGN "TRANSACTION.TXT" ORGANIZATION IS LINE SEQUENTIAL.
*
SELECT PR-MASTER-FILE
ASSIGN "MSTRSRT.TXT" ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS PR-PROD-NUM
FILE STATUS IS SW-FILE-STATUS.
*
SELECT PRINT-FILE
ASSIGN "ORDER_REPORT.TXT" ORGANIZATION IS LINE SEQUENTIAL.
*
*
DATA DIVISION.
*
FILE SECTION.
*
*
FD PR-MASTER-FILE.
*
01 PR-MASTER-RECORD.
05 PR-PROD-NUM PIC XXX.
05 PR-PROD-DESC PIC X(27).
05 PR-UNIT-PRICE PIC 9(03)V99.
05 PR-MIN-ORDER PIC 9(03).
05 PR-QTY-DISCNT-LEVEL PIC 9(03).
05 PR-DISCNT-PRCNT PIC 9V99.
05 PR-GRAND-TOTAL PIC S9(05)V99.
*
FD TRANSACTION-FILE.
01 TR-TRANSACTION-RECORD.
05 TR-CUST-NAME PIC X(25).
05 FILLER PIC X(05).
05 TR-PROD-QTY PIC 9(03).
05 FILLER PIC X(01).
05 TR-PROD-NUM PIC 9(03).
*
*
FD PRINT-FILE.
*
01 LINEOUT PIC X(160).
*
*
/
WORKING-STORAGE SECTION.
*
*
01 PRICES.
* 05 W-UNIT-PRICE-EDITED PIC ZZZV99.
05 W-GROSS-PRICE PIC S9(05)V99.
05 W-QTY-DISCNT-AMNT PIC S9(07)V99.
05 W-SALES-TAX PIC S9(06)V99.
05 W-NET-PRICE PIC S9(09)V99.
05 W-NET-PRICE-EDITED PIC ZZZ,ZZZ,ZZZV99.
*
*
01 SWITCHES.
05 SW-FILE-STATUS PIC XX.
05 PR-EOF PIC X VALUE "N".
*
01 HL-HEADING-LINE.
05 FILLER PIC X(35) VALUE SPACES.
05 FILLER PIC X(16) VALUE "ORDER REPORT".
01 HL-HEADING-COLUMNS-01.
05 FILLER PIC X(60) VALUE SPACES.
05 FILLER PIC X(06) VALUE "UNIT".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(09) VALUE "GROSS".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(06) VALUE "SALES ".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(08) VALUE "DISCNT".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(11) VALUE "DISCNT".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(08) VALUE "NET".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(10) VALUE "GRAND".
*
01 HL-HEADING-COLUMNS-02.
05 FILLER PIC X(25) VALUE "CUSTOMER".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(27) VALUE "PRODUCT".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(03) VALUE "QTY".
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(06) VALUE "PRICE".
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(06) VALUE "PRICE".
05 FILLER PIC X(05) VALUE SPACES.
05 FILLER PIC X(06) VALUE "TAX".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(08) VALUE "PERCNT".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(09) VALUE "AMOUNT".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(10) VALUE "PRICE".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(07) VALUE "TOTAL".
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(15) VALUE "MESSAGE".
*
01 DL-DETAIL-LINE.
05 DL-CUST-NAME PIC X(25).
* 05 FILLER PIC X(01).
05 DL-PROD-NUM PIC X(03).
* 05 FILLER PIC X(01).
05 DL-PROD-DESC PIC X(26).
* 05 FILLER PIC X(01).
05 DL-PROD-QTY PIC ZZZ.
05 FILLER PIC X(01).
05 DL-UNIT-PRICE PIC ZZZ.99.
05 FILLER PIC X(01).
05 DL-GROSS-PRICE PIC ZZ,ZZ9.99.
05 FILLER PIC X(01).
05 DL-SALES-TAX PIC Z,ZZ9.99.
05 FILLER PIC X(04).
05 DL-DISCNT-PRCNT PIC Z.99.
05 FILLER PIC X(01).
05 DL-QTY-DISCNT-AMNT PIC ZZ,ZZ9.99.
05 FILLER PIC X(01).
05 DL-NET-PRICE PIC X(11).
05 FILLER PIC X(01).
05 DL-GRAND-TOTAL PIC ZZ,ZZ9.99.
05 FILLER PIC X(01).
05 DL-MESSAGE PIC X(15).
*
*
/
PROCEDURE DIVISION.
000-MAINLINE.
OPEN INPUT TRANSACTION-FILE
I-O PR-MASTER-FILE
OUTPUT PRINT-FILE
WRITE LINEOUT FROM HL-HEADING-LINE AFTER PAGE
WRITE LINEOUT FROM HL-HEADING-COLUMNS-01 AFTER 2
WRITE LINEOUT FROM HL-HEADING-COLUMNS-02 AFTER 1
PERFORM UNTIL PR-EOF = "Y"
READ TRANSACTION-FILE
AT END
MOVE "Y" TO PR-EOF
NOT AT END
PERFORM 100-PROCESS-TRANSACTION
END-READ
END-PERFORM
CLOSE TRANSACTION-FILE PR-MASTER-FILE PRINT-FILE.
STOP RUN.
*
*
100-PROCESS-TRANSACTION.
MOVE SPACES TO DL-DETAIL-LINE
MOVE TR-CUST-NAME TO DL-CUST-NAME
MOVE TR-PROD-NUM TO DL-PROD-NUM
MOVE TR-PROD-NUM TO PR-PROD-NUM
READ PR-MASTER-FILE
INVALID KEY
MOVE ALL"*" TO DL-UNIT-PRICE
MOVE ALL"*" TO DL-NET-PRICE
MOVE "NO FILE" TO DL-MESSAGE
NOT INVALID KEY
PERFORM 110-PROCESS-TRANSACTION
END-READ
WRITE LINEOUT FROM DL-DETAIL-LINE AFTER 2.
*
*
110-PROCESS-TRANSACTION.
MOVE PR-PROD-DESC TO DL-PROD-DESC
MOVE PR-UNIT-PRICE TO DL-UNIT-PRICE
MOVE TR-PROD-QTY TO DL-PROD-QTY
IF TR-PROD-QTY < PR-MIN-ORDER
MOVE ALL"*" TO DL-NET-PRICE
MOVE "BELOW MIN" TO DL-MESSAGE
ELSE
MULTIPLY TR-PROD-QTY BY PR-UNIT-PRICE GIVING W-GROSS-PRICE
MOVE W-GROSS-PRICE TO DL-GROSS-PRICE
MULTIPLY W-GROSS-PRICE BY 0.07 GIVING W-SALES-TAX
MOVE W-SALES-TAX TO DL-SALES-TAX
IF TR-PROD-QTY > PR-QTY-DISCNT-LEVEL
MULTIPLY PR-DISCNT-PRCNT BY 100 GIVING DL-DISCNT-PRCNT
MOVE PR-DISCNT-PRCNT TO DL-DISCNT-PRCNT
* MULTIPLY W-GROSS-PRICE BY PR-DISCNT-PRCNT
* GIVING W-QTY-DISCNT-AMNT
* MOVE W-QTY-DISCNT-AMNT TO DL-QTY-DISCNT-AMNT
* SUBTRACT W-QTY-DISCNT-AMNT FROM W-GROSS-PRICE
END-IF
SUBTRACT W-SALES-TAX FROM W-GROSS-PRICE GIVING W-NET-PRICE
MOVE W-NET-PRICE TO W-NET-PRICE-EDITED
MOVE W-NET-PRICE-EDITED TO DL-NET-PRICE
ADD W-NET-PRICE TO PR-GRAND-TOTAL
REWRITE PR-MASTER-RECORD
MOVE PR-GRAND-TOTAL TO DL-GRAND-TOTAL
END-IF.
TR 文件:
LONELY LEO 012 010
CHARLIE CHEAP 001 743
WIDOW LADY 123 565
MISSIONARY MIKE 999 085
UNKNOWN COMIC 003 115
MUDFENCE MARTHA 200 115
SAM SENILE 007 175
ERIK ESTRADSKI 001 204
SPACE CADET 002 950
DATING BUREAU 004 565
DORM COUNCIL 450 900
LONESOME SAL 001 010
BROADMOOR COUNCIL 020 900
DIRTY OLD LADY 010 899
LAST CUSTOMER 999 999
公关文件:
004EROTIC TOOTHBRUSH 01098 001100 125
085HYMNAL 01245 005010 085
010INFLATABLE ENEMY 14095 005010 050
899SEARS GIFT CERT. 10000 006010 100
115BROWN PAPER BAGS 00005 100150 025
1752500VITAMIN E TABLETS 10000 002012 010
743BUDGET MOTEL GUIDE 00606 006100 125
280RESERVED PARKING STICKER 99999 001100 300
565BLACK BOOK--FILLED IN 00100 003006 100
010BEST FRIEND 14093 010015 050
280STUDENT PARKING STICKER 00010 001100 255
800SATIN SHEET SET 05595 001012 100
400FRENCH POSTCARD 00075 025050 050
900PLASTIC WHISTLES 00104 012100 155
这就是我到目前为止所得到的:
ORDER REPORT
UNIT GROSS SALES DISCNT DISCNT NET GRAND
CUSTOMER PRODUCT QTY PRICE PRICE TAX PERCNT AMOUNT PRICE TOTAL MESSAGE
LONELY LEO 010INFLATABLE ENEMY 12 140.95 1,691.40 118.39 1,573 88,790.54
CHARLIE CHEAP 743BUDGET MOTEL GUIDE 1 6.06 *********** BELOW MIN
WIDOW LADY 565BLACK BOOK--FILLED IN 123 1.00 123.00 8.61 114 18,493.67
MISSIONARY MIKE 085HYMNAL 999 12.45 12,437.55 870.62 5.00 11,566 15,750.72
UNKNOWN COMIC 115BROWN PAPER BAGS 3 .05 *********** BELOW MIN
MUDFENCE MARTHA 115BROWN PAPER BAGS 200 .05 10.00 0.70 .00 9 7,918.18
SAM SENILE 1752500VITAMIN E TABLETS 7 100.00 700.00 49.00 651 40,683.42
ERIK ESTRADSKI 204 .00 *********** NO FILE
SPACE CADET 950 .00 *********** NO FILE
DATING BUREAU 565BLACK BOOK--FILLED IN 4 1.00 4.00 0.28 3 18,497.39
DORM COUNCIL 900PLASTIC WHISTLES 450 1.04 468.00 32.76 .00 435 28,341.14
LONESOME SAL 010INFLATABLE ENEMY 1 140.95 *********** BELOW MIN
BROADMOOR COUNCIL 900PLASTIC WHISTLES 20 1.04 20.80 1.45 .00 19 28,360.49
DIRTY OLD LADY 899SEARS GIFT CERT. 10 100.00 1,000.00 70.00 .00 930 56,832.36
LAST CUSTOMER 999 .00 *********** NO FILE