文件的数据验证和格式化输出

时间:2015-01-28 21:44:47

标签: cobol mainframe

我试图编写一个程序来确定给定文件中是否出现了不同类型的错误。我要发布我的整个代码,因为我真的不知道我在哪里出错了。它只是对我发出警告。数据验证是2100错误检查。

   IDENTIFICATION DIVISION.
   PROGRAM-ID. ASSIGNMENT1.
   AUTHOR.  AARON.

  ******************************************************************
   ENVIRONMENT DIVISION.
  *  defines the external files - an input file and output file
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.


       SELECT DATVAL02 ASSIGN TO DATAIN
          FILE STATUS IS EF-STATUS.

       SELECT REPORT-FILE ASSIGN TO DATAOUT
          FILE STATUS IS PF-STATUS.

   DATA DIVISION.

   FILE SECTION.
   FD DATVAL02.
   01 SALES-RECORD.
       05 RECORD-CODE   PIC XX.
       05 FILLER        PIC X.
       05 VEND-NUM      PIC X(8).
       05 DATE-DUE.
            05 YEAR-DUE      PIC XX.
            05 MONTH-DUE     PIC XX.
            05 DAY-DUE       PIC XX.
       05 VEND-NAME     PIC X(20).
       05 FILLER        PIC XXX.
       05 AMT-DUE       PIC S9(6)V99.


   FD REPORT-FILE.
   01 REPORT-RECORD                PIC X(80).

   WORKING-STORAGE SECTION.

   01 FLAGS-AND-ACCUMLATORS.
       05 VALID-RECORDS     PIC S99 VALUE 0.
       05 INVALID-RECORDS   PIC S99 VALUE 0.
       05 EF-STATUS       PIC 99  VALUE 0.
       05 PF-STATUS       PIC 99  VALUE 0.
       05 A-ERROR           PIC X VALUE SPACE.
       05 C-ERROR           PIC X VALUE SPACE.
       05 E-ERROR           PIC X VALUE SPACE.
       05 F-ERROR           PIC X VALUE SPACE.
       05 B-ERROR           PIC X VALUE SPACE.
       05 D-ERROR           PIC X VALUE SPACE.
       05 G-ERROR           PIC X VALUE SPACE.
       05 H-ERROR           PIC X VALUE SPACE.
       05 I-ERROR           PIC X VALUE SPACE.
       05 A-AST             PIC XX VALUE SPACES.
       05 BC-AST            PIC X(8) VALUE SPACES.
       05 D-AST             PIC XX VALUE SPACES.
       05 E-AST             PIC XX VALUE SPACES.
       05 F-AST             PIC XX VALUE SPACES.
       05 G-AST             PIC X(15) VALUE SPACES.
       05 H-AST             PIC X(15) VALUE SPACES.
       05 I-AST             PIC X(8) VALUE SPACES.
       05 END-OF-FILE      PIC XXX VALUE "NO".
       05 ERROR-FLAG        PIC XXX VALUE SPACES.
       05 ERROR-FLAG2       PIC XXX VALUE SPACES.
       05 ERROR-FILLER      PIC XXX VALUE SPACES.
       05 VC                PIC XX VALUE "VC".
       05 NOO               PIC XX VALUE "NO".
       05 D-CHECK           PIC S9999999V99.
       05 DAY-DUE-NUM       PIC 99.
       05 MONTH-DUE-NUM     PIC 99.


   01 HEADING-LINE-1.
       05           PIC X(15) VALUE SPACES.
       05           PIC X(24) VALUE
            "VENDOR RECORD VALIDATION".
       05           PIC X(24) VALUE SPACES.
       05           PIC X(6)  VALUE
            "PAGE 1".

   01 HEADING-LINE-2.
       05           PIC XX VALUE
            "RC".
       05           PIC X VALUE SPACE.
       05           PIC X(8) VALUE
            "VENDOR #".
       05           PIC XX VALUE SPACES.
       05           PIC X(8) VALUE
            "DATE DUE".
       05           PIC XX VALUE SPACES.
       05           PIC X(11) VALUE
            "VENDOR NAME".
       05           PIC X(6) VALUE SPACES.
       05           PIC X(10) VALUE
            "AMOUNT DUE".
       05           PIC XXX VALUE SPACES.
       05           PIC X(16) VALUE
            "-- ERROR CODES--".

    01 DETAIL-LINE.
       05 RECORD-CODE-OUT           PIC XX.
       05                           PIC X VALUE SPACE.
       05 VEND-NUM-OUT              PIC X(8).
       05                           PIC XX VALUE SPACES.
       05 YEAR-DUE-OUT              PIC XX.
       05 MONTH-DUE-OUT             PIC XX.
       05 DAY-DUE-OUT               PIC XX.
       05                           PIC XX VALUE SPACES.
       05 VEND-NAME-OUT             PIC X(20).
       05                           PIC XX VALUE SPACES.
       05 AMT-DUE-OUT               PIC 999,999.99.
       05                           PIC XX VALUE SPACES.
       05 A-ERROR-OUT               PIC X VALUE SPACES.
       05                           PIC XX VALUE SPACES.
       05 B-ERROR-OUT               PIC X VALUE SPACE.
       05                           PIC XX VALUE SPACES.
       05 C-ERROR-OUT               PIC X VALUE SPACE.
       05                           PIC XX VALUE SPACES.
       05 D-ERROR-OUT               PIC X VALUE SPACE.
       05                           PIC XX VALUE SPACES.
       05 E-ERROR-OUT               PIC X VALUE SPACE.
       05                           PIC XX VALUE SPACES.
       05 F-ERROR-OUT               PIC X VALUE SPACE.
       05                           PIC XX VALUE SPACES.
       05 G-ERROR-OUT               PIC X VALUE SPACE.
       05                           PIC XX VALUE SPACES.
       05 H-ERROR-OUT               PIC X VALUE SPACE.
       05                           PIC XX VALUE SPACES.
       05 I-ERROR-OUT               PIC X VALUE SPACE.

   01 ASTERISK-LINE.
       05 A-AST-OUT                 PIC XX VALUE SPACES.
       05                           PIC X VALUE SPACE.
       05 BC-AST-OUT                PIC X(8) VALUE SPACES.
       05                           PIC XX VALUE SPACES.
       05 D-AST-OUT                 PIC XX VALUE SPACES.
       05                           PIC X VALUE SPACE.
       05 E-AST-OUT                 PIC XX VALUE SPACES.
       05                           PIC X VALUE SPACE.
       05 F-AST-OUT                 PIC XX VALUE SPACES.
       05                           PIC XX VALUE SPACES.
       05 G-AST-OUT                 PIC X(15) VALUE SPACES.
       05                           PIC XX VALUE SPACES.
       05 I-AST-OUT                 PIC X(8) VALUE SPACES.
       05                           PIC XX VALUE SPACES.
       05 H-AST-OUT                 PIC X(8) VALUE SPACES.


   01 RECORD-TOTALS.
       05                           PIC X(16) VALUE
            "VALID RECORDS: ".
       05 VALID-RECORDS-OUT         PIC 99.
       05                           PIC XX VALUE SPACES.
       05                           PIC X(17) VALUE
            "INVALID RECORDS: ".
       05 INVALID-RECORDS-OUT       PIC 99.

   PROCEDURE DIVISION.

   1000-MAIN-CONTROL.
       PERFORM 2000-INITIALIZE.
       PERFORM UNTIL END-OF-FILE = "YES"
         READ DATVAL02
           AT END
             MOVE "YES" TO END-OF-FILE
           NOT AT END
             PERFORM 2100-ERROR-ROUTINE
             IF ERROR-FLAG = "YES"
                PERFORM 2500-PROCESS
                PERFORM 3000-PROCESS
                PERFORM 4200-REINITILIZE
             END-IF
             IF ERROR-FLAG = "NO"
                PERFORM 2500-PROCESS
             END-IF
         END-READ
       END-PERFORM.
       PERFORM 4000-PROCESS.
       PERFORM 4500-TERMINATE.
       STOP RUN.

   2000-INITIALIZE.
       OPEN INPUT DATVAL02.
       OPEN OUTPUT REPORT-FILE.

       WRITE REPORT-RECORD         FROM HEADING-LINE-1.
       WRITE REPORT-RECORD         FROM HEADING-LINE-2.

   2100-ERROR-ROUTINE.
       MOVE "NO"                   TO ERROR-FLAG.
       MOVE "NO"                   TO ERROR-FLAG2.

       IF VEND-NUM = SPACES
           MOVE "YES"              TO ERROR-FLAG
           MOVE "********"         TO BC-AST-OUT
           MOVE "B"               TO B-ERROR-OUT
       END-IF.

       IF VEND-NUM IS NOT NUMERIC AND ERROR-FLAG = NOO
           MOVE "YES"              TO ERROR-FLAG
           MOVE "********"        TO BC-AST-OUT
           MOVE "C"                TO C-ERROR-OUT
       END-IF.

       IF RECORD-CODE IS NOT = VC
           MOVE "YES"              TO ERROR-FLAG
           MOVE "**"               TO A-AST-OUT
           MOVE "A"                TO A-ERROR-OUT
       END-IF.

       IF DATE-DUE IS NOT NUMERIC
           MOVE "YES"              TO ERROR-FLAG2
           MOVE "YES"              TO ERROR-FLAG
           MOVE "**"               TO D-AST-OUT
           MOVE "D"               TO D-ERROR-OUT
           MOVE "**"              TO E-AST-OUT
           MOVE "**"              TO F-AST-OUT
       END-IF.

       IF DATE-DUE = 0 AND ERROR-FLAG2 = NOO
          IF AMT-DUE IS > 0
              MOVE "YES"           TO ERROR-FLAG
              MOVE "YES"           TO ERROR-FLAG2
              MOVE "**"           TO D-AST-OUT
              MOVE "D"             TO D-ERROR-OUT
              MOVE "**"           TO E-AST-OUT
              MOVE "**"           TO F-AST-OUT
          END-IF
       END-IF.

       MOVE DAY-DUE TO DAY-DUE-NUM.
       MOVE MONTH-DUE TO MONTH-DUE-NUM.

       IF DAY-DUE-NUM > 31 OR DAY-DUE < 0 AND ERROR-FLAG2 = NOO
           MOVE "YES"              TO ERROR-FLAG
           MOVE "**"              TO E-AST-OUT
           MOVE "E"                TO E-ERROR-OUT
       END-IF.

       IF MONTH-DUE-NUM > 12 OR < 1 AND ERROR-FLAG2 = NOO
           MOVE "YES"              TO ERROR-FLAG
           MOVE "**"             TO F-AST-OUT
           MOVE "F"                TO F-ERROR-OUT
       END-IF.

       IF VEND-NAME = SPACES
           MOVE "YES"              TO ERROR-FLAG
           MOVE "***************"               TO G-AST-OUT
           MOVE "G"                TO G-ERROR-OUT
       END-IF.

       IF VEND-NAME(1:1) IS EQUAL TO SPACE
           MOVE "YES"              TO ERROR-FLAG
           MOVE "***************"         TO H-AST-OUT
           MOVE "H"                TO H-ERROR-OUT

       IF AMT-DUE IS NOT NUMERIC
           MOVE "YES"              TO ERROR-FLAG
           MOVE "********"               TO I-AST-OUT
           MOVE "I"               TO I-ERROR-OUT
       END-IF.

       IF ERROR-FLAG = "YES"
            ADD 1 TO INVALID-RECORDS
       END-IF.

       IF ERROR-FLAG = "NO"
           ADD 1 TO VALID-RECORDS
       END-IF.



   2500-PROCESS.
       MOVE RECORD-CODE    TO RECORD-CODE-OUT.
       MOVE VEND-NUM       TO VEND-NUM-OUT.
       MOVE YEAR-DUE       TO YEAR-DUE-OUT.
       MOVE MONTH-DUE      TO MONTH-DUE-OUT.
       MOVE DAY-DUE        TO DAY-DUE-OUT.
       MOVE VEND-NAME      TO VEND-NAME-OUT.
       MOVE AMT-DUE        TO AMT-DUE-OUT.

       WRITE REPORT-RECORD FROM DETAIL-LINE.

   3000-PROCESS.
       WRITE REPORT-RECORD FROM ASTERISK-LINE.

   4000-PROCESS.
       MOVE VALID-RECORDS      TO VALID-RECORDS-OUT.
       MOVE INVALID-RECORDS    TO INVALID-RECORDS-OUT.
       WRITE REPORT-RECORD     FROM RECORD-TOTALS.

   4200-REINITILIZE.
       MOVE A-ERROR            TO A-ERROR-OUT.
       MOVE B-ERROR            TO B-ERROR-OUT.
       MOVE C-ERROR            TO C-ERROR-OUT.
       MOVE D-ERROR            TO D-ERROR-OUT.
       MOVE E-ERROR            TO E-ERROR-OUT.
       MOVE F-ERROR            TO F-ERROR-OUT.
       MOVE G-ERROR            TO G-ERROR-OUT.
       MOVE H-ERROR            TO H-ERROR-OUT.
       MOVE I-ERROR            TO I-ERROR-OUT.
       MOVE A-AST              TO A-AST-OUT.
       MOVE BC-AST             TO BC-AST-OUT.
       MOVE D-AST              TO D-AST-OUT.
       MOVE E-AST              TO E-AST-OUT.
       MOVE F-AST              TO F-AST-OUT.
       MOVE G-AST              TO G-AST-OUT.
       MOVE H-AST              TO H-AST-OUT.
       MOVE I-AST              TO I-AST-OUT.
       MOVE ERROR-FILLER       TO ERROR-FLAG.
       MOVE ERROR-FILLER       TO ERROR-FLAG2.
       MOVE A-AST              TO DAY-DUE-NUM.
       MOVE A-AST              TO MONTH-DUE-NUM.
   4500-TERMINATE.
       CLOSE DATVAL02, REPORT-FILE.

