Accessing the DB2 REXX language support application programming interfaces

DB2® REXX Language Support includes several application programming interfaces that enable your REXX program to connect to a DB2 subsystem and execute SQL statements.

About this task

DB2 REXX Language Support includes the following application programming interfaces:

Start of changeDSNREXX CONNECTEnd of change
Start of change

Identifies the REXX task as a connected user of the specified DB2 subsystem. The DSNREXX plan resources are allocated by establishing an allied thread.

You should not confuse the DSNREXX CONNECT command with the DB2 SQL CONNECT statement.

You must execute the DSNREXX CONNECT command before your REXX program can execute SQL statements. Do not use the DSNREXX CONNECT command from a stored procedure.

A currently connected REXX task must be disconnected before switching to a different DB2 subsystem.

The syntax of the DSNREXX CONNECT command is:

Read syntax diagram
>>-+-----------------+--'CONNECT'--+-'subsystem-ID'-+----------><
   '-ADDRESS DSNREXX-'             '-REXX-variable--'   

Notes:
  1. CALL SQLDBS 'ATTACH TO' ssid is an alternative to ADDRESS DSNREXX 'CONNECT' ssid.
  2. The REXX-variable or 'subsystem-ID' string may also be a single member name in a data sharing group or the group attachment name.
Start of changeThe following example illustrates how to establish remote connections through the DSNREXX interface.
/* REXX */
/* Sample to connect to remote subsystems */
/* Connect to the local subsystem */
ADDRESS DSNREXX 'CONNECT' 'DB01'
/* Now connect to multiple remote subsystems */
ADDRESS DSNREXX 'EXECSQL CONNECT TO REMOTESYS1'
.
.
.
ADDRESS DSNREXX 'EXECSQL CONNECT TO REMOTESYS2'
.
.
.
End of change
End of change
DSNREXX EXECSQL
Executes SQL statements in REXX programs.

The syntax of the DSNREXX EXECSQL command is:

Read syntax diagram
>>-+-----------------+--'EXECSQL'--+-"SQL-statement"-+---------><
   '-ADDRESS DSNREXX-'             '-REXX-variable---'   

Notes:
  1. CALL 'SQLEXEC' "SQL-statement" is an alternative to ADDRESS DSNREXX 'EXECSQL' "SQL-statement".
  2. 'EXECSQL' and "SQL-statement" can be enclosed in either single or double quotation marks.
Start of changeDSNREXX DISCONNECTEnd of change
Start of change

Deallocates the DSNREXX plan and removes the REXX task as a connected user of DB2.

You should execute the DSNREXX DISCONNECT command to release resources that are held by DB2. Otherwise resources are not released until the REXX task terminates.

Do not use the DSNREXX DISCONNECT command from a stored procedure.

The syntax of the DSNREXX DISCONNECT command is:

Read syntax diagram
>>-+-----------------+--'DISCONNECT'---------------------------><
   '-ADDRESS DSNREXX-'                 

Note: CALL SQLDBS 'DETACH' is an alternative to ADDRESS DSNREXX 'DISCONNECT'.
End of change

These application programming interfaces are available through the DSNREXX host command environment. To make DSNREXX available to the application, invoke the RXSUBCOM function. The syntax is:

Read syntax diagram
>>-RXSUBCOM--(--+-'ADD'----+--,--'DSNREXX'--,--'DSNREXX'--)----><
                '-'DELETE'-'                                  

The ADD function adds DSNREXX to the REXX host command environment table. The DELETE function deletes DSNREXX from the REXX host command environment table.

The following example illustrates REXX code that makes DSNREXX available to an application.

'SUBCOM DSNREXX'                       /* HOST CMD ENV AVAILABLE?     */
IF RC THEN                             /* IF NOT, MAKE IT AVAILABLE   */
  S_RC = RXSUBCOM('ADD','DSNREXX','DSNREXX')
                                       /* ADD HOST CMD ENVIRONMENT    */
ADDRESS DSNREXX                        /* SEND ALL COMMANDS OTHER     */
                                       /* THAN REXX INSTRUCTIONS TO   */
                                       /* DSNREXX                     */
                                       /* CALL CONNECT, EXECSQL, AND  */
                                       /* DISCONNECT INTERFACES       */
⋮
S_RC = RXSUBCOM('DELETE','DSNREXX','DSNREXX')
                                       /* WHEN DONE WITH              */
                                       /* DSNREXX, REMOVE IT.         */
Related concepts:
REXX stored procedures