An OpenESQL stored procedure can:
To call a stored procedure that returns no result sets, use the CALL embedded SQL statement, or the EXECSP embedded SQL statement if you want to ensure backward compatibility with the Micro Focus Embedded SQL Toolkit for Microsoft SQL Server. For complete details on using these statements, see the CALL and EXECSP topics.
If a stored procedure returns one or more result sets, you must first declare it using the DECLARE CURSOR statement. For example:
EXEC SQL DECLARE cursorName CURSOR FOR storedProcedureCallStatement END-EXEC
You then call the stored procedure just as you would any other type of cursor using the OPEN statement to open the cursor, followed by the FETCH statement to fetch result set rows.
EXEC SQL GET NEXT RESULT SET FOR cursorName END-EXEC
If your GET NEXT RESULT SET statement returns an SQLCODE of 0, another result set is available, and you can issue another GET NEXT RESULT SET to retrieve it. However, if GET NEXT RESULT SET returns an SQLCODE of 100, no additional result sets are available.
FOR :hvar
Where :hvar is an integer host variable containing a count of the number of rows to be passed.
You return multiple result sets to a calling program by declaring one or more cursors in a stored procedure, and defining each declared cursor to return multiple result sets by including multiple SELECT statements in its definition.
EXEC SQL DECLARE C1 CURSOR FOR SELECT CUSTID FROM COMPANY; SELECT CUSTNAME FROM COMPANY; END-EXEC EXEC SQL OPEN C1 END-EXEC EXEC SQL DECLARE C2 CURSOR FOR SELECT COMPNAME FROM COMPANY; END-EXEC EXEC SQL OPEN C2 END-EXEC
In this example, we have two cursors, C1 and C2, with C1 returning two result sets, and C2 returning one result set. Therefore, these cursors return a total of three result sets to the calling application.
EXEC SQL CLOSE C1 WITH RETURN TO CALLER END-EXEC EXEC SQL CLOSE C2 WITH RETURN TO CALLER END-EXEC
Once the cursors are closed, the result sets associated with them become available to the calling application.