Calling RPG programs from Java using PCML

An RPG program or procedure can be called from Java™ using a Program Call Markup Language (PCML) source file that describes the parameters for the RPG program or procedure. The Java application can use PCML by constructing a ProgramCallDocument object with a reference to the PCML source file.

The ILE RPG compiler will generate PCML information for your ILE RPG program or module when you specify the PGMINFO(*PCML) compiler parameter on your command or Control specification. You can have the PCML information generated into a stream file if you specify the *STMF or *ALL for the Location part of the PGMINFO parameter on the command; you specify the name of the stream file in the INFOSTMF command parameter. You can have the PCML information generated directly into the module if you specify *MODULE or *ALL for the Location part of the PGMINFO parameter on the command, or if you specify the PGMINFO keyword on the Control specification; you can later retrieve the information using the QBNRPII API.

For CRTBNDRPG, PCML is generated based on the contents of the *ENTRY PLIST or the Procedure Interface of the main procedure. For CRTRPGMOD, PCML is also generated based on the Procedure Interfaces of any exported subprocedures (except Java native methods).

When you use CRTRPGMOD, and create a service program, you specify the service program in your Java code using the setPath(String) method of the ProgramCallDocument class. For example:
     AS400 as400;
     ProgramCallDocument pcd;
     String path = "/QSYS.LIB/MYLIB.LIB/MYSRVPGM.SRVPGM";
     as400 = new AS400 ();
     pcd = new ProgramCallDocument (as400, "myModule");
     pcd.setPath ("MYFUNCTION", path);
     pcd.setValue ("MYFUNCTION.PARM1", "abc");
     rc = pcd.callProgram("MYFUNCTION");

Obtaining mixed-case names in the PCML

If you specify *DCLCASE as one of the parameters of the PGMINFO keyword of your Control specification, the PCML will be generated with the names in the same case as you coded them in your program. For example, for this source, the names in the PCML would be "myFunction", and "parm1", since PGMINFO(*DCLCASE) is specified.

     CTL-OPT PGMINFO(*DCLCASE) NOMAIN;
     DCL-PROC myFunction export;
        DCL-PI *N;
           parm1 CHAR(10);
        END-PI;
     END-PROC;
The Java code uses the same case for the names:
     AS400 as400;
     ProgramCallDocument pcd;
     String path = "/QSYS.LIB/MYLIB.LIB/MYSRVPGM.SRVPGM";
     as400 = new AS400 ();
     pcd = new ProgramCallDocument (as400, "myModule");
     pcd.setPath ("myFunction", path);
     pcd.setValue ("myFunction.parm1", "abc");
     rc = pcd.callProgram("myFunction");