Passing Data to an ILE RPG Program or Procedure

You can pass data to a called ILE RPG program or procedure by using CALL…BY REFERENCE, CALL…BY VALUE, or CALL…BY CONTENT. Refer to Passing Data Using CALL…BY REFERENCE, BY VALUE, or BY CONTENT for a description of how to use CALL…BY REFERENCE, CALL…BY VALUE or CALL…BY CONTENT.

When data is passed to the ILE RPG program using CALL…BY REFERENCE, a pointer to the data item is placed into the argument list that is accepted by the ILE RPG program. When data is passed to the ILE RPG program using CALL…BY CONTENT, the value of the data item is copied to a temporary location and then a pointer containing the address of the copy's temporary location is placed into the argument list that is accepted by the ILE RPG program. For CALL…BY VALUE, the value of the item is placed into the argument list that is accepted by the ILE RPG program. CALL…BY VALUE can be used to call ILE RPG procedures but not ILE RPG program objects.

In your ILE COBOL program, you describe the arguments that you want to pass to the ILE RPG program or procedure, in the Data Division in the same manner as you describe other data items in the Data Division. Refer to Passing and Sharing Data Between Programs for a description of how to describe the arguments that you want to pass.

In the called ILE RPG program, you describe the parameters that you want to receive from the ILE COBOL program using the PARM operation. Each receiving parameter is defined in a separate PARM operation. You specify the name of the parameter in the Result field. The Factor 1 and Factor 2 entries are optional and indicate variables or literals. The value from the Factor 1 field is transferred from the Result field entry when the call occurs. The value from the Factor 2 field is placed in the Result field entry upon return.

Another method of defining parameters in an ILE RPG program is to specify them in a prototype. Each parameter is defined on a separate definition specification. For parameters passed BY REFERENCE, no special keywords are necessary. For parameters passed BY VALUE, the VALUE keyword is used. Refer to the IBM® Rational® Development Studio for i: ILE RPG Programmer's Guide for more information on how to describe the arguments in an ILE RPG program.