COBOL and PCML

A COBOL program can be called from a Java™ application using a Program Call Markup Language (PCML) source file that describes the input and output parameters for the COBOL program. The Java application can use PCML by constructing a ProgramCallDocument object with a reference to the PCML source file. See Programming->Java->IBM Toolbox for Java->Program Call Markup Language in the IBM® i Information Centerhttp://www.ibm.com/systems/i/infocenter/ for more information on how to use PCML with Java. PCML handles the data type conversions between the COBOL format and the Java format.

The ILE COBOL compiler will generate PCML for your COBOL program when you specify the PGMINFO command parameter or the PGMINFO PROCESS option. The PCML can be generated in a stream file or it can be made part of your COBOL module. If the PCML is part of your COBOL module, it can be retrieved from a program or service program containing your module using the QBNRPII API.

To have the PCML generated into a stream file, specify the PGMINFO(*PCML) command parameter along with the INFOSTMF compiler parameter to specify the name of an Integrated File System output file to receive the generated file.

To have the PCML generated directly into the COBOL module, specify the PGMINFO(*PCML *MODULE) command parameter, or specify the PGMINFO(PCML MODULE) PROCESS option.

You can have the PCML generated both into a stream file and into the COBOL module by specifying PGMINFO(*PCML *ALL) command parameter along with the INFOSTMF parameter, or by specifying the PGMINFO(*PCML) and INFOSTMF command parameters, and specifying the PGMINFO(PCML MODULE) PROCESS option.

If you specify PROCESS option PGMINFO(NOPGMINFO), no PCML will be generated even if you specified the PGMINFO(*PCML) command parameter.

Table 1 shows the support in PCML for the COBOL datatypes:

Table 1. COBOL Datatypes and Corresponding PCML Support
COBOL Data Type COBOL Format Supported in PCML PCML Data Type Length Precision Count
Character X(n) Yes character n    
A(n) Yes character n    
X(n) OCCURS DEPENDING ON M 5 Yes structure     m
A(n) OCCURS DEPENDING ON m 5 Yes structure     m
Numeric 9(n) DISPLAY Yes zoned decimal n 0  
S9(n-p)V9(p) DISPLAY Yes zoned decimal n p  
9(n-p)V9(p)
PACKED-DECIMAL 3
Yes packed decimal n p  
S9(n-p)V9(p)
PACKED-DECIMAL 3
Yes packed decimal n p  
9(4) BINARY 1, 2
Yes integer 2 15  
9(4) COMP-5 Yes integer 2 16  
S9(4) BINARY
S9(4) COMP-5 1, 2
Yes integer 2 15  
9(9) BINARY 1, 2
Yes integer 4 31  
9(9) COMP-5 Yes integer 4 32  
S9(9) BINARY
S9(9) COMP-5 1, 2
Yes integer 4 31  
S9(18) BINARY
S9(18) COMP-5 1, 2
Yes integer 8 63  
9(18) BINARY 1, 2
Yes integer 8 63  
9(18) COMP-5 not supported integer 8 64  
9(n)V9(p) BINARY
S9(n)V9(p) BINARY
9(n)V9(p) COMP-5
S9(n)V9(p) COMP-5
not supported        
USAGE COMP-1 Yes float 4    
USAGE COMP-2 Yes float 8    
UCS2
N(n) 4
Yes UCS-2/graphics n    
N(n) OCCURS
DEPENDING ON m 4, 5
Yes structure     m
Graphic G(n) Yes UCS-2/graphics n    
G(n) OCCURS DEPENDING ON M 5 Yes structure     m
Index USAGE INDEX Yes integer 4 31  
Boolean 1 not supported        
Date FORMAT DATE not supported        
Time FORMAT TIME not supported        
Timestamp FORMAT TIMESTAMP not supported        
Pointer USAGE POINTER not supported        
Procedure Pointer PROCEDURE POINTER not supported        
Note:
  1. To reduce truncation for BINARY data items, specify NOSTDTRUNC on the PROCESS statement. NOSTDTRUNC should always be specified when passing BINARY data items.
  2. BINARY, COMP-4, COMPUTATIONAL-4 map to an integer in PCML.
  3. PACKED-DECIMAL, COMP-3, COMPUTATIONAL-3, COMP, and COMPUTATIONAL are equivalent and map to the same PCML (unless COMPASBIN PROCESS option is specified, see PROCESS Statement Options for more information).
  4. PIC N is a national (UCS2) item if USAGE NATIONAL is specified or if USAGE is not specified and the NATIONAL or NATIONALPICNLIT compiler option is specified, otherwise USAGE DISPLAY-1 (DBCS) is implied.
  5. The PCML for an OCCURS DEPENDING ON array has an "init" tag that specifies the maximum size of the array.

PCML is generated based on the contents of the Procedure Division USING and GIVING/RETURNING phrases and the contents of the LINKAGE section in your COBOL program. PCML will be generated for all parameters specifed in the PROCEDURE DIVISION header USING phrase. PCML will be generated for a parameter specified in the GIVING/RETURNING phrase for this header. An error will be issued if the GIVING/RETURNING item is not a 4 byte signed binary integer. Items specified in the USING phrase that are defined as "inputoutput" in the generated PCML can be used to return information to the calling program. Items defined with the TYPE clause will receive a PCML error. For the calling program (eg JAVA program) to see the contents of the RETURN-CODE special register, the RETURN-CODE special register must be specified on the USING phrase of the PROCEDURE DIVISION header. The object data item for an OCCURS DEPENDING ON (ODO) must be defined in the linkage section and be specified as a parameter in the PROCEDURE DIVISION header USING phrase for PCML to be correctly generated for the ODO subject data item.

PCML will not be generated for renamed/redefined items.

PCML generation provides automatic data-item naming in generated PCML for filler data items and unnamed items in a data structure, helping to enable web services to use generated PCML without first modifying it. The names for these data items will be _filler_1, _filler_2, and so on.

When you use CRTCBLMOD, 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"); 
If you use CRTCBLMOD and create a program, not a service program, you will need to remove the entrypoint attribute from the PCML, since this attribute is needed only when calling service programs.