I am attempting to invoke a stored procedure (SQL) from a COBOL program. The stored procedure returns ONE result...
set, so the last (meaningful) statement in the stored procedure is OPEN cursor name. Once I issue the CALL in the COBOL program, how do I associate the result set to something meaningful, so that I may issue FETCH statements?
On DB2 UDB for iSeries, stored procedures result sets can only be accessed by clients utilizing the ODBC, JDBC, or CLI programming interfaces. This means High Level Languages (HLL) such as RPG and COBOL cannot fetch the result sets generated by an invoked stored procedure. Your COBOL program could utilize CLI APIs to invoke the stored procedure and process the result set. Another workaround is to use global temporary tables to simulate a stored procedure result set. A global table is used to hold temporary data for a database connection (job) or application. Instead of an SQL procedure returning data via a result set, that same data could be placed in a global temporary table and then the invoking COBOL program would just have to know the name of the temporary table in order to access the result set data.
Dig Deeper on DB2 UDB (universal databases)
Related Q&A from Kent Milligan
Create a host variable of the where in statement on the fly with dynamic SQL. Continue Reading
To solve the SQL error -321 on IBM i6.1, use the new values statement to overcome the error. If you are using an older release, declare a cursor ... Continue Reading
When working with DB2 files with columns that have both short and long names, there is no option choose which column names are returned via ODBC ... Continue Reading