I have an ILE RPG module that needs to pass parameters to a ILE CL module and receive a return value. Prototyping...
the CL call as EXTPGM will not get us the return value and hence we need to use EXTPROC. How do we receive a value from the CL Module and use it in RPG Module? How should the call statement be written?
The CL module has a PGM statement that lists the variable names passed into and out of the module. All values passed in will also be passed out.
The RPGLE source must contain a procedure prototype naming the CL *MODULE object in the EXTPROC keyword. Note: The procedure name is in fact the *MODULE object name. No return value must be specified. The prototype parameters following the procedure name statement must be of the same type and size as the parameters in the CLLE module.
When defining parameters for RPGLE<-->CLLE procedure calls, try to avoid 1-byte lengths, for reasons which used to be valid but probably are not any more. I make a habit of defining return codes as seven characters, because I can then pass a meaningful value or a message ID. Also, avoid 1 and 2 byte integer and unsigned fields, 1-byte graphic and UCS-2, and 4-byte floating-point fields. You may have no problems with them, but if you do have problems it may be connected with field types.
Use NO keywords on the prototype parameter statements in the RPG. The parameters will be passed by address.
In CLLE (source member SAMPLE_2) : PGM PARM(&RTCD &COMMAND) DCL VAR(&RTCD) TYPE(*CHAR) LEN(7) DCL VAR(&COMMAND) TYPE(*CHAR) LEN(50)
Use CRTCLMOD to create the *MODULE object. No special options need to be used.
In RPGLE : D Sample_2 PR ExtProc('SAMPLE_2') D pRtcd 7 D pCmd 50
In your C-specs use CALLP to call the CLLE module:
C CallP Sample_2(wkRTCD : Command)
If the CLLE module changes the values in the fields &RTCD or &COMMAND, those changed values will be reflected in the fields WKRTCD and Command in the RPGLE program.
NOTE: To compile the RPGLE object, you must either create it as a *MODULE object and then create a bound program from the two *MODULE objects, or else you can create the RPGLE as a *PGM object directly using CRTBNDRPG -- but only if you add the CLLE *MODULE object name to a binding directory and specify the following options on the CRTBNDRPG command:
Dig Deeper on iSeries ILE programming
Related Q&A from John Blenkinsop
When an error occurs on an IBM command, the diagnostic messages are sent first, then an escape message, which you can monitor. On AS/400 you see the ... Continue Reading
Learn how to 'append data to the file' with the FTP DIR command, and eliminate the hassle of having to end the FTP session and restart to view ... Continue Reading
RPGIV will 'think of' incoming integer fields as binary, and then will redefine them in the program structures as PACKED. So, when you chain a record... Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.