数据看起来像......

VC 10045380051005ABC ELECTRONICS        00001298
VT         000000                       00020000

希望实现这一目标

XX 9AAA9999  99/99/99       SHIFTED      12A 4GL 78   A   C   E F   H I
** ********     ** **  ***************   *** *** **

其中*在数据中出错。字母显示发现了什么错误。

1 个答案:

答案 0 :(得分:1)

在您的最新版本中,您创建了一个组项目(DATE-DUE),但您尚未调整从属于它的其他日期字段的级别编号。我已经将这三个级别设为10.为了方便我使用SYSIN数据,我在输入记录的末尾添加了一个32字节的FILLER。

我编译,得到一个4的RC / CC,所以linkedit / binder运行。

我使用了您的其他问题中的这些数据:

VC 10045380051005ABC ELECTRONICS 00001298 VC 050926XYZ COMPANY 00R00549 VT 12348760051115 QUALITY ASSURANCE CO 00400053 VC A14BCF80051201 00100930

获得此输出,没有异常终止:

               VENDOR RECORD VALIDATION                        PAGE 1        
RC VENDOR #  DATE DUE  VENDOR NAME      AMOUNT DUE   -- ERROR CODES--        
VC 10045380  051005  ABC ELECTRONICS       000,012.98                        
VC           050926  XYZ COMPANY           009,005.49     B                  
   ********                                                                  
