执行保存时出现运行时错误

时间:2012-03-03 03:02:16

标签: cobol

嗨我需要一些帮助我无法保存如果用户只输入2项而不超过5项。我只能保存5项但当我只输入3项时我无法保存我得到运行时错误。可能我在循环中遇到问题。提前谢谢你

我正在使用mscobol 2.20

这是我的代码我把它归还文件状态

             IDENTIFICATION DIVISION.
             PROGRAM-ID. SOENTRY.
             ENVIRONMENT DIVISION.
             INPUT-OUTPUT SECTION.
             FILE-CONTROL.



            SELECT SYSTEM-FILE
             ASSIGN TO DISK
             ORGANIZATION IS INDEXED
             ACCESS MODE IS RANDOM
             RECORD KEY IS SYS-FY
             FILE STATUS IS SYSTEM-STATUS.



           SELECT CUSTOMER-FILE
             ASSIGN TO DISK
             ORGANIZATION IS INDEXED
             ACCESS MODE IS RANDOM
             RECORD KEY IS CUSNO
             FILE STATUS IS CUSTOMER-STATUS.



           SELECT ITEM-FILE
             ASSIGN TO DISK
             ORGANIZATION IS INDEXED
             ACCESS MODE IS RANDOM
             RECORD KEY IS ITMNO
             FILE STATUS IS ITEM-STATUS.



           SELECT SO-FILE
             ASSIGN TO DISK
             ORGANIZATION IS INDEXED
             ACCESS MODE IS RANDOM
             RECORD KEY IS SONO
             FILE STATUS IS SO-STATUS.



           SELECT SOD-FILE
             ASSIGN TO DISK
             ORGANIZATION IS INDEXED
             ACCESS MODE IS RANDOM
             RECORD KEY IS SODKEY
             FILE STATUS IS SOD-STATUS.





       DATA DIVISION.
       FILE SECTION.

       FD  SYSTEM-FILE LABEL RECORD IS STANDARD
           VALUE OF FILE-ID IS "SYSTEM.DAT".
       01  SYSTEM-RECORD.
           03  SYS-FY           PIC 9(4).
           03  SYS-CONAME       PIC X(50).
           03  SYS-COADDR       PIC X(50).
           03  SYS-USER         PIC 9(10).
           03  SYS-PWORD        PIC 9(10).
           03  SYS-LASTCUSNO    PIC 9(5).
           03  SYS-LASTITMNO    PIC 9(5).
           03  SYS-LASTSONO     PIC 9(7).
           03  SYS-LASTSINO     PIC 9(7).
           03  SYS-LASTORNO     PIC 9(7).
           03  SYS-RECSTAT      PIC A.

       FD  CUSTOMER-FILE LABEL RECORD IS STANDARD
           VALUE OF FILE-ID IS "CUSTOMER.DAT".
       01  CUSTOMER-RECORD.
           03  CUSNO            PIC 9(5).
           03  CUSNAME          PIC X(40).
           03  CUSADDR          PIC X(40).
           03  CUSCONTACTPERSON PIC X(40).
           03  CUSCONTACTNO     PIC 9(18).
           03  CUSCREDITLIMIT   PIC 9(7)V99.
           03  CUSBALANCE       PIC S9(7)V99.
           03  CUSLASTSONO      PIC 9(7).
           03  CUSLASTSINO      PIC 9(7).
           03  CUSLASTORNO      PIC 9(7).
           03  CUSRECSTAT       PIC A.

       FD  ITEM-FILE LABEL RECORD IS STANDARD
           VALUE OF FILE-ID IS "ITEM.DAT".
       01  ITEM-RECORD.
           03 ITMNO                   PIC 9(5).
           03 ITMDESC                 PIC X(40).
           03 ITMUM                   PIC X(3).
           03 ITMPRICE                PIC S9(6)V99.
           03 ITMQTYONHAND            PIC 9(4).
           03 ITMQTYONORDER           PIC 9(4).
           03 ITMLASTONO              PIC 9(7).
           03 ITMLASTSINO             PIC 9(7).
           03 ITMRECSTAT              PIC X.



       FD  SO-FILE LABEL RECORD IS STANDARD
           VALUE OF FILE-ID IS "SO.DAT".

       01  SO-RECORD.
           03  SONO             PIC 9(7).
           03  SODATE           PIC 9(8).
           03  SOCUSNO          PIC 9(5).
           03  SOPAYMODE        PIC XX.
           03  SOTOTAL          PIC 9(7)V99.
           03  SOPREPBY         PIC X(30).
           03  SOAPPRBY         PIC X(30).
           03  SORECSTAT        PIC X.


       FD  SOD-FILE LABEL RECORD IS STANDARD
           VALUE OF FILE-ID IS "SOD.DAT".
       01  SOD-RECORD.
           03  SODKEY.
               05  SODSONO      PIC 9(7).
               05  SODITMNO     PIC 9(5).
           03  SODQTYORD        PIC 9(4).
           03  SODQTYINV        PIC 9(4).
           03  SODUPRICE        PIC 9(6)V99.
           03  SODAMOUNT        PIC 9(6)V99.
           03  SODRECSTAT       PIC X.



       WORKING-STORAGE SECTION.
       01  ESC-CODE        PIC 99 VALUE 0.
           88  ESC-KEY     VALUE 1.
           88  F2          VALUE 3.
           88  F10         VALUE 11.

       01  ERRMSG       PIC X(75) VALUE SPACES.
       01  ERR          PIC 9 VALUE 0.  
       01  TEMP-VAR VALUE ZEROES.
           03 VAR-ITMNO                PIC 9(5) OCCURS 5 TIMES.    
           03 VAR-ITMPRICE             PIC 9(6) OCCURS 5 TIMES.
           03 VAR-ITMQTYONORDER        PIC 9(4) OCCURS 5 TIMES.
           03 VAR-SODITMQTYORDER       PIC 9(4) OCCURS 5 TIMES.
           03 VAR-AMOUNT               PIC 9(6) OCCURS 5 TIMES.

       01  TEMP-STR VALUE SPACES.
           03 VAR-ITMDESC              PIC X(40) OCCURS 5 TIMES.
           03 VAR-ITMUM                PIC X(3) OCCURS 5 TIMES.

       01  QTYORD                  PIC 9(4).
       01  ROW                     PIC 9.
       01  R                       PIC 9.

       01  EDIT-PRICE.
           03 E-PRICE      PIC ZZZ,ZZ9.99.

       01  MY-DATE.
           03 MY-YEAR      PIC 9(4).
           03 MY-MONTH     PIC 9(2).
           03 MY-DAY       PIC 9(2).


       01  AMOUNT          PIC 9(6)V99.
       01  TOTAL-AMOUNT    PIC 9(7)V99.
       01  CUSTOMER.
              03 VAR-CRDLIMIT  PIC Z,ZZZ,ZZ9.99.
              03 VAR-BALANCE   PIC Z,ZZZ,ZZ9.99.
       01  EDIT-AMOUNT.
           03 E-AMOUNT     PIC ZZZ,ZZ9.99.
           03 E-TOTAL      PIC Z,ZZZ,ZZ9.99.
       01  MOD    PIC XX.
       01  FLAG   PIC 9.
       01  LBL.
           03  LBLSONO     PIC 9(7).

       01  APP-PREV.
           03  PREPBY          PIC  X(30).
           03  APPBY           PIC  X(30).

       01  VAR-ITEM.
           03  VAR-QTYONHAND    PIC 9(4).
           03  TOTAL-QTYONORDER PIC 9(4).

       01  CHECK-STATUS.
           03  SYSTEM-STATUS   PIC XX.
           03  CUSTOMER-STATUS PIC XX.
           03  ITEM-STATUS     PIC XX.
           03  SO-STATUS       PIC XX.
           03  SOD-STATUS      PIC XX.

       SCREEN SECTION.
       01  HEADER.
           03  BLANK SCREEN BACKGROUND-COLOR 0.
       01  ENTRY-FORM.
           03  LINE 1 COLUMN 31 PIC X(50) 
               FROM SYS-CONAME HIGHLIGHT.
           03  LINE 3 COLUMN 55 VALUE "SO NO  :".
           03  LINE 4 COLUMN 55 VALUE "SO DATE:".
           03  LINE 4 COLUMN 68 VALUE "/".
           03  LINE 4 COLUMN 73 VALUE "/".
           03  LINE 4 COLUMN 2 VALUE "CUSTOMER N0:".
           03  LINE 4 COLUMN 15 PIC 9(5) USING CUSNO.          
           03  LINE 6 COLUMN 2 VALUE "NAME       :".
           03  LINE 7 COLUMN 2 VALUE "ADDRESS    :".
           03  LINE 17 COLUMN 53 VALUE "TOTAL ======> ".
           03  LINE 17 COLUMN 66 PIC Z,ZZZ,ZZ9.99 
               FROM TOTAL-AMOUNT.
           03  LINE 19 COLUMN 2 "PREPARED BY: ".
           03  LINE 19 COLUMN 14 PIC X(30) USING SOPREPBY.    
           03  LINE 20 COLUMN 2 "APPROVED BY: ".
           03  LINE 20 COLUMN 14 PIC X(30) USING SOAPPRBY. 
           03  LINE 19 COLUMN 48 VALUE "CRDTLIMIT : ".
           03  LINE 19 COLUMN 64 PIC Z,ZZZ,ZZ9.99
               FROM VAR-CRDLIMIT.
           03  LINE 20 COLUMN 48 VALUE "BALANCE   : ".
           03  LINE 20 COLUMN 64 PIC Z,ZZZ,ZZ9.99
               FROM VAR-BALANCE.

           03  LINE 21 COLUMN 48 VALUE "ITMQTYHAND   : ".
           03  LINE 21 COLUMN 64 PIC 9(4)
               FROM ITMQTYONHAND.
           03  LINE 6  COLUMN 55 VALUE "PAYMENT MODE:".

       01 CLEAR-CUSNO.
           03  LINE 4 COLUMN 15 VALUE "00000".

       01 CUST-PRO.
           03  LINE 6 COLUMN 15 PIC X(40)
               FROM CUSNAME BACKGROUND-COLOR 0.
           03  LINE 7 COLUMN 15 PIC X(40)
               FROM CUSADDR BACKGROUND-COLOR 0.            
       01 ITEM-HEADER.             
           03  LINE 9 COLUMN 2 "ITEM NO" BACKGROUND-COLOR 9.
           03  LINE 9 COLUMN 10 "     " BACKGROUND-COLOR 9.
           03  LINE 9 COLUMN 12 "     DESCRPTION   " BACKGROUND-COLOR 9.
           03  LINE 9 COLUMN 30 "          " BACKGROUND-COLOR 9.
           03  LINE 9 COLUMN 41 " UOM " BACKGROUND-COLOR 9.
           03  LINE 9 COLUMN 47 " QTY " BACKGROUND-COLOR 9.
           03  LINE 9 COLUMN 53 "  UNIT PRICE " BACKGROUND-COLOR 9.
           03  LINE 9 COLUMN 67 "  AMOUNT  " BACKGROUND-COLOR 9.

       01  FUNCTION-KEYS.
           03  LINE 24 COLUMN 5 "Esc" HIGHLIGHT.
           03  "=Exit  ".
           03  "F2" HIGHLIGHT.
           03  "=Save  ".
           03  "F10" HIGHLIGHT.
           03  "=Cancel".
       01  ERROR-MESSAGE.
           03  LINE 25 COLUMN 5 PIC X(70) FROM ERRMSG HIGHLIGHT.
       01  CLEAR-SCREEN.
           03  BLANK SCREEN BACKGROUND-COLOR 0.
       PROCEDURE DIVISION.
       MAIN.
           OPEN I-O SYSTEM-FILE CUSTOMER-FILE ITEM-FILE 
           SO-FILE SOD-FILE.

           IF SOD-STATUS not = '00'
             DISPLAY "error" SOD-STATUS
             STOP RUN.

           IF SOD-STATUS = '05'
             DISPLAY "error" SOD-STATUS
             STOP RUN.

           IF SO-STATUS = '00'
             DISPLAY "error" SO-STATUS
             STOP RUN.

           IF SO-STATUS = '05'
             DISPLAY "error" SO-STATUS
             STOP RUN.  



           MOVE 2012 TO SYS-FY.
           READ SYSTEM-FILE INVALID KEY MOVE 1 TO ERR.
           IF ERR = 1
               DISPLAY "SYSTEM RECORD NOT FOUND."
           ELSE
               PERFORM INITIALIZE-ITEMREC
               DISPLAY HEADER

               PERFORM ENTRY1 UNTIL ESC-KEY
               DISPLAY CLEAR-SCREEN.           
           CLOSE SYSTEM-FILE CUSTOMER-FILE ITEM-FILE 
           SO-FILE SOD-FILE.    

           STOP RUN.
       ENTRY1.

           COMPUTE SONO = SYS-LASTSONO + 1.
           MOVE SONO TO LBLSONO.

           DISPLAY ENTRY-FORM ITEM-HEADER FUNCTION-KEYS ERROR-MESSAGE.

           DISPLAY (3 , 65) LBLSONO.

           MOVE 2012 TO MY-YEAR.
           DISPLAY ( 4 , 74) MY-YEAR.



           MOVE 1 TO FLAG.
           PERFORM ENTER-MONTH UNTIL FLAG = 0 OR ESC-KEY
           OR F2 OR F10.

           MOVE 1 TO FLAG.
           PERFORM ENTER-DAY UNTIL FLAG = 0 OR ESC-KEY
           OR F2 OR F10.



           MOVE 1 TO ERR.
           PERFORM ENTER-CUSNO UNTIL ERR = 0 OR ESC-KEY
           OR F2 OR F10.

           DISPLAY CUST-PRO.
           MOVE CUSCREDITLIMIT TO VAR-CRDLIMIT.
           MOVE CUSBALANCE TO VAR-BALANCE.
           DISPLAY(19 , 66) VAR-CRDLIMIT.
           DISPLAY(20 , 66) VAR-BALANCE.

           MOVE 1 TO ERR.
           PERFORM ENTER-PREP UNTIL ERR = 0 OR ESC-KEY.

           MOVE 1 TO ERR.
           PERFORM ENTER-APP UNTIL ERR = 0 OR ESC-KEY.






           MOVE 1 TO FLAG.  
           PERFORM CHCK-MOD UNTIL FLAG = 0 OR ESC-KEY.


           PERFORM ITM-INPUT.


           IF F2 PERFORM SAVE-ENTRIES
           ELSE IF F10 PERFORM CANCEL-ENTRIES. 


       ENTER-MONTH.
           ACCEPT(4 , 65)MY-MONTH.
           ACCEPT ESC-CODE FROM ESCAPE KEY.
           IF F2
              PERFORM SAVE-ENTRIES            
           ELSE IF F10
              PERFORM CANCEL-ENTRIES

           ELSE IF MY-MONTH  12
             MOVE "INVALID MONTH" TO ERRMSG
             DISPLAY ERROR-MESSAGE

           ELSE
             MOVE SPACES TO ERRMSG
             DISPLAY ERROR-MESSAGE
             MOVE 0 TO FLAG.             

       ENTER-DAY.
           ACCEPT(4 , 70)MY-DAY.
           ACCEPT ESC-CODE FROM ESCAPE KEY.
           IF F2
              PERFORM SAVE-ENTRIES            
           ELSE IF F10
              PERFORM CANCEL-ENTRIES           
           ELSE IF MY-DAY  31
             MOVE "INVALID DAY" TO ERRMSG
             DISPLAY ERROR-MESSAGE

           ELSE
             MOVE SPACES TO ERRMSG
             DISPLAY ERROR-MESSAGE         
             MOVE 0 TO FLAG.


       ENTER-CUSNO.

           ACCEPT (4 , 15) CUSNO.
           ACCEPT ESC-CODE FROM ESCAPE KEY.
           IF F2
              PERFORM SAVE-ENTRIES
           ELSE IF F10
              PERFORM CANCEL-ENTRIES
           ELSE IF CUSNO = ZEROES
              MOVE 1 TO ERR
           ELSE
              MOVE SPACES TO ERRMSG
              PERFORM VALIDATE-CUSNO.         

       VALIDATE-CUSNO.
           MOVE 0 TO ERR.   
           READ CUSTOMER-FILE INVALID KEY MOVE 1 TO ERR.
           IF ERR = 1

             MOVE "CUSTOMER NO. NOT FOUND" TO ERRMSG
             MOVE 1 TO ERR
             DISPLAY CLEAR-CUSNO
             DISPLAY ERROR-MESSAGE
             PERFORM CLEAN

           ELSE
             DISPLAY ERROR-MESSAGE.


       CHCK-MOD.

           ACCEPT (6 , 69) MOD.
           ACCEPT ESC-CODE FROM ESCAPE KEY.
           IF ESC-KEY
             DISPLAY CLEAR-SCREEN
             STOP RUN
           IF F2 PERFORM SAVE-ENTRIES
           ELSE IF F10 PERFORM CANCEL-ENTRIES.

           IF MOD  = "CA" OR "CR"
             MOVE SPACES TO ERRMSG
             DISPLAY ERROR-MESSAGE
             MOVE 0 TO FLAG

           ELSE
             MOVE "INVALID INPUT." TO ERRMSG
             DISPLAY ERROR-MESSAGE.

       ENTER-PREP.
           ACCEPT (19 , 14 ) SOPREPBY.
           ACCEPT ESC-CODE FROM ESCAPE KEY.
           IF ESC-KEY
             DISPLAY CLEAR-SCREEN
             STOP RUN 
           ELSE IF SOPREPBY = SPACES
             MOVE 1 TO ERRMSG
             MOVE "PLEASE FILL-IN" TO ERRMSG
             DISPLAY ERROR-MESSAGE
           ELSE
             MOVE SPACES TO ERRMSG
             DISPLAY ERROR-MESSAGE
             MOVE 0 TO ERR.

       ENTER-APP.
           ACCEPT (20 , 14 ) SOAPPRBY.
           ACCEPT ESC-CODE FROM ESCAPE KEY.
           IF ESC-KEY
             DISPLAY CLEAR-SCREEN
             STOP RUN 
           ELSE IF SOAPPRBY = SPACES
             MOVE 1 TO ERR
             MOVE "PLEASE FILL-IN" TO ERRMSG
             DISPLAY ERROR-MESSAGE
           ELSE
             MOVE SPACES TO ERRMSG
             DISPLAY ERROR-MESSAGE
             MOVE 0 TO ERR.


       ITM-INPUT.

           MOVE 10 TO LIN.
           MOVE 0 TO TOTAL-AMOUNT.
           MOVE 1 TO ROW.
           PERFORM ITM-INPUT1 VARYING R FROM 1 BY 1 UNTIL R > 5.



       ITM-INPUT1.
           MOVE 1 TO ERR.
           PERFORM ITM-INPUT2 UNTIL ERR = 0 OR F2 OR F10.    

       ITM-INPUT2.      

           ACCEPT (LIN, 4) ITMNO.
           ACCEPT ESC-CODE FROM ESCAPE KEY.
           IF ESC-KEY
             DISPLAY CLEAR-SCREEN
             STOP RUN
           ELSE IF F2
             PERFORM SAVE-ENTRIES
           ELSE IF F10
             PERFORM CANCEL-ENTRIES

           ELSE

             MOVE SPACES TO ERRMSG
             PERFORM ITM-INPUT3.

       ITM-INPUT3.
           MOVE 0 TO ERR               
           READ ITEM-FILE INVALID KEY MOVE 1 TO ERR.
           IF ERR = 1 
               MOVE "ITMNO NO. NOT FOUND." TO ERRMSG
               DISPLAY ERROR-MESSAGE
           ELSE

              DISPLAY ERROR-MESSAGE
              PERFORM ITM-INPUT4.


       ITM-INPUT4.

              DISPLAY (LIN , 10) ITMDESC
              DISPLAY (LIN , 41) ITMUM
              MOVE ITMPRICE TO E-PRICE
              DISPLAY (LIN , 52) E-PRICE
              DISPLAY (21 , 66 ) ITMQTYONHAND


              PERFORM VALIDATE-ITMQTY.


       VALIDATE-ITMQTY.

              ACCEPT (LIN , 48)QTYORD.
              MOVE QTYORD TO VAR-SODITMQTYORDER(R).   
              ACCEPT ESC-CODE FROM ESCAPE KEY.

              IF ESC-KEY
               DISPLAY CLEAR-SCREEN
               STOP RUN

              ELSE IF VAR-SODITMQTYORDER (R) > ITMQTYONHAND
                MOVE "INSUFFICIENT STOCK" TO ERRMSG
                DISPLAY ERROR-MESSAGE
              ELSE
                COMPUTE AMOUNT = VAR-SODITMQTYORDER (R) * ITMPRICE
                MOVE AMOUNT TO E-AMOUNT
                DISPLAY (LIN , 66)E-AMOUNT
                ADD 1 TO LIN

                MOVE ITMNO TO VAR-ITMNO(R)
      *          MOVE ITMQTYONORDER TO VAR-ITMQTYONORDER(R).
                MOVE ITMDESC TO VAR-ITMDESC(R)
                MOVE ITMUM TO VAR-ITMUM(ROW)


                COMPUTE TOTAL-QTYONORDER = ITMQTYONORDER + 
                VAR-SODITMQTYORDER (ROW)

                MOVE ITMPRICE TO VAR-ITMPRICE(R)
                MOVE AMOUNT TO VAR-AMOUNT(R)
                COMPUTE TOTAL-AMOUNT =  TOTAL-AMOUNT + AMOUNT
                MOVE TOTAL-AMOUNT TO E-TOTAL
                DISPLAY (17 , 66) E-TOTAL
                COMPUTE VAR-QTYONHAND = ITMQTYONHAND 
                - VAR-SODITMQTYORDER(R)

                ADD 1 TO ROW.
       SAVE-ENTRIES.

           PERFORM SAVE-SOD VARYING R FROM 1 BY 1 UNTIL
           R = ROW.

           PERFORM SAVE-SO.
           MOVE LBLSONO TO CUSLASTSONO.
           REWRITE CUSTOMER-RECORD.
           MOVE LBLSONO TO SYS-LASTSONO.    
           REWRITE SYSTEM-RECORD.
           MOVE "ENTRIES RECORDED." TO ERRMSG.
           DISPLAY ERROR-MESSAGE.
           PERFORM INITIALIZE-ITEMREC. 

       SAVE-SOD.
           MOVE LBLSONO TO SODSONO.
           MOVE VAR-ITMNO(R) TO SODITMNO.
           MOVE VAR-SODITMQTYORDER(R) TO SODQTYORD.
           MOVE VAR-ITMPRICE(R) TO SODUPRICE.
           MOVE VAR-AMOUNT(R) TO SODAMOUNT.
           WRITE SOD-RECORD. 
           PERFORM SAVE-ITEM.

       SAVE-ITEM.
           MOVE VAR-ITMNO(R) TO SODITMNO.
           READ ITEM-FILE.
           MOVE VAR-QTYONHAND TO ITMQTYONHAND.
           MOVE TOTAL-QTYONORDER TO ITMQTYONORDER.
           MOVE LBLSONO TO ITMLASTONO.
           REWRITE ITEM-RECORD.

       SAVE-SO.

           MOVE LBLSONO TO SONO.
           MOVE MY-DATE TO SODATE.
           MOVE CUSNO TO SOCUSNO.
           MOVE TOTAL-AMOUNT TO SOTOTAL.
      *     MOVE PREPBY TO SOPREPBY. 
      *     MOVE APPBY TO SOAPPRBY.            
           MOVE "O" TO SORECSTAT.
           WRITE SO-RECORD.


       CANCEL-ENTRIES.
           MOVE "ENTRIES CANCELLED" TO ERRMSG.
           PERFORM INITIALIZE-ITEMREC.

       INITIALIZE-ITEMREC.
           MOVE ZEROES TO CUSTOMER-RECORD.
           MOVE ZEROES TO CUSNO ITMNO. 
           MOVE ZEROES TO CUSBALANCE CUSCREDITLIMIT.
           MOVE ZEROES TO SODAMOUNT SODUPRICE.
           MOVE ZEROES TO TOTAL-AMOUNT SORECSTAT.
           MOVE 0 TO R.

           MOVE SPACES TO TEMP-STR.
           MOVE SPACES TO SOPREPBY SOAPPRBY.
           MOVE "A" TO ITMRECSTAT.
           MOVE 'O' TO SODRECSTAT.

           MOVE SPACE TO SOPAYMODE MOD.
           MOVE ZEROES TO SODQTYINV ITMQTYONHAND.
           MOVE SPACES TO CUSNAME CUSADDR.

       CLEAN.
           MOVE SPACES TO CUSNAME.
           MOVE SPACES TO CUSADDR.






