IDENTIFICATION DIVISION.
       PROGRAM-ID.    RELATOR-PROVIDER.
       AUTHOR.        COBOLware Services Ltda.
       DATE-WRITTEN.  99/99/9999.
       SECURITY.      *************************************************
                      *                                               *
                      *  Exemplo de programa provedor de informacoes  *
                      *  para o Relator 1.0                           *
                      *                                               *
                      *************************************************
       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-CHAVE
                  FILE STATUS       IS FS-MasterFile.

           SELECT AddFile1   ASSIGN TO DISK
                  ORGANIZATION      IS INDEXED
                  ACCESS MODE       IS RANDOM
                  RECORD KEY        IS AddFile1-CHAVE
                  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-CHAVE
                  LOCK MODE         IS AUTOMATIC
                  FILE STATUS       IS FS-AddFile2.

       DATA DIVISION.
       FILE SECTION.

       FD  MasterFile
           VALUE OF FILE-ID LB-MasterFile.

       01  MasterFile-REG.
           05 MasterFile-CHAVE.
              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-CHAVE PIC  9(005).

       FD  AddFile1
           VALUE OF FILE-ID LB-AddFile1.

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

       FD  AddFile2
           VALUE OF FILE-ID LB-AddFile2.

       01  AddFile2-REG.
           05 AddFile2-CHAVE.
              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.

       01  AREAS-DE-TRABALHO.
           05 FS-MasterFile             PIC  X(002) VALUE "00".
           05 LB-MasterFile             PIC  X(050) VALUE "MasterFile".
           05 FS-AddFile1               PIC  X(002) VALUE "00".
           05 LB-AddFile1               PIC  X(050) VALUE "AddFile1".
           05 FS-AddFile2               PIC  X(002) VALUE "00".
           05 LB-AddFile2               PIC  X(050) VALUE "AddFile2".

       LINKAGE SECTION.

       COPY RELATOR.CPY.
           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   FS-MasterFile > "09"
                OR   FS-AddFile1 > "09"
                OR   FS-AddFile2 > "09"
                     SET RELATOR-FIM TO TRUE
                END-IF
                MOVE HIGH-VALUES TO MasterFile-REG
                                    AddFile1-REG
                                    AddFile2-REG
                IF   RELATOR-COLUNA (1) = "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) = "CAMPO-1"
           AND  CAMPO-1 > 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-CHAVE NOT = AddFile1-CHAVE)
                INITIALIZE AddFile1-REG
                MOVE MasterFile-AddFile1-CHAVE TO AddFile1-CHAVE
                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-CHAVE NOT = AddFile2-CHAVE)
               INITIALIZE AddFile2-REG
               MOVE AddFile1-AddFile2-CHAVE TO AddFile2-CHAVE
               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 RELATOR-PROVIDER.