On Java Development

All things related to Java development, from the perspective of a caveman.

CLP to RPG to Java

without comments


This post presents two IBM iSeries programs, a CLP and its associated RPG-LE program and a Java class. Together, they serve to illustrate how to call Java methods from an RPG program. The Class-methods reside in a .JAR-file deployed on the IFS.


The CL Program

The CL program presented below simply acts to establish classpath entries for the dependencies. They are LOG4J for logging, which is not illustrated in this post and iText.jar which provides the means for embedding an image file into a .PDF document.


The RPGLE Program


The Java Class

The Java class presented below depends upon iText to place the image-file into a .PDF document.
The iText project can be found here The book “iText in Action” can be found here.

The main() method is for testing purposes. It instantiates and calls the methods to test the Java code. Once debugged and proofed in this way, development continues with the RPG layer, but the main method stays.

The Voodoo occurs here:

It’s basically saying this: The name of this function is createPDF. It defines 3 parms. The *JAVA instance of the class, the fully qualified name of the class to be referenced and the method to be called. The *JAVA is a placeholder for the instance of the class. Since we can’t do this: IFSImage2PDF.createPDF() in RPG, we have to pass the instance of the class for every method call. The *JAVA part is the instance. ( i.e. createPDFDoc(IFSImage2PDF : imgSrc : pdfTgt); )

The *JAVA reference is created from this:

After this, it’s 1-2-3,

Create the instance:

To call the method to first convert the parms to Java types:

Then call the method with the parms.

Finally, the Java class.

Written by admin

September 29th, 2014 at 7:45 am

Posted in RPG and Java

Tagged with

Leave a Reply

You must be logged in to post a comment.