我没有像你的例子那样使用因为我不知道如何使用它。编译时给我一个错误。先生的方式先生,为什么如果我有文件状态检查我的程序将不会是运行时并且它将写入so.dat和sod.dat并且我的sono将被生成但是如果我将删除文件状态,我的程序将在输入仅3个或少于5个项目时输入输出错误。请您启发我的想法。提前谢谢你。

1 个答案:

答案 0 :(得分:1)

我强烈建议您使用END-IF语句来整理代码,因为这会使代码更容易理解和阅读。如果你只是依靠全停,那么你就有可能错过一次,这似乎是“CHK-MOD”段落中“STOP RUN”行的情况。虽然这可能不是您的文件错误的问题。

另外,我建议你弄清楚如何使用EVALUATE语句,因为这些可以使代码更具可读性。请考虑以下对ENTER-MONTH段落的替代方法:

ENTER-MONTH.
       ACCEPT(4 , 65)MY-MONTH.
       ACCEPT ESC-CODE FROM ESCAPE KEY.
       EVALUATE TRUE
          WHEN F2
             PERFORM SAVE-ENTRIES

          WHEN F10
             PERFORM CANCEL-ENTRIES

          WHEN MY-MONTH > 12
             MOVE "INVALID MONTH" TO ERRMSG
             DISPLAY ERROR-MESSAGE

          WHEN OTHER
             MOVE SPACES TO ERRMSG
             DISPLAY ERROR-MESSAGE
             MOVE 0 TO FLAG
       END-EVALUATE.

你的SAVE-ITEM段落有点神秘。 ITEM-FILE的关键是ITMNO,但是您在READ之前将Item No移动到SODITMNO中。此外,您假设存在ITEM-FILE记录并始终执行REWRITE。如果记录不存在怎么办?

最后,我不确定这是否重要,但您没有定义DECLARATIVES部分。这通常是捕获I / O错误并从中继续运行的方法。

我还会在您的文件状态(ITEM-STATUS,SO-STATUS,SOD-STATUS等)上放置88个Level值,以便您可以测试这些值而不是状态值。例如,ITEM-STATUS下的ITEM-NOT-FOUND可能有88级值。

如果可以,请使用这些可读性改进来编辑源代码,我们可能会更好地看到您的错误。