RPGIV @ Work

A unique site for RPG and System i Lovers


Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Call RPG program form Java Print E-mail
User Rating: / 1
Written by Chamara Withanachchi   

You need to download JTopen for this. You can get it from http://jt400.sourceforge.net/

package Controller;

import com.ibm.as400.access.*;

public class CallAS400Program {
    public static void main(String[] args){
		AS400 sys=new AS400("");		
		String inputMessage="R 0 0 310 14903 0 0 0 1000 test";
		String returnValue="";
		// Create AS400 Text objects for the different lengths
		// of parameters you are sending in.
		AS400Text txt80 = new AS400Text(80);
		AS400Text txt50 = new AS400Text(50);
		// declare and instantiate  your parameter list.
		ProgramParameter[] parmList = new ProgramParameter[2];
		// assign values to your parameters using the AS400Text class to convert to bytes
		// the second parameter is an integer which sets the length of your parameter output
		parmList[0] = new ProgramParameter( txt80.toBytes(inputMessage),80);
		parmList[1] = new ProgramParameter( txt50.toBytes(returnValue),50);
		ProgramCall pgm = new ProgramCall(sys,"/QSYS.LIB/SDBUTILS.LIB/SMS001R.PGM",parmList);
		if (pgm.run()!=true) {
		    system.out.println("Output Data 0: " + (String)txt80.toObject( parmList[0].getOutputData() ) );
		    System.out.println("Output Data 1: " + (String)txt50.toObject( parmList[1].getOutputData() ) );
	    	AS400Message[] messageList = pgm.getMessageList();
	        for (int i=0; i < messageList.length; i++)
	            System.out.print  ( messageList[i].getID() );
	            System.out.print  ( ": " );
	            System.out.println( messageList[i].getText() );
		}catch(Exception e) {
<Previous   Next>