AS400 Program Calls
  • 24 Aug 2021
  • 9 Minutes to read
  • Contributors
  • Dark
    Light

AS400 Program Calls

  • Dark
    Light

Article summary

AS400 program calls

AS400 program calls are  performed via the java toolkit as service calls. All AS400 programs that has a parameter list can be called this way.

 

To define a service interface that mirror the parameter list for a program, a XML description of it must be made -a so-called PCML-file. It describes all parameters and it’s possible structures. 

 

RPG programs

RPG programs are not only stored in source members in a AS400-library, but also in the Eclipse project structure. The standard location in a project is under Docs/RPG with possible source file sub-folders.

Distribute RPG programs between AS400 and Eclipse

To distribute the RPG source member to Eclipse from the source file, you do the following.

 

Start a command window on your PC

Set the java source folder for your project as home with command cd path, like cd C:\Java\eclipse\workspace\Karlshamns_Warehouse\Docs\RPG

Start ftp for the AS400 server: ftp ip-adress and login.

Change path to actual source file, like ftp> cd /qsys.lib/mvxcmod.lib/mmsrc.file

Get the source file from the source-member to the project, like ftp> get mws410ca.mbr

 

To distribute the RPG source member from Eclipse to the source file, you do the following.

 

Start a command window on your PC

Set the java source folder for your project as home with command cd path, like cd C:\Java\eclipse\workspace\Karlshamns_Warehouse\ Docs\RPG

Start ftp for the AS400 server: ftp ip-adress and login.

Change path to actual source file, like ftp> cd /qsys.lib/mvxcmod.lib/mmsrc.file

Put the source file from the project to the source-member, like ftp> put mws410ca.mbr

 

Note that put of a source member to a source file looses member information, why that shall be added manually.

 

See the example below for a get of a source member:

 

 

C:\>cd java\eclipse\workspace\Karlshamns_Warehouse\Docs\RPG

C:\Java\eclipse\workspace\Karlshamns_Warehouse\Docs\RPG>ftp sekab002

Connected to sekab002.karlshamns.se.

220-QTCP at sekab001.karlshamns.se.

220 Connection will close if idle more than 5 minutes.

User (sekab002.karlshamns.se:(none)): user

331 Enter password.

Password:

230 user logged on.

ftp> cd /qsys.lib/mvxcmod.lib/mmsrc.file

250-NAMEFMT set to 1.

250 "/QSYS.LIB/MVXCMOD.LIB/MMSRC.FILE" is current directory.

ftp> get mws410ca.mbr

200 PORT subcommand request successful.

150 Retrieving member MWS410CA in file MMSRC in library MVXCMOD.

250 File transfer completed successfully.

ftp: 33297 bytes received in 0,85Seconds 39,08Kbytes/sec.

ftp>

 

See example below for a put of a source member:

 

C:\>cd java\eclipse\workspace\Karlshamns_Warehouse\Docs\RPG

 

C:\Java\eclipse\workspace\Karlshamns_Warehouse\Docs\RPG>ftp sekab002

Connected to sekab002.karlshamns.se.

220-QTCP at sekab001.karlshamns.se.

220 Connection will close if idle more than 5 minutes.

User (sekab002.karlshamns.se:(none)): pksoreid

331 Enter password.

Password:

230 PKSOREID logged on.

ftp> cd /qsys.lib/mvxcmod.lib/mnsrc.file

250-NAMEFMT set to 1.

250 "/QSYS.LIB/MVXCMOD.LIB/MNSRC.FILE" is current directory.

ftp> put mns211ca.mbr

200 PORT subcommand request successful.

150 Sending file to member MNS211CA in file MNSRC in library MVXCMOD.

250 File transfer completed successfully.

ftp: 82940 bytes sent in 0,45Seconds 184,31Kbytes/sec.

ftp>

 

 

Service interface/PCML-file design

You design the pcml-file by describing the parameter list in XML format. You define each parameter as one or several fields, with it’s usage, type, length and possible init. Then you define the program-call by pinpointing the path and the parameters as well it’s usage.

 

A parameter is always defined as a structure, even if it only contains only one field. Each structure is only defined by name, which shall be the same as the structure of the parameter name in the program call:

 

  <!-- Format MWS410DS -->

  <struct name="MWS410DS">

    …

  </struct>

 

 

Each structure contains one or several fields of different types. All fields shall be named exactly as the fields in the parameter structure. A character field shall specify usage (input or output), type (char), length (no of characters) and initiation value (blanks or a value). Numeric (type=zoned) fields also specify precision (number positions that are decimals) and the initiation shall be numeric.

 

The program call structure is defining the path to the program and in what order the parameters shall be interchanged. See example below:

 

<!-- Program MWS410CA and its parameter list -->

  <program name="MWS410CA" path="/QSYS.LIB/%LIBL%.LIB/MWS410CA.PGM">

    <data name="MWS410"             type="struct"   struct="MWS410DS"    usage="inputoutput"/>

  </program>

 

Note that it is very important that the pcml-file fully mirrors the parameter structure in field types, lengths and inits, otherwise you will get rather strange errors in the program call, like data decimal errors.

 

See example below:

 

<pcml version="1.0">