VT 12348760  051115  QUALITY ASSURANCE CO  004,000.53  A                     
**                                                                           
VC A14BCF80  051201                        001,009.30        C           G  H
   ********            ***************            ********                   
VALID RECORDS:  01  INVALID RECORDS: 03 

我已粘贴您其他问题的数据。

请注意,如果您的实际数据不正确,您可能会收到金额字段的异常终止。

另请注意金额字段中的R发生了什么。您尚未对NUMERIC进行验证。


我现在已经编译并运行了两个更正程序(两个计数的VALUE子句和END-READ)。这是输出:

               VENDOR RECORD VALIDATION                        PAGE 1
RC VENDOR #  DATE DUE  VENDOR NAME      AMOUNT DUE   -- ERROR CODES--
VC 10045380  051005  ABC ELECTRONICS       000,01298                 
VT        0  000000                        000,20000     B           
   ********                                                          
VALID RECORDS:  01  INVALID RECORDS: 01                              

我使用了一个固定长度的文件,因为我无法访问你的实际文件,它必须是可变长度的(在FD中显式是好的,那么你就不会得到那些我信息的编译结束时的消息。)

你还有一些事情需要解决,但程序正在运行并产生输出。如果您对这些代码进行了更改并仍然存在问题,则表明您的文件出错了。

