PowerWire.eu

Independent IBM i, AIX and Linux news and tech tips for Europe and beyond

  • Home
  • News
  • Technical Articles
    • IBM i
    • AIX
    • Linux
    • VIOS
  • Subscribe
  • About Us
  • Contact Us
  • Advertise with PowerWire.eu

Using PHP and RPG to Communicate Together

January 5, 2016 by Andy Youens

abstract binary background

In this article, I wish to take you through how we can communicate between PHP and RPG on our IBM i.
I recently had a request from one of our clients asking if I had any examples of calling an RPG program from a PHP script. This gave me the idea, via the PowerWire platform, to explain how we can get these two fantastic languages working together.
As you may know, PHP is an excellent programming language that coupled with our traditional programs, can provide functionality, that by default, can be difficult and at times frustrating to provide. For example, try sending an HTML email from RPG, or get RPG to use a webservice, umm….
PHP is an ideal programming language to complement our conventional programming languages, not replace them.
The majority of the examples in this article, will use the excellent XML Services, also known as the IBM i Toolkit developed by IBM and Zend. The methods and functions included in the toolkit, really ease our development.

Example 1
In the first example, we will show how we can call a RPG program, (can be any IBM i program object in fact) without passing any parameters.

youens eg1

To explain, firstly, we make a connection to our IBM i, using the XML Toolkit. This is achieved by the getInstance method of the Toolkit class.
The variable $conn is used as the Toolkit object and used to perform the methods of the toolkit.
Next we use the PgmCall method, passing the name of the program, the library it resides in, and thirdly, the parameter variable, which is null as we are not passing any variables into the program POWERWIRE/FSS1. We could have omitted the last three parameters on our call as these are optional.
If we need to know if the call was successful we can check if there is any value in the parameter $result, returned from the program call.
How easy was that! All due to the XML Toolkit, that Zend and IBM provided.

Example 2
Let us move on now and show how to pass parameters to our programs from a PHP script.
In this example, a call to our program will change the value of the User Profile parameter, so we can review it after the call. This is contained in the array $outputParams[‘USER’].
The Toolkit will help us again with this. We have to create an array of the attributes of the parameters, type, size, etc. This can be seen using the array variable $param.
As in the previous example, we use the PgmCall method to run our program call FSS3 in library POWERWIRE.

youens eg2

Please note that in the above example, to save space I have not included the initial connection to our server, refer back to the first example, if you need to know how to do this.
Now we have that working as we intended, let’s get a bit more complicated. This time we are going to pass a data structure for our RPG to receive.

youens eg3

In this example, we are passing four parameters to our RPG program. Two character strings, an integer and a data structure.
The data-structure is built, using an array, into the variable $ds, then added to the parameter list. Obviously, our RPG at the other end, must be expecting a data-structure.
All easier than you may have been expecting.
In the next article, we will be showing how simple it is to integrate PHP into our applications, by demonstrating how we can execute a PHP script and pass parameters between the two from an RPG program.

Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems.

 

Filed Under: IBM i, Technical Articles Tagged With: IBM i, PHP, RPG

Free monthly newsletter signup

News

A screen a story – Not our problem anymore

Last week I ran into an issue, which did teach me something new about the command WRKPRB. After checking a … [Read More...]

Raspberry Pi and Machine Learning

In my last article, I demonstrated how I used Machine Learning on the Raspberry Pi to determine if a … [Read More...]

Shield Advanced Solutions – new Messaging and Monitoring solutions

September 2022 – Toronto As Shield Advanced Solutions celebrates the significant milestone, 25 years of … [Read More...]

More articles from this section

Quick Links

  • Advertise
  • Subscribe

Follow Us…

  • Email
  • LinkedIn
  • Twitter

Search This Website

Copyright © 2023 · Cue Communications · All Rights Reserved

Log in