Blog
DB2utor

Categories

March 15, 2010

Stored Procedures and DB2

Have you ever wanted to issue a DB2 command from your program? It's actually possible, thanks to stored procedures. Procedure SYSPROC.ADMIN_COMMAND_DB2 allows you to issue DB2 commands. Information on this and other administrative stored procedures is available in the Administration Guide. For the different versions of DB2 manuals, go here.

Unfortunately, IBM doesn't provide a simple way of calling a stored procedure from TSO using SPUFI or some other command line mode. However, you can test the stored procedure from your client if you have DB2 Connect installed or Data Studio with a license to connect to z/OS.
To determine which databases and tablespaces are in a restrictive state, issue this from the DB2 command line:

call sysproc.admin_command_db2('-dis db(*) sp(*) restrict limit(*)', 34,TS,null,?,?,?,?,?,?,?,?)

(Note: The third parameter, TS, instructs the stored procedure to parse the string in parameter 1 as a  –DISPLAY DATABASE (*) SPACENAM(*) statement and return table space information.) 

To learn which IBM administrative procedures are installed, query the DB2 catalog. The following query can be used to list all install procedures owned by SYSPROC, which is usually the schema owner for these procedures:

SELECT SUBSTR(SCHEMA,1,8) AS SCHEMA
           , SUBSTR(NAME,1,18) AS NAME
 FROM SYSIBM.SYSROUTINES
WHERE SCHEMA = 'SYSPROC'
ORDER BY SCHEMA, NAME

If you use these procedures in your application, please respond in Comments.