Executing Stored Procedures
With Sybase stored procedures, an application has the option of processing return parameters, a return status, and/or the results of selects performed by the stored procedure.
It is very important that the application performs the correct sequence of processing in order to successfully process each part of a stored procedure as it is returned from the server.
NOTE: Because of the way that Sybase Client-Library handles result sets and return values, you must always process the result set before calling RWDBStoredProc::returnValue() or RWDBStoredProc::fetchReturnParams(). Calling either of these functions before processing the result set generates an empty reader, even for result sets generated by nested stored procedures.
Here’s an example of processing all of the different parts of the stored procedure. We'll use the procedure shown in Creating a Stored Procedure.
 
RWDBStoredProc royalty = aDb.storedProc("royalty");
float percentage;
royalty << myTitleId; // from application input
royalty << myNewSales; // from application input
royalty << &percentage; // will process on return
RWDBTable royaltyTable = royalty.execute().table();
RWDBReader reader = royaltyTable.reader();
while (reader())
{
// save or display the royalties
}
if (royalty.returnValue().asInt() == 1)
{
// continue processing with the royalty percentage
// returned
royalty.fetchReturnParams();
if (percentage > 10.0)
...
}
else
cout << "invalid title id" << endl;