IDENTIFICATION DIVISION.
       PROGRAM-ID.    PROVIDER.
       AUTHOR.        COBOLware Services Ltda.
       DATE-WRITTEN.  99/99/9999.
       SECURITY.      *************************************************
                      *                                               *
                      *  Exemplo de programa provedor para o Relator  *
                      *                                               *
                      *************************************************
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES. DECIMAL-POINT IS COMMA.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.

           SELECT MasterFile ASSIGN TO DISK
                  ORGANIZATION      IS INDEXED
                  ACCESS MODE       IS SEQUENTIAL
                  RECORD KEY        IS MasterFile-KEY
                  FILE STATUS       IS FS-MasterFile.

           SELECT AddFile1   ASSIGN TO DISK
                  ORGANIZATION      IS INDEXED
                  ACCESS MODE       IS RANDOM
                  RECORD KEY        IS AddFile1-KEY
                  LOCK MODE         IS AUTOMATIC
                  FILE STATUS       IS FS-AddFile1.

           SELECT AddFile2   ASSIGN TO DISK
                  ORGANIZATION      IS INDEXED
                  ACCESS MODE       IS RANDOM
                  RECORD KEY        IS AddFile2-KEY
                  LOCK MODE         IS AUTOMATIC
                  FILE STATUS       IS FS-AddFile2.

       DATA DIVISION.
       FILE SECTION.

       FD  MasterFile
           VALUE OF FILE-ID LB-MasterFile.

       01  MasterFile-RECORD.
           05 MasterFile-KEY.
              10 MasterFile-CAMPO-1   PIC  9(005).
           05 MasterFile-CAMPO-2      PIC  X(030).
           05 MasterFile-CAMPO-3      PIC S9(006)V99.
           05 MasterFile-AddFile1-KEY PIC  9(005).

       FD  AddFile1
           VALUE OF FILE-ID LB-AddFile1.

       01  AddFile1-RECORD.
           05 AddFile1-KEY.
              10 AddFile1-CAMPO-4     PIC  9(005).
           05 AddFile1-CAMPO-5        PIC  X(030).
           05 AddFile1-CAMPO-6        PIC  9(008).
           05 AddFile1-AddFile2-KEY   PIC  9(005).

       FD  AddFile2
           VALUE OF FILE-ID LB-AddFile2.

       01  AddFile2-RECORD.
           05 AddFile2-KEY.
              10 AddFile2-CAMPO-7     PIC  9(005).
           05 AddFile2-CAMPO-8        PIC  X(030).
           05 AddFile2-CAMPO-9        PIC  9(014).
           05 AddFile2-CAMPO-10       PIC  9(008).

       WORKING-STORAGE SECTION.

       COPY CWFSLB REPLACING ==(FileName)== BY  MasterFile
                                     SPACES BY "MasterFile".
       COPY CWFSLB REPLACING ==(FileName)== BY  AddFile1
                                     SPACES BY "AddFile1".
       COPY CWFSLB REPLACING ==(FileName)== BY  AddFile2
                                     SPACES BY "AddFile2".
       LINKAGE SECTION.

       COPY RELATOR.
           03 MasterFile-RELATOR.
              04 CAMPO-1       PIC  9(005).
              04 CAMPO-2       PIC  X(030).
              04 CAMPO-3       PIC S9(006)V99. *> "V"
           03 AddFile1-RELATOR.
              04 CAMPO-4       PIC  9(005).
              04 CAMPO-5       PIC  X(030).
              04 CAMPO-6       PIC  9(008).    *> "D" DDMMAAAA
           03 AddFile2-RELATOR.
              04 CAMPO-7       PIC  9(005).
              04 CAMPO-8       PIC  X(030).
              04 CAMPO-9       PIC  9(014).
              04 CAMPO-10      PIC  9(008).    *> "E" 99999-999

       PROCEDURE DIVISION USING PARAMETROS-RELATOR.

       000-INICIO.

           ON   1
                INITIALIZE RELATOR-CAMPOS
                OPEN INPUT MasterFile AddFile1 AddFile2
                IF   NOT OK-MasterFile
                OR   NOT OK-AddFile1 
                OR   NOT OK-AddFile2 
                     SET RELATOR-FIM TO TRUE
                END-IF
                MOVE HIGH-VALUES TO MasterFile-RECORD
                                    AddFile1-RECORD
                                    AddFile2-RECORD
                IF   RELATOR-COLUNA (1) EQUAL "CAMPO-1"
                     MOVE RELATOR-MENOR (1) (1: LENGTH OF CAMPO-1)
                       TO MasterFile-CAMPO-1
                     START MasterFile KEY NOT LESS MasterFile-CAMPO-1
                END-IF.

           READ MasterFile IGNORE LOCK
                AT  END
                    SET RELATOR-FIM TO TRUE
                NOT END
                    PERFORM 110-MOVER-MasterFile THRU 110-99-FIM
                    PERFORM 120-MOVER-AddFile1   THRU 120-99-FIM
                    PERFORM 130-MOVER-AddFile2   THRU 130-99-FIM
           END-READ.

           IF   RELATOR-COLUNA (1) EQUAL "CAMPO-1"
           AND  CAMPO-1 GREATER RELATOR-MAIOR (1) (1: LENGTH OF CAMPO-1)
                SET RELATOR-FIM TO TRUE
           END-IF

           IF   RELATOR-FIM
                CLOSE MasterFile
                CLOSE AddFile1
                CLOSE AddFile2
           END-IF.

       000-99-FIM. GOBACK.

       110-MOVER-MasterFile.

           INITIALIZE MasterFile-RELATOR

           MOVE MasterFile-CAMPO-1 TO CAMPO-1
           MOVE MasterFile-CAMPO-2 TO CAMPO-2
           MOVE MasterFile-CAMPO-3 TO CAMPO-3.

       110-99-FIM. EXIT.

       120-MOVER-AddFile1.

           IF  (MasterFile-AddFile1-KEY NOT EQUAL AddFile1-KEY)
                INITIALIZE AddFile1-RECORD
                MOVE MasterFile-AddFile1-KEY TO AddFile1-KEY
                READ AddFile1 IGNORE LOCK
                INVALID KEY
                        MOVE "Nao encontrado" TO AddFile1-CAMPO-5
                END-READ
                INITIALIZE AddFile1-RELATOR
                MOVE AddFile1-CAMPO-4 TO CAMPO-4
                MOVE AddFile1-CAMPO-5 TO CAMPO-5
                MOVE AddFile1-CAMPO-6 TO CAMPO-6
           END-IF.

       120-99-FIM. EXIT.

       130-MOVER-AddFile2.

           IF  (AddFile1-AddFile2-KEY NOT EQUAL AddFile2-KEY)
               INITIALIZE AddFile2-RECORD
               MOVE AddFile1-AddFile2-KEY TO AddFile2-KEY
               READ AddFile2 IGNORE LOCK
                    INVALID KEY
                    MOVE "Nao encontrado" TO AddFile2-CAMPO-8
               END-READ
               INITIALIZE AddFile2-RELATOR
               MOVE AddFile2-CAMPO-7  TO CAMPO-7
               MOVE AddFile2-CAMPO-8  TO CAMPO-8
               MOVE AddFile2-CAMPO-9  TO CAMPO-9
               MOVE AddFile2-CAMPO-10 TO CAMPO-10
           END-IF.

       130-99-FIM. EXIT.

       END PROGRAM PROVIDER.