Return to the RPG Tips
Passing an Indicator from RPG to CL
Q. Can I pass an indicator from an RPG/400 program to a CL program?A. For reasons I don't entirely understand, neither RPG/400 nor RPG IV lets you specify indicators in the Parm opcode's result field. However, I know of two ways to work around this problem in RPG IV.
One way is to take advantage of RPG IV's pointer support. Suppose you have a CL program that must receive indicator 57 as a parameter. The following shows how you code this with RPG IV's pointer support:
* etc. D IndDsPtr S * Inz( %Addr( *IN ) ) D IndDs DS Based( IndDsPtr ) D Ind57 57 57 D Ind23 23 23 * etc. C Call 'CLPGM' C Parm Ind57 * etc.Here, I've defined a based data structure called IndDs whose basing pointer is IndDsPtr. IndDsPtr is initialized with the address of the indicator array. Therefore, field Ind57, which is defined as a one-byte field in position 57 of the data structure, is actually addressing indicator 57. I can pass field Ind57 as a parameter as shown in the Parm statement following the Call.The following code shows how to set up your CL program to accept this indicator parameter. Notice you can define the indicator parameter either as a character or a logical variable.
Pgm &IndParm /* Note, I show two alternatives for declaring the */ /* passed indicator parameter. */ /* Alternative 1 declare as a character variable */ Dcl &IndParm *Char 1 /* Alternative 2 declare as a logical variable */ Dcl &IndParm *Lgl /* etc. */The second technique for passing an indicator as a parameter from an RPG IV program to a CL program is to prototype the call, as shown below:* etc. D ClPgm PR ExtPgm( 'CLPGM' ) D IndParm 1 * etc. C CallP ClPgm( *IN57 ) C Eval *INLR = *On * etc.The prototype uses the ExtPgm keyword, which tells the compiler that I want to make an ordinary dynamic call to an external program (as opposed to invoking an ILE procedure). The parameter is simply defined as a one-character field. RPG lets me pass an indicator as my parameter, as shown at the CallP statement. You use the technique in the sample CL above to set up the CL program to receive the indicator variable.by Mike Cravitz
[report a broken link by clicking here]