Previous Topic Next topic Print topic


Code Sample

This exercise adds a new paragraph to the COBOL application that reads all records from the source file and writes them into the newly created database table.

  1. Modify the procedure division of your COBOL application as follows:
    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.
                PERFORM COPY-FILE.
                STOP RUN.
    
           OPEN-IN-FILE.
                OPEN INPUT ACCT-IN.
                CLOSE ACCT-IN.
    
    
           CREATE-OUT-FILE.
                OPEN OUTPUT ACCT-OUT.
                CLOSE ACCT-OUT.
    
           COPY-FILE.
               OPEN INPUT ACCT-IN.
               OPEN OUTPUT ACCT-OUT.
               READ ACCT-IN NEXT RECORD AT END CONTINUE.
               PERFORM UNTIL ACCT-FILE-STATUS = "10"
                   MOVE CORRESPONDING ACCT-IN-REC TO ACCT-OUT-REC
                   WRITE ACCT-OUT-REC
                   READ ACCT-IN NEXT RECORD AT END CONTINUE
               END-PERFORM.
               CLOSE ACCT-IN.
               CLOSE ACCT-OUT.
               DISPLAY "Conversion Complete.".
    
  2. Open your configuration file mssql.cfg and verify that it contains the following entry:
    
    ##################################################
    # The following is a list of individual assignments
    # of files to a filesystem other than the default
    ##################################################
    
    DBACCTFIL-HOST mssql
    
  3. Rebuild and run your application.

If the run was successful, all of your records should now be stored in the database table. You can use a tool such as Microsoft SQL Server Management Studio to verify your data. For example, you can do a quick check with the SQL command:

select  acctdo, snamedo1, snamedo2 from dbo.DBACCTFIL

which returns all of the account numbers and surnames from your newly created table. Another quick spot check you can use is the SQL command:

SELECT COUNT (*) FROM dbo.DBACCTFIL

This returns the total number of rows in your table. You can compare this result to the number of records returned by the rebuild /n acctfil command.

Previous Topic Next topic Print topic