Guild Companies, Inc.  
 
Midrange Programmer - How-To Advice & Free Code
OS/400 Edition
Volume 1, Number 9 - May 9, 2002

The iSeries Toolbox for Java: GUI-izing Program Calls

by Kevin Vandever

[The code for this article is available for download.]

In "Learning Java by Example," Shannon O'Donnell provided some simple Java applications that allowed you to execute PC commands and access spool files from the iSeries. He did this to arm you with new tools, but he also afforded you working code from which you could learn Java. Using the same premise, in this article I will provide you with a Java application to call an iSeries program and display the results on a GUI form. Download it and use it as is, or mold it to fit your needs.

Another Way to Call a Program

If you've read my articles on the iSeries Toolbox for Java, you know that I have written about a couple of different ways to call iSeries programs from Java. In fact, I have written about my two preferred methods, using the toolbox and another method that doesn't use the toolbox at all. I am about to show you another way to call iSeries programs from Java, but this isn't necessarily a method that you will use in a production environment, as you would with my previous examples. This method will most likely be used as a tool by you or maybe others within your shop. But, hey, don't let me limit you; use it as you see fit.

System Status with a Click of a Button

This application will call the system API, QWCRSSTS, which returns system status information, and display some of that information in an applet (GUI screen). The Java source for this application can be found in the ProgramCallButtonExample.java file. Instructions for downloading the iSeries Toolkit for Java and properly setting up your environment can be found in "Calling a Program Using the iSeries Toolbox for Java."

This code is provided by IBM as an example of how to display the results of a program call in a Java applet. I have used this code as is, but have also modified it to display results from homegrown iSeries programs. Follow the same structure of this program, and you'll be set.

Description of the Code

You will notice two main methods, one static and the other non-static. The static method creates an instance of the ProgramCallButtonExample class and calls the non-static Main method, which accepts the input parameters and performs the rest of the logic.

This demo application accepts a system name or IP address for the AS/400 you want to connect to. If you forget this parameter, it will tell you. The code within the Try block then builds the GUI applet, creates an AS/400 connection object based on the input parameter you supply, and then creates a program path object based on the program you are going to call and on, of course, the path where it resides.

The Java program then sets up the parameters required for the specific API. You will notice some Java-to- AS/400 conversion classes being used to set up the parameters. Java integers, BigDecimals, and Strings have to be converted to their iSeries counterparts before they can be used. I won't cover these in too much detail because they really aren't used anymore, except in this technique, because there have been new ways invented to convert Java data to iSeries data that are much easier to use. (See my previous articles on calling programs from Java for more details on these techniques.)

After the parameters are set, the Java application handles what happens when the user closes the applet window (in this case it exits nicely) and what happens when the user clicks the Refresh button (in this case, it makes a call to the AS/400 API).

Give It a Try

Java applets are not used all that much anymore, as they have made way for more server-side solutions such as servlets and JavaServer Pages. However, as a tool to use internally, or as a way to learn Java from a working example, this technique works quite well. Enjoy!

Sponsored By
PROFOUND LOGIC SOFTWARE

Looking to increase programmer productivity? Visit http://www.RPGAlive.com/now.

RPG-Alive adds an array of graphical features to IBM's native Source Edit Utility, and is one of only a few products to receive a 10 out of 10 rating in an independent evaluation by 400Times.

RPG-Alive allows RPG programmers to quickly gain an understanding of existing RPG programs, and facilitates a quicker way for programmers to change or write new source code.

Here is what RPG-Alive users say:

Name: Glenn Elliott
Company: GDX Automotive
"Your software is awesome. If someone were to sit down and figure out a great software program to accent code generation on a 400, this would be it. Everything from source code indentation to promptable key words. What a time saver! Thank you for saving me some time!"

Name: Stuart Rowe
Company: Help/Systems, Inc.
"Installation went flawlessly, it started working without asking any questions, no lengthy setup, keep it up you're doing a great job. I have my manager poised over the checkbook with pen in hand as I type this."

Name: Krish Thirumalai
Company: Manhattan Associates
"Excellent product. We have a lot of people in our organization that use and love this product. The built-in help for opcodes and BIF's is really cool! Our programmers no longer need to search for their RPG manuals to look up these opcodes."

Name: Jim Kucharik
Company: Victaulic Company of America
"Your product has won the hearts of our programmers, not an easy thing to do!"

To try RPG-Alive on your system, visit http://www.RPGAlive.com/now or call (937) 439-7925.

THIS ISSUE
SPONSORED BY:
SoftLanding Systems
LANSA
ACOM Solutions
ASNA
Profound Logic Software
WorksRight Software
BACK ISSUES
TABLE OF CONTENTS
Creating a VARPG Appointment Calendar
Dynamic Selection with Embedded SQL
Validating XML with a Document Type Definition
The Ins and Outs of Qshell
The iSeries Toolbox for Java: GUI-izing Program Calls
Exploring iSeries Navigator Application Administration
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 5/8/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.