<!-- PCML source for calling MWS410CA API  Print delivery documents -->

  <!-- Format MWS410DS -->

  <struct name="MWS410DS">

    <data name="WWCONO"    usage="input"             type="zoned"  length="3"                 precision="0"              init="0"/>

    <data name="WWDLIX"    usage="input"             type="zoned"  length="11"              precision="0"                      init="0"/>

    <data name="WWINOU"    usage="input"             type="zoned"  length="1"                 precision="0"              init="0"/>

    <data name="WWOPT2"    usage="input"             type="char"                length="2"                                                                       init="  "/> 

             <data name="WWCHID"             usage="input" type="char"                length="10"                                                        init="         "/> 

             <data name="XSGDTA"             usage="output"             type="char"                length="256"/>

             <data name="WWDSP1"             usage="input" type="char"                length="1"                                                                       init=" "/> 

             <data name="WWDSP2"             usage="input" type="char"                length="1"                                                                       init=" "/>  

             <data name="WWDSP3"             usage="input" type="char"                length="1"                                                                       init=" "/> 

             <data name="WWDSP4"             usage="input" type="char"                length="1"                                                                       init=" "/> 

             <data name="WWDSP5"             usage="input" type="char"                length="1"                                                                       init=" "/> 

             <data name="WWDSP6"             usage="input" type="char"                length="1"                                                                       init=" "/> 

             <data name="WWDSP7"             usage="input" type="char"                length="1"                                                                       init=" "/> 

             <data name="WWDSP8"             usage="input" type="char"                length="1"                                                                       init=" "/>   

             <data name="WWDSP9"             usage="input" type="char"                length="1"                                                                       init=" "/> 

  </struct>

  <!-- Program MWS410CA and its parameter list -->

  <program name="MWS410CA" path="/QSYS.LIB/%LIBL%.LIB/MWS410CA.PGM">

    <data name="MWS410"             type="struct"   struct="MWS410DS"    usage="inputoutput"/>

  </program> 

</pcml>

 

 

 

Distribute PCML-file from Eclipse to AS400

To be able to execute the AS400 program, the PCML-file must be deployed on the AS400 in the Comflow connection kit-folder. 

 

Do the following:

 

Start a command window on your PC

Set the java source folder for your project as home with command cd path, like cd C:\Java\eclipse\workspace\Karlshamns_Warehouse\src\java

Start ftp for the AS400 server: ftp ip-adress and login.

Change path to Comflow connection kit, like ftp> cd /Comflow/connectionkit

Put the pcml file from the project into the connectionkit folder, like ftp> put mws410ca.pcml

                                                                                             

See log below as an example:

 

cd \Java\eclipse\workspace\Karlshamns_Warehouse\src\java

C:\Java\eclipse\workspace\Karlshamns_Warehouse\src\java>ftp sekab002

Connected to sekab002.karlshamns.se.

220-QTCP at sekab001.karlshamns.se.

220 Connection will close if idle more than 5 minutes.

User (sekab002.karlshamns.se:(none)): pksoreid

331 Enter password.

Password:

230 PKSOREID logged on.

ftp> cd /Comflow/connectionkit

250-NAMEFMT set to 1.

250 "/Comflow/connectionkit" is current directory.

ftp> put mws410ca.pcml

200 PORT subcommand request successful.

150 Sending file to /Comflow/connectionkit/mws410ca.pcml

250 File transfer completed successfully.

ftp: 1639 bytes sent in 0,02Seconds 81,95Kbytes/sec.

ftp>

 

Now you have deployed on the AS400 and you can execute the program from a rule. To check the pcml-file, you can do WRKLNK in an AS400 terminal window, and use option 5 on the Comflow folder and then option 5 on the connectionkit-folder and there your file should be.

 

If the PCML file is seralized (an requirement for early versions of Comflow), you first need to remove the xxx.pcml.ser file, where xxx.pcml is your pcml file, and then do a new serialization of the new pcml file. 

 

You remove the file by using the WRKLNK command in the AS400 and go to the Comflow/connectionkit folder by using option 5 for each folder. Then you remove the xxx.pcml.ser by using option 4.

 

To do a new serialization of the pcml-file, you do the following:

 

  • In the AS400 window, use command ”qsh” and   Enter
  • Do the command ”cd /Comflow/connectionkit” and hit Enter
  • Do the command ”java -cp .:./lib/jt400Native.jar com.ibm.as400.data.ProgramCallDocument -serialize xxx” and hit Enter (xxx can then be cos100ca for the cos100ca.pcml file)

 

Program call rule

To execute a program call, you just use the access the PCML definition via the ServerProgramCall packages, which you have to import into the rule. 

 

First you init the program call, then you set the parameters in the PCML file and finally you execute the program call. Se example code below.

 

 

import net.comactivity.core.connect.ServerProgramCall;

import net.comactivity.core.connect.ServerProgramCalls;

 

 

 

 

 

 

// call MWS410CA to print and/or generate all documents

                           ServerProgramCalls calls = new ServerProgramCalls(); //New program call session

              calls.ping(Environment.getStandardEnvironment(processData)); // New program connection

                           

                           ServerProgramCall mws410ca = new ServerProgramCall("MWS410CA"); //New program call

                 mws410ca.setFormatting(true);

 

                 mws410ca.addParameter("WWCONO", dialogWorkspace.getSessionValues().getValue("CONO"));

                 mws410ca.addParameter("WWCHID", dialogWorkspace.getSessionValues().getValue("USERID"));

                 mws410ca.addParameter("WWINOU", mapData.getData(METADATAID, "INOU"));

                 mws410ca.addParameter("WWDLIX", mapData.getData(METADATAID, "DLIX"));

                 mws410ca.addParameter("WWOPT2", mapData.getData(METADATAID, "OPT2"));

                 mws410ca.addParameter("XSGDTA", mapData.getData(METADATAID, "GDTA"));

 

                 

                 boolean ret = mws410ca.call(processData); //Execute program call

                 if (!ret) {

                     return false;

                 }

                

                           return true;

             }

}

 


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.