Search code examples
phpsqlzend-frameworkcallibm-midrange

call RPGLE program from SQL within PHP / Zend Framework


We have an AS400 RPGLE program created within the library LMTLIB, which is called ARTEST.

It has a single numeric inout parameter, which just returns 2

$myVar = "1";

$db = Zend_Registry::get('config')->resources->multidb->as400;

$abstractAdapter = new Zend_Db_Adapter_Db2($db);

//Gives the message "Invalid bind-variable position 'myVar'"
$sql = 'CALL QSYS.QCMDEXC(\'CALL LMTLIB.ARTEST PARM(?)\', 0000000026.00000)';

//Gives the message "Token PARM was not valid. Valid tokens: ( INTO USING. SQLCODE=-104"    
$sql = 'CALL LMTLIB.ARTEST PARM(?)';

//Gives the message "ARTEST in LMTLIB type *N not found. SQLCODE=-204"
$sql = 'CALL LMTLIB.ARTEST (?)';

$stmt = new Zend_Db_Statement_Db2($abstractAdapter, $sql);

$stmt->bindParam('myVar', $myVar, 4, 1);

$stmt->execute();

Now, i can kind-of understand why the third SQL statement would fail with the "not found" message... because it is not a table / file, but rather an RPGLE program.

The thing thats irritating, is that if i remove the (?), and simply put in (1)... the SQL call appears to be successful, and the RPGLE program shows it had been called. However, I'm then not able to see what the response from the program was.

Thanks in advance for any help!


Solution

  • Generally, the database manager uses the CALL statement to invoke a stored procedure. When it does that, it looks for a stored proc whose parameter signature matches the signature of the CALL.

    If there's no stored proc with that name and signature, the database manager tries to call a program. Again, there's a parameter matching process that happens.

    http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/db2/rbafzmstcallsta.htm

    I suggest creating a stored procedure so you can get the parameters matched properly.