你有一个非常令人沮丧的问题,似乎归结为“环境”。您需要能够看到您的编译列表。如果编译失败(RC / CC高于4),那么您的linkedit / binder步骤将不会运行,并且您将无法获得新的可执行程序。我认为这是你的问题,但你需要你的导师帮忙解决如何找到编译列表并确认没有错误。

我没有使用Rational Developer,也不知道你是使用zPDT还是正在编译大型机,或者你是如何从Rational Developer会话中查看编译器输出的。

您的代码对于学习者来说基本上是可以的,并且可能已经持续了几天。您一直在努力解决与代码无关的问题,但不知道您的程序是否存在编译错误。基本上,除了几个拼写错误,它就在那里。

当您确实在您的环境中运行它时,请更新您的Code Review问题。


一个非常好的事情是,编译生成了你运行的程序的版本,无论它是否被滥用。

您可以显示编译程序的日期和时间:

   WORKING-STORAGE SECTION.
   01  W-WHEN-COMPILED                      PIC X(8)BX(8).
   ...

在做任何其他事情之前,除了确定这是CALLed子程序中的第一次之外,还有以下内容:

   MOVE WHEN-COMPILED                TO W-WHEN-COMPILED
   DISPLAY 
           "Program XXXXXXXX compiled on "
           W-WHEN-COMPILED

