DB2 10.5 for Linux, UNIX, and Windows

Considerations while programming REXX embedded SQL applications

REXX is an interpreted language, which means that no precompiler, compiler, or linker is used. Instead, three DB2® APIs are used to create DB2 applications in REXX. You can use these APIs to access different DB2 elements.

About this task

The three APIs that are available for creating embedded SQL applications in REXX are:
SQLEXEC
Supports the SQL language.
SQLDBS
Supports command-like versions of DB2 APIs.
SQLDB2
Supports a REXX specific interface to the command-line processor. See the description of the API syntax for REXX for details and restrictions on how this interface can be used.

Before using any of the DB2 APIs or issuing SQL statements in an application, you must register the SQLDBS, SQLDB2 and SQLEXEC routines. This notifies the REXX interpreter of the REXX/SQL entry points. The method you use for registering varies slightly between Windows-based and AIX® platforms.

Use the following examples for correct syntax for registering each routine:

Sample registration on Windows operating systems
/* ------------ Register SQLDBS with REXX  -------------------------*/ 
If Rxfuncquery('SQLDBS')  <> 0 then 
    rcy = Rxfuncadd('SQLDBS','DB2AR','SQLDBS') 
If rcy \= 0 then 
    do 
      say 'SQLDBS was not successfully added to the REXX environment' 
      signal rxx_exit 
    end 
 
/* ------------ Register SQLDB2 with REXX  -------------------------*/ 
If Rxfuncquery('SQLDB2')  <> 0 then 
    rcy = Rxfuncadd('SQLDB2','DB2AR','SQLDB2') 
If rcy \= 0 then 
    do 
      say 'SQLDB2 was not successfully added to the REXX environment' 
      signal rxx_exit 
    end 
 
/* ----------------- Register SQLEXEC with REXX  --------------------*/ 
If Rxfuncquery('SQLEXEC') <> 0 then 
    rcy = Rxfuncadd('SQLEXEC','DB2AR','SQLEXEC') 
If rcy \= 0 then 
    do 
      say 'SQLEXEC was not successfully added to the REXX environment' 
      signal rxx_exit 
    end 
Sample registration on AIX
  /* ------------ Register SQLDBS, SQLDB2 and SQLEXEC with REXX --------*/ 
 rcy = SysAddFuncPkg("db2rexx") 
 If rcy \= 0 then 
   do 
     say 'db2rexx was not successfully added to the REXX environment' 
     signal rxx_exit 
   end 

On Windows-based platforms, the RxFuncAdd commands need to be executed only once for all sessions.

On AIX, the SysAddFuncPkg should be executed in every REXX/SQL application.

Details on the Rxfuncadd and SysAddFuncPkg APIs are available in the REXX documentation for Windows-based platforms and AIX.

It is possible that tokens within statements or commands that are passed to the SQLEXEC, SQLDBS, and SQLDB2 routines could correspond to REXX variables. In this case, the REXX interpreter substitutes the variable's value before calling SQLEXEC, SQLDBS, or SQLDB2.

To avoid this situation, enclose statement strings in quotation marks (' ' or " "). If you do not use quotation marks, any conflicting variable names are resolved by the REXX interpreter, instead of being passed to the SQLEXEC, SQLDBS or SQLDB2 routines.