On Java Development

All things related to Java development, from the perspective of a caveman.

Calling RPG or CL Programs with SETLIBLEXEC

without comments


This post shows how to call RPG and CL programs using SETLIBLEXEC which is a stored procedure residing on the iSeries (only in QGPL). SETLIBLEXEC accepts parameter values for the environment name of the library list to be used when it runs the name of the program to be called and the parameter values needed by that program.

The information that follows shows how SETLIBLEXEC builds the following command string that accepts 2 parameters as shown.
CALL PGM(CLM0001C2) PARM(‘localhost’ ‘ckraft’).

The code below shows how to implement the call of the program with the expected parameters.

As can be seen using SETLIBLEXEC is straight forward. Begin by instantiating the object while passing the data source to the constructor, then set the environment (the library list name) followed by adding the parameters need by the stored procedure that is indicated by the callStoredProc() method.

Internally, SETLIBLEXEC constructs the two parameters needed by the stored procedure. There is the fully formed call statement and the name of the library used during its execution.

If the program has no parameters, simply omit the lines that call the methods addParameterValue as seen on lines 3 and 4. In this event, the name/value pairs used by SETLIBLEXEC to call the program will look like this;

That’s all there is to calling an RPG or CL program on the iSeries. The majority of the reusable code that makes this so simple for the developer resides under the package setliblexec which comes with the baseproject.

Shown below is a simple class diagram for SETLIBLEXEC

As can be seen, SETLIBLEXEC extends Spring’s StoredProcedure class which operates upon the data source object seen being passed on SETLIBLEXEC’s constructor. This means the project must be configured to use Spring and the proper data source must be configured. If using baseproject, all of this has been taken care of and no additional changes to the project is required.

Written by admin

April 3rd, 2014 at 1:42 pm

Leave a Reply

You must be logged in to post a comment.