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
    forums
Go Back   Code Forums > Code Newbie > Submit Tutorials > Java
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 05-12-2004, 07:08 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
Program Call to AS400 using JTOpen

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/
__________________
testing 1 2 3
sde is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
Help on starting new program B00tleg Standard C, C++ 21 10-17-2004 12:58 PM
Need help on program B00tleg Standard C, C++ 1 10-12-2004 12:02 AM
JDBC and AS400/iSeries Connection with JTOpen sde Java 0 05-17-2004 09:42 AM
Program is skipping cin.getline call rarmknecht Standard C, C++ 3 05-15-2004 08:11 AM


All times are GMT -8. The time now is 02:16 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





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