************************************************************************* 
      ** 
      ** Source File Name = dbcmt.cbl  1.3 
      ** 
      ** Licensed Materials - Property of IBM 
      ** 
      ** (C) COPYRIGHT International Business Machines Corp. 1995, 1999  
      ** All Rights Reserved. 
      ** 
      ** US Government Users Restricted Rights - Use, duplication or 
      ** disclosure restricted by GSA ADP Schedule Contract with 
      ** 
      **    PURPOSE : to show the use of the CHANGE DATABASE COMMENT API. 
      **          - search through the list of the database directory. 
      **          - change the database comment. 
      ** 
      **    APIs USED : 
      **       OPEN DATABASE DIRECTORY SCAN           sqlgdosd() 
      **       GET NEXT DATABASE DIRECTORY ENTRY      sqlgdgne() 
      **       CLOSE DATABASE DIRECTORY SCAN          sqlgdcls() 
      **       CHANGE DATABASE COMMENT                sqlgdcgd() 
      **       INSTALL SIGNAL HANDLER                 sqlgisig() 
      **       DEREFERENCE ADDRESS                    sqlgdref() 
      ** 
      ** 
      ** For more information about these samples see the README file. 
      ** 
      ** For more information on programming in COBOL, see the: 
      **    -  "Programming in COBOL" section of the Application Development Guide. 
      ** 
      ** For more information on Building COBOL Applications, see the: 
      **    - "Building COBOL Applications" section of the Application Building Guide. 
      ** 
      ** For more information on the SQL language see the SQL Reference. 
      ** 
      ************************************************************************* 

       Identification Division.
       Program-Id. "dbcmt".

       Data Division.
       Working-Storage Section.

       copy "sqlenv.cbl".
       copy "sqlutil.cbl".
       copy "sqlca.cbl".

      * Local Variables 
       77 rc                  pic s9(9) comp-5.
       77 idx                 pic 9(4) comp-5.
       77 errloc              pic x(80).

      * Variables for the CHANGE DATABASE COMMENT API 
       77 new-comment-len   pic 9(4) comp-5 value 22.
       77 path-len          pic 9(4) comp-5 value 0.
       77 alias-len         pic 9(4) comp-5 value 0.
       77 new-comment       pic x(31) value "THIS IS A NEW Comment".
       77 path              pic x(1025).

      * Variables for OPEN/CLOSE DATABASE DIRECTORY APIs. 
       77 dbCount           pic 9(4) comp-5.
       77 dbHandle          pic 9(4) comp-5.

      * Variables for GET NEXT DATABASE DIRECTORY ENTRY API. 
       01 buffer            pointer.
       77 sqledinfo-sz      pic 9(4) comp-5 value 560.
       77 disp-drive        pic x(50).

       Procedure Division.
       dbcmt-pgm section.
           display "Sample COBOL Program : dbcmt.cbl".

      ************************** 
      * INSTALL SIGNAL HANDLER * 
      ************************** 
           call "sqlgisig" using
                                 by reference sqlca
                           returning rc.

      ****************************************** 
      * OPEN DATABASE DIRECTORY SCAN API called * 
      ******************************************* 
           call "sqlgdosd" using
                                 by value      path-len
                                 by reference  sqlca
                                 by reference  dbCount
                                 by reference  dbHandle
                                 by reference  path
                           returning rc.
           move "OPEN DATABASE DIRECTORY SCAN" to errloc.
           call "checkerr" using SQLCA errloc.

           perform get-db-entry thru end-get-db-entry
              varying idx from 0 by 1 until idx equal dbCount.

       after-change-comment.

      ******************************************** 
      * CLOSE DATABASE DIRECTORY SCAN API called * 
      ******************************************** 
           call "sqlgdcls" using
                                 by value      dbHandle
                                 by reference  sqlca
                           returning rc.
           move "CLOSE DATABASE DIRECTORY SCAN" to errloc.
           call "checkerr" using SQLCA errloc.

       end-dbcmt. stop run.

       get-db-entry section.

      ************************************************ 
      * GET NEXT DATABASE DIRECTORY ENTRY API called * 
      ************************************************ 
           call "sqlgdgne" using
                                 by value      dbHandle
                                 by reference  buffer
                                 by reference  sqlca
                           returning rc.

      ********************************** 
      * DEREFERENCE ADDRESS API called * 
      ********************************** 
           call "sqlgdref" using
                                 by value      sqledinfo-sz
                                 by reference  SQLEDINFO
                                 by reference  buffer
                           returning rc.

           if SQL-DBNAME equal "SAMPLE  "
              go to Change-Comment.

       end-get-db-entry. exit.

       Change-Comment Section.

           inspect SQL-ALIAS tallying alias-len for characters
              before initial " ".

           inspect new-comment tallying new-comment-len for characters
              before initial " ".

      *************************** 
      * CHANGE DATABASE COMMENT * 
      *************************** 
           call "sqlgdcgd" using
                                 by value       new-comment-len
                                 by value       path-len
                                 by value       alias-len
                                 by reference   sqlca
                                 by reference   new-comment
                                 by reference   path
                                 by reference   SQL-ALIAS
                           returning rc.
           move "CHANGE DATABASE COMMENT" to errloc.
           call "checkerr" using SQLCA errloc.

           display "CHANGE DATABASE COMMENT successful".
       end-Change-Comment. go to after-change-comment.