Category Archives: RPG

How to change the library list before calling an external RPG program in a DB2 SQL stored procedure on IBMi

Below is how you can create a SQL stored procedure that calls the CL command ADDLIBLE to change the library list before calling an external RPG program that may require that Library in the Library List to run properlyWe also handle the error scenario where you might add a library that already exists (which would crash your SQL stored proc).  Let me know if this is helpful by commenting below or tweeting a reply to @php_dave

Calling PHP from RPG via PASE

Recently I wanted the RPG developer to call my PHP program for a process we are creating. By putting the business logic in PHP it allows us to use it internally in a Green Screen Application and on our website. We needed the ability to hash a password, send an email, and update a database record. Now this could all be done strictly using RPG and ILE, but PHP has functions built into the language to accomplish these goals such as password_hash() and mail().

I looked into using “PHP101: RPG Call PHP 101” on the YIP website, but the RPG developer found the Scott Klement article which is much simpler and easier to use and understand here:

http://iprodeveloper.com/rpg-programming/run-qshellpase-commands-rpg-special-files

You’ll have to register for the article but its worth it since his article is written well and has a zip file of the source code

By following scott klement’s example you have the RPG program run a command through PASE that calls the PHP to run your script.

md = 'PATH=$PATH:/usr/local/Zend/Core/bin && +
iconv -f 37 -t 819 | +
php /www/zendcore/htdocs/MyPHPScript.php';

In his example he’s using Zend Core (the older version of PHP on i), so if your on Zend Server you’ll use these paths:

/usr/local/zendsvr/bin/php  /www/zendsvr/htdocs/MyPHPScript.php

...and if you're on Zend Server 6 or above it will be 

/usr/local/zendsvr6/bin/php and /www/zendsvr6/htdocs/MyPHPScript.php

Now to send parameters into the script you just add them to the command line command:

/usr/local/zendsvr/bin/php  /www/zendsvr/htdocs/MyPHPScript.php parameter1 parameter2 parameter3

You’ll use the $argv variable to access the parameters pass into the PHP script and use echo to send data back to the RPG program.

You may run into permissions issues with calling /usr/local/zendsvr/bin/php because Zend Server installed using QSECOFR, so you might have to add permissions to that path to the user calling PHP from RPG

Now your PHP Dev and RPG dev can collaborate on many projects that need to be done in house apps and the website! You can also try running the Command line PHP by doing CALL QP2TERM