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 iSeries service program to add or subtract two numbers and return the answer public class prc2numbers { public prc2numbers() { } 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 answer; // RPG program variable boolean rc = false; // Return code for program call String msgId, msgText; // Strings for as400 messags/400 try { // Instantiate the Objects (assign the variables) pcml = new ProgramCallDocument(sys, "MathPcml"); pcml.setValue("Add.parameter1", new Integer("5")); pcml.setValue("Add.parameter2", new BigDecimal("6.30")); // 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("Add"); // If return code is false, get messages from the iSeries if(rc == false) { // Retrieve list of AS/400 messages AS400Message[] msgs = pcml.getMessageList("Add"); // 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 Add failed. See messages listed above"); System.exit(0); } // Return code was true, call to Add succeeded - woo-hoo! else { // Process the returned Data answer = (BigDecimal) pcml.getValue("Add.answer"); System.out.print("5" + " + " + "6.30" + " = " + answer); System.exit(0); } } catch (PcmlException e) { System.out.println(e.getLocalizedMessage()); e.printStackTrace(); System.out.println("Call to Add failed"); System.exit(0); } // Disconnect from AS/400 sys.disconnectAllServices(); } }