Problem solve Get help with specific problems with your technologies, process and projects.

How to call an RPG program from Java

I need to run a RPG program on an AS/400 from a Web-based Java application running on Weblogic on a Sun Solaris...

box. This would need to be a synchronous connection. How could I do it?

There are several common ways to call an RPG program from Java:

1. Use a DB2/400 Stored procedure call.

2. Create a Program Call Object in the Java Toolkit for AS/400 using PDML.

3. Use JNI ( Java Native Interface ) to call an ILE RPG program.

There are advantages and disadvantages to each. Only the stored procedure can return a result set if needed. JNI is an process call.

Usually we use stored procedure calls for calling RPG programs from Java.

You need to have the jt400.jar file in the Java classpath so you can access the JDBC driver class needed for remote SQL access to the AS/400:


This works on any platform a JSDK will run on including iSeries. It has the most flexibility in how to call your RPG program.

1. Create a stored procedure on the AS/400 to call your RPG program.
You can pass in parameters.
Receive back updated parameters from your RPG program.
If needed, you could even return a result set that your Java client could navigate a row at a time !

2. Use AS/400 Java toolkit JDBC Driver to run the remote stored procedure on the AS/400.

Open a JDBC connection.
Create an SQL CALL statement to call the stored procedure passing parms as needed.
Receive the updated parms from the call.
Close the statement and the connection.

Here is an example of a stored procedure definition to call a CL program passing in 2 variables and returning 2 variables:

  create procedure EMPGC01C
	   ( IN LIBNAME CHAR(10), 
	     IN EMPNO CHAR(6), 
	 		OUT PAY DECIMAL(9,2), 
	 		OUT FLAG CHAR(5)  

The statement above can be run in either Interactive SQL on the iSeries or (as I prefer) in a JDBC SQL statement to create the procedure definition.

Having created the procedure, you run a CALL statement to execute it. Here I use the following string in a prepared statement to run the procedure. Before executing the statement, I can set the first 2 input parameter Values, which are passed to my host CL program.

String stmt = "CALL CCBS.EMPGC01C (?, ?, ?, ?)";

The REALLY good news from IBM. If you don't know how to do the SQL above in Java you can use 2 IBM visual tools to: create the procedure and call it.

DB2/400 stored procedures can be defined in Operations Navigator.

You can create a call to a stored procedure as an SQL Call Statement in WebSphere Studio visually. You can also generate a JSP application to run the stored procedure visually using the WebSphere Studio database wizard.

This was last published in July 2001

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.