阅读索引文件(COBOL)的问题

时间:2011-05-28 02:45:10

标签: cobol

我在一个围绕阅读索引文件的程序中遇到了一个大问题。虽然该程序涉及另外两个工作正常,但这个仍然给我带来问题。以下是涉及它的所有内容的代码:

       SELECT PO-MASTER-FILE
           ASSIGN TO 'PO-INDEXED.DAT'
           ORGANIZATION IS INDEXED
           ACCESS IS RANDOM
           RECORD KEY IS PO-KEY
           FILE STATUS IS FILE-STATUS-CODE.

   DATA DIVISION.
   FILE SECTION.

   FD  PO-MASTER-FILE.
   01  PO-MASTER-RECORD.
       05  PO-KEY.
           10  PO-VEND-NUMBER-M        PIC X(4).
           10  PO-ORDER-ID-M           PIC X(8).

   WORKING-STORAGE SECTION.
       05  PO-KEY-S.
           10  POLI-VEND-NUMBER-S      PIC X(4).
           10  POLI-ORDER-ID-S         PIC X(8).

   SCREEN SECTION.
       05  LINE 07  COLUMN 23  VALUE 'NUMBER:'
               FOREGROUND-COLOR 10.
       05  LINE 07  COLUMN 50          PIC X(4)
               USING POLI-VEND-NUMBER-S
               FOREGROUND-COLOR 15 AUTO.
       05  LINE 08  COLUMN 23  VALUE 'ORDER ID:'
               FOREGROUND-COLOR 10.
       05  LINE 08  COLUMN 50          PIC X(8)
               USING POLI-ORDER-ID-S
               FOREGROUND-COLOR 15 AUTO.

   PROCEDURE DIVISION.
   100-MAIN.
       OPEN I-O   POLI-MASTER-FILE
                  PO-MASTER-FILE
                  ITEM-MASTER-FILE

       PERFORM 120-DISPLAY-SCREEN
           UNTIL FUNCTION-CODE-S = 'END' OR 'end'

           CLOSE  POLI-MASTER-FILE
                  PO-MASTER-FILE
                  ITEM-MASTER-FILE

           EXIT PROGRAM
           STOP RUN.

   120-DISPLAY-SCREEN.

  ****
       MOVE FUNCTION-CODE-S TO SAVE-FUNCTION-CODE

  ****
       MOVE POLI-VEND-NUMBER-S TO SAVE-VEND-NUMBER

  ****
       CALL 'DATETIME' USING DATE-TIME-PASS-AREA

       DISPLAY SCREEN-IMAGE
       ACCEPT SCREEN-IMAGE

       IF FUNCTION-CODE-S = 'END' OR 'end'
           CONTINUE
       ELSE
           PERFORM 200-PROCESS
       END-IF.

   200-PROCESS.
       MOVE SPACES TO ERROR-MESSAGE-S
       EVALUATE TRUE
           WHEN FUNCTION-CODE-S = 'INQ' OR 'inq'
               PERFORM 300-INQUIRY
           WHEN FUNCTION-CODE-S = 'ADD' OR 'add'
               PERFORM 400-ADD
           WHEN FUNCTION-CODE-S = 'CHG' OR 'chg'
               PERFORM 500-CHANGE
           WHEN FUNCTION-CODE-S = 'DEL' OR 'del'
               PERFORM 600-DELETE
           WHEN OTHER
               MOVE 'Invalid Function Code' TO ERROR-MESSAGE-S
       END-EVALUATE.

   400-ADD.
  ****
       PERFORM 900-VALIDATE-THE-FIELDS THRU 999-EXIT
       IF ERROR-MESSAGE-S = SPACES
           PERFORM 420-OK-TO-ADD-THE-RECORD
       ELSE
  ****
           MOVE SPACES TO POLI-DATE-ADDED-S
       END-IF.

   900-VALIDATE-THE-FIELDS.
       MOVE PO-KEY-S TO PO-KEY
       READ PO-MASTER-FILE
           INVALID KEY
               IF FILE-STATUS-CODE = '23'
                   MOVE 'Vendor Number Or Order ID Is Not Found'
                       TO ERROR-MESSAGE-S
                   GO TO 999-EXIT
               ELSE
                   MOVE FILE-STATUS-CODE TO UNEXPECTED-CODE
                   MOVE UNEXPECTED-CODE TO ERROR-MESSAGE-S
               END-IF
       END-READ

在此之后还有更多的验证代码,即使我在屏幕上留下POLI-VEND-NUMBER-SPOLI-ORDER-ID-S空白,程序也会跳过此部分,就好像它找到了一个文件一样。我至少可以说有点难过。任何帮助将不胜感激。谢谢你的时间。

1 个答案:

答案 0 :(得分:1)

好的,我发现了问题。似乎我遗漏了索引文件中的一些字段,因为在程序的这一部分中不需要它们。因此,记录不会加载和(由于某种原因)读取被跳过。基本上这是缺少的:

   FD  PO-MASTER-FILE.
   01  PO-MASTER-RECORD.
       05  PO-KEY.
           10  PO-VEND-NUMBER-M        PIC X(4).
           10  PO-ORDER-ID-M           PIC X(8).
       05  PO-DATE-ADDED-M.
               10 PO-DA-YEAR-M         PIC X(4).
               10 PO-DA-MONTH-M        PIC XX.
               10 PO-DA-DAY-M          PIC XX.

感谢任何看过这个并试图提供帮助的人。