Java method call from RPG (method call in own class)

A memorandum of calling Java methods from ILE RPG. It is also mentioned in the "IBM Rational Development Studio for i ILE RPG Programmer's Guide" (IBM i version 7.2), but it wasn't written in great detail, so I actually tried it.

The environment of IBM i that was executed is version: V5R4, Java: 1.4.2. (It also worked on V7R2 and Java 1.8.0.)

To make it a little more practical, I created a program that returns the status of running jobs. Pass a string (job name) as an argument and return the string (status). (If the same job name exists more than once, the status of the first acquired job is returned.)

IBM i environment check

It's okay if the Java version is returned by the following command.

java -version

Folder structure

The folder structure of IFS on IBM i is as follows.


Java program preparation

package mypackage;


public class As400Funcs {

	public static void main(String[] args) {

	public static String GetJobSts(String searchJob) {
		AS400 as400  = new AS400("192.168.XXX.XXX" ,"MYUSER" ,"MYPASS");

		String resultStatus		= "NONE";

		//get JobList
		RJobList jobList = new RJobList(as400);
		try {
			jobList.setSelectionValue(RJobList.PRIMARY_JOB_STATUSES, new String[] { RJob.JOB_STATUS_ACTIVE });
			//Get First Job
			long numberOfJobs = jobList.getListLength();
			for (long i = 0; i<numberOfJobs; ++i){
				RJob ajob = (RJob)jobList.resourceAt(i);
				RJob rjob = new RJob(as400,searchJob,(String)ajob.getAttributeValue(RJob.USER_NAME),(String)ajob.getAttributeValue(RJob.JOB_NUMBER));
				resultStatus  	= (String)rjob.getAttributeValue(RJob.ACTIVE_JOB_STATUS);
				System.out.println("JOB Status:"+resultStatus);
				System.out.println("JOB Name:"+searchJob);
		} catch (ResourceException e) {
		return resultStatus;

Compile and test run Java programs

Set environment variables. (Please sign off once to make sure.)

ADDENVVAR ENVVAR(CLASSPATH) VALUE('/JavaApps/bin:/JavaApps/lib/jt400.jar')

Compile and test run (QSHELL)

javac -d /JavaApps/bin /JavaApps/src/mypackage/
java mypackage/As400Funcs

In the sample, the argument job name is "DSP01", Please specify the job that is actually running. It's okay if you can get the status correctly.

RPG program preparation and compilation


      *Sample program that calls a JAVA method
     H DFTACTGRP(*NO)                                                                        
     D MAIN            PR                  EXTPGM('GETJOBSTSR')                              
     D                               10A                                                     
     D MAIN            PI                                                                    
     D searchJob                     10A                                                     
     D newString       PR              O   ExtProc(*JAVA:                                    
     D                                             'java.lang.String':                       
     D                                             *CONSTRUCTOR)                             
     D                                     Class(*JAVA:'java.lang.String')                   
     D  bytes                        10A   Const Varying                                     
     D GetJobSts       PR              O   ExtProc(*JAVA:                                    
     D                                     'mypackage.As400Funcs'                            
     D                                     :'GetJobSts')                                     
     D                                     STATIC                                            
     D                                     CLASS(*JAVA:'java.lang.String')      //Return type
     D  string                         O   CLASS(*JAVA:'java.lang.String') Const//Parameters
     D getBytes        PR            10A   ExtProc(*JAVA:                         
     D                                             'java.lang.String':            
     D                                             'getBytes')                    
     D                                     Varying                                
     D string1         S               O   Class(*JAVA:'java.lang.String')        
     D StringResult    S               O   Class(*JAVA:'java.lang.String')        
     D StringDisply    S             10A   Varying                                
          String1 = newString(searchJob) ;                                        
          StringResult = GetJobSts(String1) ;                                     
          StringDisply = getBytes(StringResult) ;                                 
          dsply StringDisply;                                                     
          *inLR = *on ;                                                           
          return ;                                                                

Run RPG program


It is OK if the job status is displayed on the screen.

"Received JAVA exception when calling JAVA method" error


In the case of an error, the environment variable "CLASSPATH" is often incorrect. Especially once the RPG is executed, the JVM starts with that job, and then

ADDENVVAR ENVVAR(CLASSPATH) VALUE('/JavaApps/bin:/JavaApps/lib/jt400.jar')

** Is not reflected ** even if is executed. (It seems that you cannot restart the JVM, and you have to sign off once.)

Recommended Posts

Java method call from RPG (method call in own class)
Call Java method from JavaScript executed in Java
Call Kotlin's sealed class from Java
Call the super method in Java
Implement Java Interface in JRuby class and call it from Java
GetInstance () from a @Singleton class in Groovy from Java
Call Java from JRuby
How to get Class from Element in Java
Java programming (class method)
[Java] Get KFunction from Method / Constructor in Java [Kotlin]
Call a method with a Kotlin callback block from Java
Write a class in Kotlin and call it in Java
Call a program written in Swift from Processing (Java)
Call your own method with PreAuthorize in Spring Security
How to get the class name / method name running in Java
[Kotlin] Get Java Constructor / Method from KFunction and call it
Call Chain from Chain in Spring Integration
[Java] Object-oriented syntax --class method / argument
Automatic photo resizing method in Java
Handle your own annotations in Java
StringBuffer and StringBuilder Class in Java
Call TensorFlow Java API from Scala
[java] What I did when comparing Lists in my own class
[Java] Wrapper that executes private method of object from outside class
Study Deep Learning from scratch in Java.
[Java] Pass arguments to constructor in Mockito / Set method default call to callRealMethod
Java method
java (method)
Call Java library from C with JNI
Call GitHub API from Java Socket API part2
Understand java interface in your own way
Call the Windows Notification API in Java
Concurrency Method in Java with basic example
[Beginner] Java method / class / external library [Note 23]
Reverse Key from Value in Java Map
Using JavaScript from Java in Rhino 2021 version
What is a class in Java language (1 /?)
What is a class in Java language (2 /?)
Why does Java call a file a class?
What is the main method in Java?
Java method
Class method
Call Java methods from Nim using jnim
[Java] method
Get history from Zabbix server in Java
Creating a matrix class in Java Part 1
[Java Spring MVC] I want to use DI in my own class
Call Visual Recognition in Watson Java SDK
[Java] Instance method, instance field, class method, class field, constructor summary
Element operation method in appium TIPS (Java)
When calling println etc. from an external Java class file in Processing
[Java] method
Call a method of the parent class by explicitly specifying the name in Ruby
Increment with the third argument of iterate method of Stream class added from Java9
Cause of is not visible when calling a method of another class in java
[Java] Handling of JavaBeans in the method chain
[Java] Dynamic method call by reflection of enum (enum)
I tried hitting a Java method from ABCL
Text extraction in Java from PDF with pdfbox-2.0.8
[Java SE 11 Silver] Arrays class method summary [Java beginner]
Java starting from beginner, class declaration / object generation