您获得的输出将是该程序实际编译的日期/时间,与编译列表中的日期/时间完全匹配。

我已经使用了这样的代码,并将其推荐给其他人,已有30多年的历史,它已经节省了大量的时间。

还有一个内在的功能,即编译时。这是相同的,但是有四位数的年份。因为在可预见的未来,今年的CC将是20,你可以选择做哪一个。两者都在编译时解决,对运行时的影响最小。


您没有END-READ。这为您提供了编译的E级诊断,返回代码/条件代码为8,并且您之后的关联/绑定步骤可能尚未运行(请查看文件2中的步骤的COND)为你的工作假脱机。)

以下是您的代码提醒:

 PERFORM UNTIL END-OF-FILE = "YES"
     READ DATVAL02
       AT END
         MOVE "YES" TO END-OF-FILE
       NOT AT END
         PERFORM 2100-ERROR-ROUTINE
         IF ERROR-FLAG = "YES"
            PERFORM 2500-PROCESS
            PERFORM 3000-PROCESS
         END-IF
         IF ERROR-FLAG = "NO"
            PERFORM 2500-PROCESS
         END-IF
   END-PERFORM.

这是END-READ的样子:

 PERFORM UNTIL END-OF-FILE = "YES"
     READ DATVAL02
       AT END
         MOVE "YES" TO END-OF-FILE
       NOT AT END
         PERFORM 2100-ERROR-ROUTINE
         IF ERROR-FLAG = "YES"
            PERFORM 2500-PROCESS
            PERFORM 3000-PROCESS
         END-IF
         IF ERROR-FLAG = "NO"
            PERFORM 2500-PROCESS
         END-IF
       END-READ
   END-PERFORM

由于没有链接任何新程序,您仍在运行旧程序并仍然收到旧错误。


您正在添加未提供初始值的非二进制字段。

   05 VALID-RECORDS     PIC S99.
   05 INVALID-RECORDS   PIC S99.

   IF ERROR-FLAG = "YES"
        ADD 1 TO INVALID-RECORDS
   END-IF.

   IF ERROR-FLAG = "NO"
       ADD 1 TO VALID-RECORDS
   END-IF.

没有初始值(来自VALUE子句,或MOVE或甚至是恐惧INITIALIZE),该值未定义且不太可能对分区十进制字段有效,因此S0C7。

看看这个:https://stackoverflow.com/a/17102485/1927206,看看你是否可以从你计划失败的确切位置开始。


