Tuesday, April 24, 2012

AS400 Stored Procedure Testing

Please see the code stored on github.com.

Prerequisite for calling Java to execute an AS400 stored procedure is to have the jt400.jar in your classpath.

Five steps are required to use the code to create a Java class and, with it, call an AS400 stored procedure.

First, create a file named AS400DEV.properties and enter the following with your AS400 name, user-id and password.
system=
userid=
password=
If you like, you may alter StoredProcWriter to eliminate the use of the properties file and, on lines 328 through 332, (a.) hard-code the system name, (b.) eliminate the the user-id and password from the connection arguments and (c.) change prompt to true.

Next, create the class that we will use to create the Java class to call the AS400 stored procedure.
javac StoredProcWriter.java
The StoredProcWriter class was created by the java compiler in the previous step. Next we use that class to create the code for the stored procedure call.
java -classpath .;jt400.jar StoredProcWriter <library> <as400storedprocedure> <javaclass.java>
Now we're finished with StoredProcWriter and will compile the Java code created in the previous step.
javac -classpath .;jt400.jar <javaclass.java>
The next step is to run the class that will call the stored procedure. You may want to examine the code and change the
java -classpath .;jt400.jar <javaclass>
The first of the four steps is only required to first create the StoredProcWriter class. Once that is done, it isn't necessary to repeat it. Below are the steps I would use to call the stored procedure Jon and Susan wrote about on the last page of their article on creating and testing stored procedures.
javac StoredProcWriter.java 
java -classpath .;jt400.jar StoredProdWriter MYLIB CustomersByState CustomersByState
javac  -classpath .;jt400.jar CustomersByState.java
java -classpath .;jt400.jar CustomersByState

Caveat: this code is really old. It wasn't state of the art when I wrote it 10 years ago but it does get the job done.