*************************************************************************
**
** Source File Name = nodecat.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 :
** an example showing how to use the Catalog Node API in order to:
** - create/catalog a node
** - list a directory of nodes (showing what was created)
** - uncatalog the node
**
** APIs USED :
** CATALOG NODE sqlgctnd()
** OPEN NODE DIRECTORY SCAN sqlgnops()
** GET NEXT NODE DIRECTORY ENTRY sqlgngne()
** CLOSE NODE DIRECTORY SCAN sqlgncls()
** UNCATALOG NODE sqlguncn()
** 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. "nodecat".
Data Division.
Working-Storage Section.
copy "sqlenv.cbl".
copy "sqlca.cbl".
* Variables for catalog/uncatalog nodes
77 node-name pic x(8).
77 node-name-length pic s9(4) comp-5 value 0.
* Local Variables
77 rc pic s9(9) comp-5.
77 errloc pic x(80).
77 idx pic 9(9) comp-5.
* Variables for OPEN, GET, CLOSE, DEREFERENCE nodes
01 buffer pointer.
77 sqleninfo-sz pic 9(4) comp-5 value 460.
77 disp-host pic x(50).
77 handle pic 9(4) comp-5.
77 cbl-count pic 9(4) comp-5.
Procedure Division.
nodecat-pgm section.
display "Sample COBOL Program : nodecat.cbl".
* Initialize local variables
move "newnode" to node-name.
inspect node-name tallying node-name-length for characters
before initial " ".
display " ".
* Initialize SQL-NODE-STRUCT structure
move SQL-NODE-STR-ID to STRUCT-ID of SQL-NODE-STRUCT.
move "test node : newnode" to COMMENT of SQL-NODE-STRUCT.
move node-name to NODENAME of SQL-NODE-STRUCT.
move SQL-PROTOCOL-TCPIP to PROTOCOL of SQL-NODE-STRUCT.
* for TCP/IP connections, additional information on host and server
* needs to be entered
* Initialize SQL-NODE-TCPIP structure
move "hostname" to HOSTNAME of SQL-NODE-TCPIP.
move "servicename" to SERVICE-NAME of SQL-NODE-TCPIP.
*********************************
* CATALOG NODE API called *
*********************************
call "sqlgctnd" using
by reference sqlca
by reference SQL-NODE-STRUCT
by reference SQL-NODE-TCPIP
returning rc.
move "CATALOG NODE" to errloc.
call "checkerr" using SQLCA errloc.
display "Now listing all nodes".
perform list-nodes.
*********************************
* UNCATALOG NODE API called *
*********************************
call "sqlguncn" using
by value node-name-length
by reference sqlca
by reference node-name
returning rc.
move "UNCATALOG NODE" to errloc.
call "checkerr" using SQLCA errloc.
display "list all nodes [after uncataloged node]".
perform list-nodes.
end-nodecat. stop run.
list-nodes Section.
***************************************
* OPEN NODE DIRECTORY SCAN API called *
***************************************
call "sqlgnops" using
by reference handle
by reference cbl-count
by reference sqlca
returning rc.
if sqlcode equal SQLE-RC-NODE-DIR-EMPTY
display "--- Node directory is empty ---"
go to end-list-nodes.
move "OPEN NODE DIRECTORY SCAN" to errloc.
call "checkerr" using SQLCA errloc.
if cbl-count not equal to 0
perform get-node-entry thru end-get-node-entry
varying idx from 0 by 1 until idx equal cbl-count.
****************************************
* CLOSE NODE DIRECTORY SCAN API called *
****************************************
call "sqlgncls" using
by value handle
by reference sqlca
returning rc.
move "CLOSE NODE DIRECTORY SCAN" to errloc.
call "checkerr" using SQLCA errloc.
end-list-nodes. exit.
get-node-entry Section.
********************************************
* GET NEXT NODE DIRECTORY ENTRY API called *
********************************************
call "sqlgngne" using
by value handle
by reference buffer
by reference sqlca
returning rc.
**********************************
* DEREFERENCE ADDRESS API called *
**********************************
call "sqlgdref" using
by value sqleninfo-sz
by reference SQLENINFO
by reference buffer
returning rc.
* printing out the node information
move SQL-HOSTNAME of SQLENINFO to disp-host.
display "node name : ", SQL-NODE-NAME.
display "node comment : ", SQL-COMMENT of SQLENINFO.
display "node host name : ", disp-host.
display "node service name : ", SQL-SERVICE-NAME.
if SQL-PROTOCOL equal SQL-PROTOCOL-APPC
display "node protocol : APPC".
if SQL-PROTOCOL equal SQL-PROTOCOL-NETB
display "node protocol : NetBios".
if SQL-PROTOCOL equal SQL-PROTOCOL-APPN
display "node protocol : APPN".
if SQL-PROTOCOL equal SQL-PROTOCOL-TCPIP
display "node protocol : TCP/IP".
if SQL-PROTOCOL equal SQL-PROTOCOL-CPIC
display "node protocol : CPIC".
if SQL-PROTOCOL equal SQL-PROTOCOL-IPXSPX
display "node protocol : IPX/SPX".
display " ".
end-get-node-entry. exit.