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.

9月 15, 2015

COBOL 顯示所有資料


        ID DIVISION.
        PROGRAM-ID. P0611.
        ENVIRONMENT DIVISION.
        INPUT-OUTPUT SECTION.
        FILE-CONTROL.
        COPY 'UTI\PC.FC'.
        DATA DIVISION.
        FILE SECTION.
        COPY 'UTI\PC.FD'.
        WORKING-STORAGE SECTION.
        01 EOF PIC 9 VALUE 0.
        77 PC-STATUS PIC X(02).

        77 CUT PIC 99 VALUE 0.
        PROCEDURE DIVISION.
        MAIN SECTION.
        MAIN-RTN.
            OPEN I-O PC-FILE.
            PERFORM UNTIL EOF = 1
                READ PC-FILE NEXT AT END MOVE 1 TO EOF
                END-READ
                ADD 1 TO CUT
            END-PERFORM
            SUBTRACT 1 FROM CUT
            PERFORM CUT TIMES
                DISPLAY PC-PASSWORD PC-PROP-ID PC-STCK-ID PC-OFFICE-NAME
                DISPLAY PC-CHINESE-CODE PC-PRINTER-CODE PC-CHAR-DENSITY
                DISPLAY PC-RATE
            END-PERFORM.
            CLOSE PC-FILE.
        MAIN-EXIT.

9月 08, 2015

COBOL 讀取資料


        ID DIVISION.
        PROGRAM-ID. P0612.
        ENVIRONMENT DIVISION.
        INPUT-OUTPUT SECTION.
        FILE-CONTROL.
        COPY 'UTI\PERSON.FC'.
        DATA DIVISION.
        FILE SECTION.
        COPY 'UTI\PERSON.FD'.
        WORKING-STORAGE SECTION.
        01 EOF PIC X VALUE 'N'.
        77 PERSON-FSTATUS PIC X(02).
        77 CUT PIC 9999 VALUE 0.
        PROCEDURE DIVISION.
        MAIN SECTION.
        MAIN-RTN.
            OPEN I-O PERSON-FILE.


                ACCEPT CUT.

                MOVE CUT TO PERSON-NO.
                READ PERSON-FILE
                END-READ.
                DISPLAY PERSON-NO PERSON-NAMEX PERSON-BANK-NO.
                DISPLAY PERSON-BIRTHDAY PERSON-MAIL-ADDR.
                DISPLAY PERSON-ARV-DATE PERSON-EDUC-XXX.
                DISPLAY PERSON-DEDUCT-DAY PERSON-DEDUCT-MONTH.
                DISPLAY PERSON-DUTY PERSON-INSURE-BEG-DATE.
                DISPLAY PERSON-INSURE-MONTH-PAY.
                DISPLAY WAGE-DATA.
                DISPLAY PERSON-PRO-SALARY-FLAG PERSON-PRO-SALARY.
                DISPLAY PERSON-PRO-PROMOTE-FLAG.



            CLOSE PERSON-FILE.
        MAIN-EXIT.