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) ) LANGUAGE CL FENCED EXTERNAL NAME 'CCBS/EMPGC01C' PARAMETER STYLE GENERAL
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.
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.
Dig deeper on Web Development
Related Q&A from Jim Mason
Java to Excel with the AS400 may be attractive, but if you have complex VBA macros in Excel, the JDBCODBC bridge will not work well for you. A better...continue reading
There are a couple of options for accessing AS/400 data, from the old way using Client Access ODBC drivers, to Java, to a new application from Groovy.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.