编译干净的程序,RC 0并没有诊断消息,并且运行时没有异常终止:

   ID DIVISION.                                                     
   PROGRAM-ID. VARA.                                                
   ENVIRONMENT DIVISION.
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.


       SELECT DATVAL02 ASSIGN TO DATAIN
          FILE STATUS IS EF-STATUS.

       SELECT REPORT-FILE ASSIGN TO DATAOUT
          FILE STATUS IS PF-STATUS.

   DATA DIVISION.

   FILE SECTION.
   FD DATVAL02 RECORDING MODE F.
   01 SALES-RECORD.
       05 RECORD-CODE   PIC XX.
       05 FILLER        PIC X.
       05 VEND-NUM      PIC X(8).
       05 YEAR-DUE      PIC 99.
       05 MONTH-DUE     PIC 99.
       05 DAY-DUE       PIC 99.
       05 VEND-NAME     PIC X(20).
       05 FILLER        PIC XXX.
       05 AMT-DUE       PIC S9(6)V99.
       05  FILLER PIC X(32).

   FD REPORT-FILE RECORDING MODE F.
   01 REPORT-RECORD                PIC X(80).

   WORKING-STORAGE SECTION.
   01  W-WHEN-COMPILED             PIC X(8)BX(8).

   01 FLAGS-AND-ACCUMLATORS.
       05 VALID-RECORDS     PIC S99 VALUE ZERO.
       05 INVALID-RECORDS   PIC S99 VALUE ZERO.
       05   EF-STATUS       PIC 99  VALUE 0.
       05   PF-STATUS       PIC 99  VALUE 0.
       05 A-ERROR           PIC X VALUE SPACE.
       05 C-ERROR           PIC X VALUE SPACE.
       05 E-ERROR           PIC X VALUE SPACE.
       05 F-ERROR           PIC X VALUE SPACE.
       05 B-ERROR           PIC X VALUE SPACE.
       05 D-ERROR           PIC X VALUE SPACE.
       05 G-ERROR           PIC X VALUE SPACE.
       05 H-ERROR           PIC X VALUE SPACE.
       05 I-ERROR           PIC X VALUE SPACE.
       05 A-AST             PIC XX VALUE SPACES.
       05 BC-AST            PIC X(8) VALUE SPACES.
       05 D-AST             PIC XX VALUE SPACES.
       05 E-AST             PIC XX VALUE SPACES.
       05 F-AST             PIC XX VALUE SPACES.
       05 G-AST             PIC X(15) VALUE SPACES.
       05 I-AST             PIC X(8) VALUE SPACES.
       05  END-OF-FILE      PIC XXX VALUE "NO".
       05 ERROR-FLAG        PIC XXX VALUE SPACES.
       05 ERROR-FLAG2       PIC XXX VALUE SPACES.
       05 VC                PIC XX VALUE "VC".
       05 NOO               PIC XX VALUE "NO".
       05 D-CHECK           PIC S9999999V99.


   01 HEADING-LINE-1.
       05           PIC X(15) VALUE SPACES.
       05           PIC X(24) VALUE
            "VENDOR RECORD VALIDATION".
       05           PIC X(24) VALUE SPACES.
       05           PIC X(6)  VALUE
            "PAGE 1".

   01 HEADING-LINE-2.
       05           PIC XX VALUE
            "RC".
       05           PIC X VALUE SPACE.
       05           PIC X(8) VALUE
            "VENDOR #".
       05           PIC XX VALUE SPACES.
       05           PIC X(8) VALUE
            "DATE DUE".
       05           PIC XX VALUE SPACES.
       05           PIC X(11) VALUE
            "VENDOR NAME".
       05           PIC X(6) VALUE SPACES.
       05           PIC X(10) VALUE
            "AMOUNT DUE".
       05           PIC XXX VALUE SPACES.
       05           PIC X(16) VALUE
            "-- ERROR CODES--".

   01 DETAIL-LINE.
       05 RECORD-CODE-OUT           PIC XX.
       05                           PIC X VALUE SPACE.
       05 VEND-NUM-OUT              PIC 9(8).
       05                           PIC XX VALUE SPACES.
       05 YEAR-DUE-OUT              PIC XX.
       05 MONTH-DUE-OUT             PIC XX.
       05 DAY-DUE-OUT               PIC XX.
       05                           PIC XX VALUE SPACES.
       05 VEND-NAME-OUT             PIC X(20).
       05                           PIC XX VALUE SPACES.
       05 AMT-DUE-OUT               PIC 999,999.99.
       05                           PIC XX VALUE SPACES.
       05 A-ERROR-OUT               PIC X.
       05                           PIC XX VALUE SPACES.
       05 B-ERROR-OUT               PIC X.
       05                           PIC XX VALUE SPACES.
       05 C-ERROR-OUT               PIC X.
       05                           PIC XX VALUE SPACES.
       05 D-ERROR-OUT               PIC X.
       05                           PIC XX VALUE SPACES.
       05 E-ERROR-OUT               PIC X.
       05                           PIC XX VALUE SPACES.
       05 F-ERROR-OUT               PIC X.
       05                           PIC XX VALUE SPACES.
       05 G-ERROR-OUT               PIC X.
       05                           PIC XX VALUE SPACES.
       05 H-ERROR-OUT               PIC X.
       05                           PIC XX VALUE SPACES.
       05 I-ERROR-OUT               PIC X.

   01 ASTERISK-LINE.
       05 A-AST-OUT                 PIC XX.
       05                           PIC X VALUE SPACE.
       05 BC-AST-OUT                PIC X(8).
       05                           PIC XX VALUE SPACES.
       05 D-AST-OUT                 PIC XX.
       05                           PIC X VALUE SPACE.
       05 E-AST-OUT                 PIC XX.
       05                           PIC X VALUE SPACE.
       05 F-AST-OUT                 PIC XX.
       05                           PIC XX VALUE SPACES.
       05 G-AST-OUT                 PIC X(15).
       05                           PIC XX VALUE SPACES.
       05 I-AST-OUT                 PIC X(8).
       05                           PIC XX VALUE SPACES.
       05 H-AST-OUT                 PIC X(8).

   01 RECORD-TOTALS.
       05                           PIC X(16) VALUE
            "VALID RECORDS: ".
       05 VALID-RECORDS-OUT         PIC 99.
       05                           PIC XX VALUE SPACES.
       05                           PIC X(17) VALUE
            "INVALID RECORDS: ".
       05 INVALID-RECORDS-OUT       PIC 99.

   PROCEDURE DIVISION.

   1000-MAIN-CONTROL.
       MOVE WHEN-COMPILED         TO W-WHEN-COMPILED
       DISPLAY
               "TEST PROGRAM COMPILED ON "
               W-WHEN-COMPILED
       PERFORM 2000-INITIALIZE.
       PERFORM UNTIL END-OF-FILE = "YES"
         READ DATVAL02
           AT END
             MOVE "YES" TO END-OF-FILE
           NOT AT END
             PERFORM 2100-ERROR-ROUTINE
             IF ERROR-FLAG = "YES"
                PERFORM 2500-PROCESS
                PERFORM 3000-PROCESS
             END-IF
             IF ERROR-FLAG = "NO"
                PERFORM 2500-PROCESS
             END-IF
         END-READ
       END-PERFORM.
       PERFORM 4000-PROCESS.
       PERFORM 4500-TERMINATE.
       STOP RUN.

   2000-INITIALIZE.
       OPEN INPUT DATVAL02.
       OPEN OUTPUT REPORT-FILE.

       WRITE REPORT-RECORD         FROM HEADING-LINE-1.
       WRITE REPORT-RECORD         FROM HEADING-LINE-2.

   2100-ERROR-ROUTINE.
       MOVE "NO"                   TO ERROR-FLAG.
       MOVE "NO"                   TO ERROR-FLAG2.

       IF VEND-NUM = SPACES
           MOVE "YES"              TO ERROR-FLAG
           MOVE "********"         TO BC-AST-OUT
           MOVE "B"                TO B-ERROR-OUT
       END-IF.


       IF ERROR-FLAG = "YES"
            ADD 1 TO INVALID-RECORDS
       END-IF.

       IF ERROR-FLAG = "NO"
           ADD 1 TO VALID-RECORDS
       END-IF.



   2500-PROCESS.
       MOVE RECORD-CODE    TO RECORD-CODE-OUT.
       MOVE VEND-NUM       TO VEND-NUM-OUT.
       MOVE YEAR-DUE       TO YEAR-DUE-OUT.
       MOVE MONTH-DUE      TO MONTH-DUE-OUT.
       MOVE DAY-DUE        TO DAY-DUE-OUT.
       MOVE VEND-NAME      TO VEND-NAME-OUT.
       MOVE AMT-DUE        TO AMT-DUE-OUT.

       WRITE REPORT-RECORD FROM DETAIL-LINE.

   3000-PROCESS.
       WRITE REPORT-RECORD FROM ASTERISK-LINE.

   4000-PROCESS.
       MOVE VALID-RECORDS      TO VALID-RECORDS-OUT.
       MOVE INVALID-RECORDS    TO INVALID-RECORDS-OUT.
       WRITE REPORT-RECORD     FROM RECORD-TOTALS.

   4500-TERMINATE.
       CLOSE DATVAL02, REPORT-FILE.