Combining PHP and RPG for Digital Transformation on IBM i

Alan Seiden

For many organizations, business logic coded in RPG or COBOL is their “secret sauce,” providing them with a profitable long-term competitive edge. It therefore makes good business sense to leverage this investment when embarking on digital transformation initiatives or even when enhancing existing applications. In this article, we'll share ways to combine PHP and RPG to achieve lasting business results while raising the stature of IT in the eyes of management.

Two powerful ways to combine PHP and RPG

RPG was designed to execute business logic flawlessly. The PHP language was built for developing web applications and APIs. How can RPG and PHP complement one another? In working with companies utilizing IBM i systems (and AS/400 and iSeries before that) for many years, we’ve used two highly effective and easy techniques to combine these two languages: PHP applications calling RPG business logic, and the reverse, RPG applications enriched by calling PHP scripts to perform tasks that are easier in PHP.  

PHP calling RPG

For companies looking to utilize existing RPG-based business logic to update their look or expand their self-service possibilities through web-based applications or web services, PHP can call RPG.  

I first explored the power of PHP calling RPG in 2008 when I helped Allied Beverage Group, a premier wine and spirits distributor now located in Elizabeth, New Jersey, develop their flagship business-to-business e-commerce system. Called eBiz, this web-based application provides self-service opportunities to customers and sales representatives, boosting sales and reducing the number of calls coming to the customer service department. The IT team took existing “green screen” RPG applications and created self-contained modules containing product ordering logic that could be called from PHP. This ensured that the logic remained consistent between the classic 5250 application and the new web-based one. We were honored for this work by winning the COMMON/IBM Innovation award, and, best of all, eBiz is still going strong today, having gained wide adoption and being enhanced continuously to meet changing business and market needs. 

We chose the PHP Toolkit to call the RPG programs as it is a robust way to call RPG programs and other IBM i resources efficiently and flexibly, as well as being free and open source. I helped develop the PHP Toolkit and still maintain it today with others. We ship the toolkit with our Seiden Group CommunityPlus+ PHP distribution for IBM i and the toolkit source code is available at GithubMore examples for how to use the toolkit are available on our site. 

When speaking with King Harrison of K3S, he described his company’s RPG business logic as their “treasure.” Their carefully architected RPG routines provide a solid foundation on which they can build a wide variety of highly graphical front ends that can keep up with changing technology. When he developed web pages to show inventory information, he used the PHP Toolkit to call these RPG “APIs,” as King refers to them. The speed is superb and the charts allow business experts to make superior decisions. For details, read “RPG APIs: A Modernization Treasure.” 

RPG calling PHP

Creative developers looking for the most straightforward way to do a job can enhance RPG programs by calling scripts written in PHP, Python, and other open-source languages of the PASE environment. These “scripting” languages provide features that, while possible to implement in RPG, are simpler or more flexible in other languages such as PHP.  

For example, they can: 

  • Send emails or text messages 
  • Create images or PDFs 
  • Create or read Excel spreadsheets
  • Download video using web services 
  • Web service and API functions to communicate with external services 
  • Protocols include REST, SOAP, and GraphQL 

Over the last few years, we’ve worked with many companies to help them connect to APIs and web services, as well as creating their own.

Some of the most common types include: 

  • Shipping services 
  • Payment APIs to provide self-service payment functionality 
  • Customer Relationship Management (CRM) systems (ex: Salesforce) 

One interesting recent project was to enhance a custom RPG-based CRM with functionality that would track marketing email opens and link clicks. We developed PHP scripts to do all that and then worked with our client to make sure the PHP scripts could be called easily from their RPG programs. For calling the PHP scripts, we recommended Scott Klement’s open source HTTPAPI tool.   

Additional tools that allow calling PHP and Python scripts via web URLs include: 

  • IBM’s HTTPGETCLOB and related SYSTOOLS Db2 functions 
  • liburl (ILE C)  

PHP can also be called directly from RPG without using a web URL though it will have a bit of a slower startup than with the above HTTP techniques.

Examples include:  

  • QSH, which you can call from a CL program or via QCmdExc in RPG 
  • Qshoni, a versatile open source tool by Richard Schoen which can call PASE programs such as PHP and Python, making “stdout” output and success/failure flags available to the calling RPG or CL program. We recently used Qshoni to call a Python script that downloaded a video using a SOAP API and returned a success flag. 

Getting Started: RPG and PHP Together

The best way to start is with a small, but useful project idea. When you combine RPG and tools such as PHP, Python, and Node.js, you can say “yes” to many projects that would otherwise be difficult. If you need to install PHP, we recommend our own CommunityPlus+ PHP, but Zend Server PHP also works. With a small project, you can learn a new language gradually and you are welcome to contact us for suggestions or to discuss a boost to get started.  

For additional tips be sure to catch Alan’s presentation as part of the RPG & DB2 Summit Lunch and Learn Series on March 17, 2021 at 1pm EST.  

Alan Seiden is the principal of Seiden Group, which helps companies bridge the gap between traditional IBM i technology, such as RPG, with open source tools and techniques, such as PHP, Python, Node.js, APIs, and web services. 


Subscribe by Email

No Comments Yet

Let us know what you think