Home > Ask the AS/400 Experts > iSeries Web Development Questions & Answers > How to call an RPG program from Java
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

How to call an RPG program from Java

Jim Mason EXPERT RESPONSE FROM: Jim Mason

Pose a Question
Other iSeries 400 Categories
Meet all iSeries 400 Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 09 July 2001
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?


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
iSeries Web Development
JDBCODBC functionality -- Java to Excel for complex workbooks
Accessing AS/400 data using Excel ODBC drivers
IBM WebSphere Studio Application Developer error
Database pooling on iSeries
Connecting WebSphere to AS/400 for image retrieval
Retrieving the value selected by a user
Condense ILE service program procedures
WebSphere error during login process
Connecting WebSphere to a DB2 database
WebFacing error: User ID or password invalid

Web Development
Implementing a browser interface in COBOL: Creating your graphic Web page
Implementing a browser interface in COBOL: Getting started
IBM i shop boosts online sales with RPG-based Web platform
Migrating from RPG to EGL on IBM i
Groovy programming on IBM i
Running PHP open source applications: NOBODY needs authority
Zend Web software teams up with IBM System i
The best technologies and tools for System i programmers in 2009
Seven IBM i project lessons learned in 2008
AS/400 lessons from the past, present, and future: A holiday tale

iSeries Java programming
Groovy programming on IBM i
EGL Rich UI on IBM i: Do you Dojo?
Programming for the Web on the IBM i, what is possible
Database performance comparisons on IBM i
Database drivers on the i: MySQL vs. IBM Toolbox
How to: Output SQL script to a text file from an AS/400
Application modernization for the iSeries: Why bother?
JDBCODBC functionality -- Java to Excel for complex workbooks
Necessity leads to iSeries Watchdog development
Accessing AS/400 data using Excel ODBC drivers
iSeries Java programming Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
WebSphere Development Studio Client (WDSC)  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


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:

com.ibm.as400.access.AS400JDBCDriver

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.

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.




Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



iSeries Networking - Printing, Remote Access, TCP/IP
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts