import com.ibm.as400.data.ProgramCallDocument; import com.ibm.as400.data.PcmlException; import com.ibm.as400.access.AS400; import com.ibm.as400.access.AS400Message; import java.math.BigDecimal; // Example class to call an RPG program to add two numbers and return the sum public class add2numbers { public add2numbers() { } public static void main(String argv[]) { // Create and instantiate an AS/400 Object // If you do not enter a user id or password, you will be prompted for each // AS400 sys = new AS400("url of iSeries", "user id", "password"); System.out.println("Connecting to iSeries..."); AS400 sys = new AS400(); // Create Data Objects ProgramCallDocument pcml; // com.ibm.as400.data.ProgramCallDocument BigDecimal sum = new BigDecimal("0"); // RPG program variable String comment; // RPG program variable boolean rc = false; // Return code for program call String msgId, msgText; // Messages returned from AS/400 try { // Instantiate the Objects (assign the variables) pcml = new ProgramCallDocument(sys, "ExamplePcml"); pcml.setValue("program.parameter1", new Integer("5")); pcml.setValue("program.parameter2", new BigDecimal("5.25")); // Debug statement...Use to view outbound and inbound parms if you need it //com.ibm.as400.data.PcmlMessageLog.setTraceEnabled(true); // Call the Program System.out.println("Calling the program..."); rc = pcml.callProgram("program"); // If return code is false, get messages from the iSeries if(rc == false) { // Retrieve list of AS/400 messages AS400Message[] msgs = pcml.getMessageList("program"); // Loop through all messages and write them to standard output for (int m = 0; m < msgs.length; m++) { msgId = msgs[m].getID(); msgText = msgs[m].getText(); System.out.println(" " + msgId + " - " + msgText); } System.out.println("Call to PROGRAM failed. See messages listed above"); System.exit(0); } // Return code was true, call to PROGRAM succeeded - woo-hoo! else { // Process the returned Data sum = (BigDecimal) pcml.getValue("program.sum"); comment = (String) pcml.getValue("program.comment"); System.out.print("5" + " + " + "5.25" + " = " + sum); System.out.print("\n"); System.out.print(comment); System.exit(0); } } catch (PcmlException e) { System.out.println(e.getLocalizedMessage()); e.printStackTrace(); System.out.println("Call to PROGRAM failed"); System.exit(0); } // Disconnect from AS/400 sys.disconnectAllServices(); } }