9月 30, 2015

COBOL 寫檔


        COPY 'UTI\UNY.FC'.

        DATA DIVISION.
        FILE SECTION.
        COPY 'UTI\UNIT.FD'.
        COPY 'UTI\UNY.FD'.

        WORKING-STORAGE SECTION.
        01 EOF PIC 9 VALUE 0.
        77 UNIT-STATUS PIC X(02).
            88 UNIT-FIND VALUE '00'.
            88 UNIT-ERR VALUE '94' '98'.
        77 WS01 PIC X(01).
        77 WK-FLG PIC 99.


        PROCEDURE DIVISION.

        MAIN SECTION.
        MAIN-RTN.
            MOVE 0 TO WK-FLG.
            MOVE SPACES TO WS01.
            OPEN I-O UNIT-FILE.
            OPEN OUTPUT UNY-FILE.


                PERFORM UNTIL EOF = 1
                    READ UNIT-FILE NEXT AT END MOVE 1 TO EOF
                    END-READ
                    IF UNIT-FIND
                         ADD 1 TO WK-FLG

                         MOVE UNIT-KEY TO UNY-KEY
                         MOVE UNIT-NAME TO UNY-NAME
                         MOVE UNIT-PEOPLE TO UNY-PEOPLE
                         MOVE UNIT-MAX TO UNY-MAX
                         MOVE UNIT-FLAG TO UNY-FLAG
                         MOVE UNIT-NOTE TO UNY-NOTE
                         MOVE ',' TO XA1 XA2 XA3 XA4 XA5
                         WRITE UNY-REC
                     END-IF
                END-PERFORM.
                DISPLAY WK-FLG.

            CLOSE UNIT-FILE UNY-FILE.
            STOP RUN.

        MAIN-EXIT.
            EXIT PROGRAM.

沒有留言: