Tips: Run and call iSeries stored procedures

Use these tips for running and calling iSeries™ stored procedures.

Running a stored procedure on the iSeries server:

ODBC provides a standard interface for calling stored procedures. The implementation of stored procedures differs significantly across various databases. This simple example follows the recommended approach for running a stored procedure on the iSeries server:

  1. Set up a create procedure statement for the stored procedure and create it. The creation of the stored procedure only needs to be done once and it does not have to be done through ODBC. The definition that it provides is available to all ODBC as well as integrated i5/OS™ applications.
  2. Prepare the stored procedure call.
  3. Bind the parameters of the procedure, indicating whether each parameter is to be used for input to the procedure, output from the procedure, or input/output.
  4. Call the stored procedure.

Calling iSeries stored procedures using Visual Basic:

Use care in coding the SQLBindParameter functions. Never use Visual Basic strings as a buffer when binding either columns (SQLBindCol) or parameters (SQLBindParameter). Instead, use byte arrays, which–unlike strings–will not be moved around in memory. See Example: Call an iSeries stored procedure by using Visual Basic for more information.

Pay careful attention to the data types that are involved. There may be subtle differences with those that you use with, for instance, a select statement. Also, ensure that you have an adequately sized buffer for output and input/output parameters. The way that you code the stored procedure on the iSeries server can affect performance significantly. Whenever possible, avoid closing the program with exit() in C language and with SETON LR in RPG language. Preferably, use RETRN or return, but you may need to re-initialize variables on each call, and by-pass file opens.