In today’s enterprise landscape, many organizations still rely on IBM i (formerly AS/400) systems running business-critical RPG programs. Rewriting that legacy logic in Java isn't always practical—or even necessary. Why start from scratch when you can integrate and modernize?
In this blog, let’s explore how you can call RPG or CL programs directly from Java, keeping your existing logic intact while delivering modern application experiences.
🔄 Why Call RPG from Java?
Here are some real-world reasons why you'd want to connect Java to RPG:
· UI Modernization: You want to build a modern web or mobile UI without rewriting the core business logic in RPG. Solution? Keep RPG for business logic and call it from your Java-based frontend.
· Database Access Control: Want to prevent Java from directly accessing DB2 for i? Let RPG handle the database interactions, and Java just calls the program—keeping logic and access centralized.
💡 PCML – The Magic Behind the Scenes
The easiest and flexible way to connect Java with RPG is using PCML (Program Call Markup Language). PCML is an XML-based format where you define:
· The RPG/CL program name
· Its location (like library and path)
· All input and output parameters with types
The names and types of the parameters in PCML must match exactly with those in your RPG program.
🛠️ Steps to Call RPG/CL from Java
✅ Step 1: Create the PCML File
This XML file defines your RPG program structure:

✅ Step 2: Java Code to Call the Program
Step 2. Below is the Java source code used to call the RPG program. You can use the same logic to call the CL program

In the screenshot above, we created an IBM i connection by providing the IBM i 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);
boolean rc = pcml.callProgram("Program Name");
We are making a call to the RPG program (or 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 IBM i cannot run the program, check the message list to get an error message
AS400Message[] mgs = pcml.getMessageList("Program Name");
🔎 Note: The parameter names in setValue() and getValue() must match what you defined in the PCML file.
🧩 Final Thoughts
Integrating RPG programs with Java is a smart, future-ready approach. It allows you to:
· Preserve your trusted RPG logic
· Build modern UIs and apps with Java
· Reduce rewriting efforts
· Extend your IBM i systems without losing reliability
Instead of replacing legacy systems, this method helps enhance them with the best of both worlds—RPG’s stability and Java’s versatility.
#IBMChampion#champions-blog-feed