Calling RPG Program From JAVA: Let Us Interact with the Legacy System
Just Think…,
Why choose between old and new when you can have the best of both worlds?
Let Us…,
Discover the magic of calling RPG programs from Java for enhanced functionality.”
Introduction
Integrating legacy RPG (Report Program Generator) programs with modern Java applications is a common scenario in enterprises aiming to leverage existing systems while embracing new ones. IBM iSeries (formerly AS/400) systems often contain crucial business logic that companies cannot afford to rewrite. In this blog, you will learn how to call RPG programs from a Java application seamlessly, ensuring a seamless integration of old and new technologies.
There are various use cases/requirements of the Calling RPG/CL Program from Java
- The UI (User Interface) needs to be modernized without migrating the RPG, business logic to Java. The RPG program can be called in this case, as its business logic will be written in RPG.
- Whenever we do not want Java to interact with AS400 DB2, we can call the RPG program to interact with DB2. In this way, Java can no longer access DB2 directly.
Calling AS/400 RPG/CL Program
Our first need is the details of the RPG program we will be calling from our Java client, including its name, the library where its object resides, the input parameter names, and the output.
We will use PCML to call the RPG/CL program from Java. First, let us see what PCML does.
PCML:
The most flexible method is the Program Call Markup Language (PCML). This is an API that IBM provided for calling RPG/CL programs. In PCML we can specify the parameters that the RPG program except and output it will return.
Here are the steps to call the RPG/CL program from Java:
Step 1. Create an XML document using the Program Call Markup Language (PCML) format that IBM has provided.
In the above Screenshot we have created a PCML file that contains the following:
- Program Name: Program we want to call.
- Path: LIB is the program location, #IAOBJ.LIB is the library name and TESTEXAMPLE.PGM is the Program Name.
- Parameter: Whose usage is specified as input, which means it is an input parameter of the program and specified as the data type of the input parameter. Also, there is an Output Parameter whose usage is specified as output along with its datatypes.
Also, the name of the parameters must be the same as the name of the parameters declared in the RPG program.
If your RPG program accepts multiple input parameters, then you can specify multiple input parameters in the PCML file.
Step 2. Below is the Java source code which is used to call the RPG program. You can use the same logic to call the CL program
In the screenshot above, we created an AS400 connection by providing the AS400 host and user credentials.
Using the as400 connection object and the program name, we created a PCML object.
ProgramCallDocument pcml = new ProgramCallDocument (as400, “Program Name”);
It is necessary to set parameters in the following format before calling the RPG/CL program if the program accepts input parameters.
pcml.setValue(“ProgramName.Input_Parameter1”, Value);
Note: The parameter name should be the same as mentioned in the PCML file.
boolean rc = pcml.callProgram(“Program Name”);
We are making a call to the RPG program (same as CL) and providing input as program name.
It will return True if the call is successful.
If the call was successful and output was returned, you will see the following format:
Object fullName = pcml.getValue(“ProgramName.Output_Parameter_NAME”);
If AS400 cannot run the program, look at the message list to get an error message
AS400Message[] mgs = pcml.getMessageList(“Program Name”);
Conclusion
Java applications integrated with RPG programs represent a strategic approach for modernizing and extending IBM i systems. The combination of RPG’s business logic capabilities and Java programming scalability and versatility allows organizations to design robust, future-proof solutions.
With JDBC for database interaction, web services for interoperability, or JNI for direct integration, the synergy between RPG and Java opens new possibilities in enterprise software development. This integration remains crucial in maintaining competitiveness and meeting the dynamic challenges of the digital age as businesses evolve.
How can we help you?
We have hundreds of highly-qualified, experienced experts working in 70+ technologies.