IDENTIFICATION DIVISION.
       PROGRAM-ID. MATCH001.
       AUTHOR.     JIRO SUZUKI.
      *------------------------------------------------------------
      * マッチング(1:N)
      *------------------------------------------------------------
       ENVIRONMENT DIVISION.  
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
         SELECT  IN01  ASSIGN  TO  IN01NAME
                 ACCESS  MODE  IS  SEQUENTIAL.  
         SELECT  IN02  ASSIGN  TO  IN02NAME
                 ACCESS  MODE  IS  SEQUENTIAL.  
         SELECT  OUT1  ASSIGN  TO  OUT1NAME
                 ACCESS  MODE  IS  SEQUENTIAL.  
       DATA DIVISION.
       FILE SECTION.
       FD  IN01.
       COPY I-SECTION.
       FD  IN02.
       COPY I-EMPLOYEE.
       FD  OUT1.
       COPY O-EMPLOYEELIST.
       WORKING-STORAGE SECTION.
       01 IN01NAME.
         03              PIC X(16) VALUE "/HOME/OWNER/DAT/".
         03 NAME         PIC X(12) VALUE "MATCH001IN01".
         03              PIC X(04) VALUE ".DAT".
       01 IN02NAME.
         03              PIC X(16) VALUE "/HOME/OWNER/DAT/".
         03 NAME         PIC X(12) VALUE "MATCH001IN02".
         03              PIC X(04) VALUE ".DAT".
       01 OUT1NAME.
         03              PIC X(16) VALUE "/HOME/OWNER/DAT/".
         03 NAME         PIC X(12) VALUE "MATCH001OUT1".
         03              PIC X(04) VALUE ".DAT".
       01 CNS-AREA.
         03 CNS-INIT-MSG. 
           05            PIC X(10) VALUE "----- PGM=".
           05            PIC X(08) VALUE "MATCH001".
           05            PIC X(11) VALUE "START -----".
         03 CNS-TERM-MSG. 
           05            PIC X(10) VALUE "----- PGM=".
           05            PIC X(08) VALUE "MATCH001".
           05            PIC X(11) VALUE "END   -----".
       01 CNT-AREA.
         03 CNT-IN01     PIC 9(12) VALUE ZERO.
         03 CNT-IN02     PIC 9(12) VALUE ZERO.
         03 CNT-OUT1     PIC 9(12) VALUE ZERO.
       01 WORK-AREA.
         03 W-MST-KEY    PIC X(06).
         03 W-TRN-KEY    PIC X(06).
      *------------------------------------------------------------
       PROCEDURE DIVISION.
       MAIN SECTION.            *>全体処理
         PERFORM INIT-PROC THRU INIT-EXIT.
         PERFORM MAIN-PROC THRU MAIN-EXIT.
         PERFORM TERM-PROC THRU TERM-EXIT.
         STOP RUN.
      *------------------------------------------------------------
       INIT-PROC.               *>初期処理
         DISPLAY CNS-INIT-MSG.
         OPEN INPUT  IN01 IN02
              OUTPUT OUT1.
       INIT-EXIT.
      *------------------------------------------------------------
       MAIN-PROC.               *>主処理
         PERFORM READ-IN01.
         PERFORM READ-IN02.
         PERFORM UNTIL ( W-MST-KEY = HIGH-VALUE )
                   AND ( W-TRN-KEY = HIGH-VALUE )
           EVALUATE TRUE
             WHEN W-MST-KEY < W-TRN-KEY
               PERFORM MST-ONLY
             WHEN W-MST-KEY = W-TRN-KEY
               PERFORM MATCHING-PROC
             WHEN W-MST-KEY > W-TRN-KEY
               PERFORM TRN-ONLY
           END-EVALUATE
         END-PERFORM.
       MAIN-EXIT.
      *------------------------------------------------------------
       TERM-PROC.               *>終了処理
         CLOSE IN01 IN02
               OUT1.
         DISPLAY "IN01=" CNT-IN01.
         DISPLAY "IN02=" CNT-IN02.
         DISPLAY "OUT1=" CNT-OUT1.
         DISPLAY CNS-TERM-MSG.
       TERM-EXIT.
      *------------------------------------------------------------
       MATCHING-PROC.           *>マッチング処理
         INITIALIZE O-EMPLOYEELIST.
         MOVE SPACE TO O-EMPLOYEELIST.
      *
         MOVE I-EMPLOYEEID   OF I-EMPLOYEE    TO O-EMPLOYEEID.
         MOVE I-SECTIONID    OF I-EMPLOYEE    TO O-SECTIONID.
         MOVE I-EMPNAMEKANA  OF I-EMPLOYEE    TO O-EMPNAMEKANA.
         MOVE I-EMPNAMEKANJI OF I-EMPLOYEE    TO O-EMPNAMEKANJI.
         MOVE I-SECTIONNAMEKANA OF I-SECTION  TO O-SECTIONNAMEKANA.
         MOVE I-SECTIONNAMEKANJI OF I-SECTION TO O-SECTIONNAMEKANJI.
         PERFORM WRITE-OUT1.
         PERFORM READ-IN02.
      *------------------------------------------------------------
       MST-ONLY.                *>マスターのみの処理
         PERFORM READ-IN01.
      *------------------------------------------------------------
       TRN-ONLY.                *>トランのみの処理
         INITIALIZE O-EMPLOYEELIST.
         MOVE SPACE TO O-EMPLOYEELIST.
      *
         MOVE I-EMPLOYEEID   OF I-EMPLOYEE  TO O-EMPLOYEEID.
         MOVE I-SECTIONID    OF I-EMPLOYEE  TO O-SECTIONID.
         MOVE I-EMPNAMEKANA  OF I-EMPLOYEE  TO O-EMPNAMEKANA.
         MOVE I-EMPNAMEKANJI OF I-EMPLOYEE  TO O-EMPNAMEKANJI.
         PERFORM WRITE-OUT1.
         PERFORM READ-IN02.
      *------------------------------------------------------------
       READ-IN01.               *>IN01読込処理
         READ IN01 INTO I-SECTION
           AT END
             MOVE HIGH-VALUE TO W-MST-KEY
           NOT AT END
             MOVE I-SECTIONID OF I-SECTION TO W-MST-KEY
             ADD 1 TO CNT-IN01
         END-READ.
      *------------------------------------------------------------
       READ-IN02.               *>IN02読込処理
         READ IN02 INTO I-EMPLOYEE
           AT END
             MOVE HIGH-VALUE TO W-TRN-KEY
           NOT AT END
             MOVE I-SECTIONID OF I-EMPLOYEE TO W-TRN-KEY
             ADD 1 TO CNT-IN02
         END-READ.
      *------------------------------------------------------------
       WRITE-OUT1.              *>OUT1書込処理
         WRITE O-EMPLOYEELIST. 
         ADD 1 TO CNT-OUT1.