Previous Topic Next topic Print topic


Code Sample

Database Connectors is designed to simplify the process of working with relational databases as much as possible for the COBOL application developer. With this in mind, you can use the traditional COBOL OPEN OUTPUT verb to create a new database table. Modify the application from the previous example to have a new file description matching the existing file format, but intended to be your new table in the database.

$SET CREATEXFD
      IDENTIFICATION DIVISION.
      PROGRAM-ID. DBACCT.

      ENVIRONMENT DIVISION.

      INPUT-OUTPUT SECTION.
      FILE-CONTROL.

      SELECT ACCT-IN
              ASSIGN TO DISK "ACCTFIL"
              ORGANIZATION IS INDEXED
              ACCESS MODE IS DYNAMIC
              RECORD KEY IS
                 ACCTDO OF ACCT-IN-REC
              ALTERNATE RECORD KEY IS
                 SNAMEDO1 OF ACCT-IN-REC WITH DUPLICATES
              FILE STATUS IS ACCT-FILE-STATUS.

      SELECT ACCT-OUT
              ASSIGN TO DISK "DBACCTFIL"
              ORGANIZATION IS INDEXED
              ACCESS MODE IS DYNAMIC
              RECORD KEY IS
                 ACCTDO OF ACCT-OUT-REC
              ALTERNATE RECORD KEY IS
                 SNAMEDO1 OF ACCT-OUT-REC WITH DUPLICATES
              FILE STATUS IS ACCT-FILE-STATUS.

      DATA DIVISION.
      FILE SECTION.

      FD ACCT-IN
         RECORD IS VARYING FROM 63 to 383.
      01 ACCT-IN-REC.
      COPY "acctrec2.cpy".

      FD ACCT-OUT
         RECORD IS VARYING FROM 63 to 383.
      01 ACCT-OUT-REC.
      COPY "acctrec2.cpy".

      WORKING-STORAGE SECTION.
      01 ACCT-FILE-STATUS.
         05 ACCT-STATUS-KEY-1                   PIC X(1).
         05 ACCT-STATUS-KEY-2                   PIC X(1).
         05 ACCT-STATUS-KEY-2-BINARY REDEFINES ACCT-STATUS-KEY-2
                                                 PIC 9(2) COMP-X.
      01 USER-RETURN                            PIC X(10).

      PROCEDURE DIVISION.
      DECLARATIVES.
      FILE-ERR-HANDLING SECTION.
         USE AFTER STANDARD ERROR PROCEDURE ON ACCT-IN, ACCT-OUT.
      FILE-ERR.
         DISPLAY "File Error: ", ACCT-FILE-STATUS.
         DISPLAY "Press <return> to exit".
         ACCEPT USER-RETURN.
         STOP RUN.
      END DECLARATIVES.

      LEVEL-1 SECTION.
      MAIN-LOGIC.
     *     PERFORM OPEN-IN-FILE.
           PERFORM CREATE-OUT-FILE.
           STOP RUN.

      OPEN-IN-FILE.
           OPEN INPUT ACCT-IN.
           CLOSE ACCT-IN.

      CREATE-OUT-FILE.
           OPEN OUTPUT ACCT-OUT.
           CLOSE ACCT-OUT.

In the code sample above, you have:

Previous Topic Next topic Print topic