You are on page 1of 4

Stored procedure: CREATE PROCEDURE Sample_Stored_Procedure2 ( IN inParm1 CHAR(10) , IN inParm2 CHAR(10) , OUT outError CHAR(1) ) LANGUAGE RPGLE DYNAMIC

RESULT SETS 1 NOT DETERMINISTIC MODIFIES SQL DATA CALLED ON NULL INPUT EXTERNAL NAME LIB_NAME/TT6002R PARAMETER STYLE GENERAL; Pgm TT5002R - Calls stored proc h dftactgrp(*no) h actgrp(*CALLER) h option(*SrcStmt: *NoDebugIO) /copy qcopysrc,SQLCLI_H2 D env D conn D stmt s s s like(SQLHENV) like(SQLHDBC) like(SQLHSTMT)

D First_Name s 20A D Last_Name s 20A D Emp_Id s 5A D w@call s 500A d in@Parm1 s 10a d in@Parm2 s 10a d out@Parm1 s 1a d qT s 1a d err_flag s 1a /free monitor; SQLAllocEnv(env); SQLAllocConnect(env: conn); SQLSetConnectAttrI( : : : SQLConnect( : : : : : :

inz('User1') inz('Data1') inz('?') inz('''') inz(*blanks)

conn SQL_ATTR_DBC_SYS_NAMING SQL_TRUE %size(SQLINTEGER) );

conn '*LOCAL' SQL_NTS *NULL SQL_NTS *NULL SQL_NTS );

SQLAllocStmt( conn : stmt ); w@call = 'Call Sample_Stored_Procedure2(?,?,?)'; SQLPrepare(stmt :w@call : %size(w@call)); // bind input/output parameters

SQLBindParameter(stmt :1 :SQL_PARAM_INPUT :SQL_CHAR :SQL_CHAR :10 :0 :%addr(in@Parm1) :10 :10); SQLBindParameter(stmt :2 :SQL_PARAM_INPUT :SQL_CHAR :SQL_CHAR :10 :0 :%addr(in@Parm2) :10 :10); SQLBindParameter(stmt :3 :SQL_PARAM_OUTPUT :SQL_CHAR :SQL_CHAR :0 :0 :%addr(out@Parm1) :1 :1); SQLExecDirect( stmt : w@call : SQL_NTS ); if out@Parm1 <> *blanks; endif; SQLBindCol( stmt : : : : : SQLBindCol( stmt : : : : : SQLBindCol( stmt : : : : : 3 SQL_CHAR %addr(Emp_Id) %size(Emp_Id) *omit ); 2 SQL_CHAR %addr(Last_Name) %size(Last_Name) *omit ); 1 SQL_CHAR %addr(First_Name) %size(First_Name) *omit );

dow SQLFetch( stmt ) = SQL_SUCCESS; if First_Name <> *blanks or Last_Name <> *blanks or Emp_Id <> *blanks; endif; enddo; on-error; // issue some type of error message; endmon; monitor; SQLFreeStmt( stmt : SQL_DROP ); SQLDisconnect( conn ); SQLFreeConnect( conn ); SQLFreeEnv( env ); on-error; // issue some type of error message; endmon; *inlr = *on; /end-free Pgm TT6002R - Pgm called by stored proc - when run - if you look at the contents of the two input var's - they will be truncated. * -------------------------------------------------------------- * * ---- Entry Parameters... * -------------------------------------------------------------- * d in@Parm1 s 10a d in@Parm2 s 10a * ---- Out Parameters... d out@Error s 1a //--------------------------------------------------------//- Main Line Processing //--------------------------------------------------------/Free *inlr = *on; return; /End-Free //--------------------------------------------------------//- Subroutine: *inzsr //- Standard Initialization Subroutine //--------------------------------------------------------/Free begsr *inzsr; /end-free c *entry plist c parm in@Parm1 c parm in@Parm2 c parm out@Error /Free if in@Parm1 = *blanks or

in@parm2 = *blanks; out@Error = 'Y'; endif; endsr; /End-Free **TECHNICAL NOTE** IBM has this info on the bind parameter SQLBindParameter( SQLHSTMT StatementHandle, SQLUSMALLINT ParameterNumber, SQLSMALLINT InputOutputType, SQLSMALLINT ValueType, SQLSMALLINT ParameterType, SQLUINTEGER ColumnSize, SQLSMALLINT DecimalDigits, SQLPOINTER ParameterValuePtr, SQLINTEGER BufferLength, SQLINTEGER *StrLen_or_IndPtr);

/* /* /* /* /* /* /* /* /* /*

hstmt */ ipar */ fParamType */ fCType */ fSqlType */ cbColDef */ ibScale */ rgbValue */ cbValueMax */ pcbValue */

You might also like