SRVPGM Testing with JUnit

The ServiceProgramCall class in AS400 Java toolbox makes it easy to execute service program (SRVPGM) subprocedures from Java but there are some limitations that the ServiceProgramCall API has that limit your choices in the development of the subprocedure. The documentation states the following requirements for the design of the service program subprocedure:
  • The service program must be on an AS/400 running OS/400 V4R4 or later.
  • Up to seven parameters can be passed to the service program.
  • The return value must be void or numeric. This class does not support calling service programs that return a pointer.


  • As shown in the diagram, when a user has entered an address on a 5250 UI, the getLatLng subprocedure places the address and a GUID on the request FIFO data queue and immediately performs a receive on the keyed data queue for 5 seconds. The Java app reads the request from the FIFO queue and sends the address to Google which returns the latitude and longitude and county name. The county name is converted into the county code and the three values are put on the keyed data queue along with the RPG program's GUID key. The subprocedure waits for a response on the keyed data queue and returns the values to the caller.



    There is a lot going on but with the modularity of service programs and Java classes, the code stays fairly simple. This application does the following as shown on in the diagram:
  • RPG puts request on first DTAQ
  • RPG waits on response DTAQ
  • Java reads request DTAQ
  • Java sends address to Google
  • Java parses JSON for lat/lng
  • Java does county code lookup
  • Java puts lat/lng/county code on response DTAQ
  • RPG gets response off DTAQ it waited on


  • The purpose of the JUnit code is to replace the call of the subprocedure made from the RPG program with a call from the Java JUnit test. This test is an integration test of all the components working together and the main benefit it provide is performance verification.





    Blog Archive