Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    java
  » Program Call to AS400 using JTOpen
      by sde
 Page 1 of 1 
   

(Login to remove green text ads)
I spent a couple days trying to figure out how to call an AS400 program remotely using JTOpen.

IBM has examples of the Program Call on the website, however the difficulty I had was retrieving the output data of my parameter list.

After scowering the internet for other examples, I found that you need to declare the size of your output parameter as the second argument when you declare your parameter.

Below is an example of Java calling a program. The program takes 7 text parameters and returns 7 text parameters.

Code:
// import the AS400 access classes import com.ibm.as400.access.*; public class CallAS400Program{ CallAS400Program(){ } public static void main(String[] args){ try{ // declare a new instance of your as400 AS400 sys = new AS400("myAS400Name","myAS400Profile","myAS400Password"); String addr1,addr2,city,state,zip,zip4,error; addr1 = "12345 A Street"; addr2 = ""; city = "Los Angeles"; state = "CA"; zip = ""; zip4 = ""; error = ""; // Create AS400 Text objects for the different lengths // of parameters you are sending in. AS400Text txt30 = new AS400Text(30); AS400Text txt20 = new AS400Text(20); AS400Text txt2 = new AS400Text(2); AS400Text txt5 = new AS400Text(5); AS400Text txt4 = new AS400Text(4); AS400Text txt3 = new AS400Text(3); // declare and instantiate your parameter list. ProgramParameter[] parmList = new ProgramParameter[7]; // 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( txt30.toBytes(addr1),30); parmList[1] = new ProgramParameter( txt30.toBytes(addr2),30); parmList[2] = new ProgramParameter( txt20.toBytes(city),20); parmList[3] = new ProgramParameter( txt2.toBytes(state),2); parmList[4] = new ProgramParameter( txt5.toBytes(zip),5); parmList[5] = new ProgramParameter( txt4.toBytes(zip4),4); parmList[6] = new ProgramParameter(txt3.toBytes(error),3); // declare and instantiate the program. // if you don't know the exact program string, you can use: QSYSObjectPathName.toPath("MYLIBRARY","MYPROGRAM","PGM") ProgramCall pgm = new ProgramCall(sys,"/QSYS.LIB/MYLIBRARY.LIB/MYPROGRAM.PGM",parmList); if (pgm.run() != true) { AS400Message[] messageList = pgm.getMessageList(); }else{ System.out.println("Output Data 0: " + (String)txt30.toObject( parmList[0].getOutputData() ) ); System.out.println("Output Data 1: " + (String)txt30.toObject( parmList[1].getOutputData() ) ); System.out.println("Output Data 2: " + (String)txt20.toObject( parmList[2].getOutputData() ) ); System.out.println("Output Data 3: " + (String)txt2.toObject( parmList[3].getOutputData() ) ); System.out.println("Output Data 4: " + (String)txt5.toObject( parmList[4].getOutputData() ) ); System.out.println("Output Data 5: " + (String)txt4.toObject( parmList[5].getOutputData() ) ); System.out.println("Output Data 6: " + (String)txt3.toObject( parmList[6].getOutputData() ) ); sys.disconnectService(AS400.COMMAND); } }catch(Exception e) { System.out.println(e.toString()); } } }
There are examples of other data formats on the IBM website.

Below are some reference links:
http://publib.boulder.ibm.com/iserie...zahh/page1.htm
http://www-124.ibm.com/developerworks/oss/jt400/




 
 Page 1 of 1 
   

Rate This Article
1 2 3 4 5 6 7 8 9 10





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle