Calling an AS400/iSeries RPG in ColdFusion

After googling the hell out of this over the last few days I decided that my effort should actually go back in to the community to hopefully make someone else's life easier than mine was.

I am assuming at this point that you have a AS400 datasource setup using the JDBC JT400 driver. If you don't know how, and there is enough demand I'll post something on this, otherwise this guide simply demonstrates how to call an RPG program on an AS400 and read the OUT param that comes back.

I've put all of my comments in the code rather than making this post longer than it needs to be. Any questions then please use the comments as usual

All of my knowledge about the packages I have used come from publib.boulder.ibm.com/iseries/ .... com/ibm/as400/access // AS400/iSeries attributes uname = "USERNAME"; pword = "PASSWORD"; as400Ip = "10.10.10.10"; if( NOT isDefined("application.as400") OR isDefined( "url.reload" ) ){ // get our JDBC driver 'iSeries' iSeries = createObject("java", "com.ibm.as400.access.AS400"); // initilise the driver with our credentials iseries.init(as400Ip, Trim(UCase(uname)), Left(Trim(pword), 10)); // Validate the passed in details v = (iSeries.ValidateSignon()); // when valid put JDBC Connection drivers in Application scope application.as400 = { iSeries = iSeries, Command = createObject("java", "com.ibm.as400.access.CommandCall"), ProgramCall = createObject('java', 'com.ibm.as400.access.ProgramCall'), ProgramParameter = createObject('java', 'com.ibm.as400.access.ProgramParameter'), AS400Text = createObject('java', 'com.ibm.as400.access.AS400Text') }; } // 1) First parameter // Each paramater must be type of AS400Text application.as400.AS400Text.init( 11 ); // Set the length // init the fist ProgramParameter that is going to be passed in p1 = application.as400.ProgramParameter.init("1"); // Add the value in an AS/400 format in the specified byte array p1.setInputData( application.as400.AS400Text.toBytes("") ); // 2) Second parameter application.as400.AS400Text.init( 11 ); // Set the length // init the fist ProgramParameter that is going to be passed in p2 = application.as400.ProgramParameter.init("1"); // Add the value in an AS/400 format in the specified byte array p2.setInputData( application.as400.AS400Text.toBytes("") ); // Put the params into an array paramAry = [p1,p2]; // The command/RPG you are going to call CommandtoRun = "/QSYS.LIB/MYLIB1.LIB/VPCQWEQW.PGM"; // init using the iSeries connection we created, CommandToRun, and the params (in an array) PgmCall = application.as400.ProgramCall.init( application.as400.iSeries, CommandtoRun, paramAry ); // Now run it (returns boolean) PgmRun = ( application.as400.ProgramCall.Run()); // any errors or messages can be found here msgList = application.as400.ProgramCall.getMessageList()

Did not run It ran. Im now going to get the second OUT param
#application.as400.AS400Text.toObject( p2.getOutputData() )#

comments powered by Disqus