Quick reminder. IN RPG, how do we return a parameter using C-style "Return value" syntax, instead of passing in parameter list? Using RPGLE /free.
// pgm: PARM1
dcl-pr PARM2 EXTPGM('PARM2');
PrOption char(1) const;
RET char(5) ;
end-pr;
dcl-s RET char(5) ;
Eval RET='';
callP PARM2('1':RET);
*inlr = *on;
return;
// pgm: PARM2
dcl-pr PARM2 EXTPGM('PARM2');
PrOption char(1) ;
RET char(5) ;
end-pr;
dcl-pI PARM2 ;
PrOption char(1) ;
RET char(5) ;
end-pI;
// do some stuff
Eval Ret= '1';
Eval *inlr = *on;
//Return RET;
return;
The RPG programs on IBM i do not support a returned value from a *PGM object.
Returned values are only supported from subprocedures.
// pgm: PARM1
dcl-pi PARM1 EXTPGM('PARM1');
PrOption char(1) const;
RET char(5) ;
end-pi;
ret = SubProc2('1');
*inlr = *on;
return;
dcl-proc SubProc2;
dcl-pi *n char(5);
PrOption char(1);
end-pi;
return '00001';
end-proc;
*PGM Return codes for RPG and COBOL are handled by the system.
The return codes sent by running RPG IV programs are:
- 0 --> When a program is started, or by the CALL operation before a program is called
- 1 --> When a program ends with LR set on
- 2 --> When a program ends with an error (response of C, D, F, or S to an inquiry message)
- 3 --> When a program ends because of a halt indicator (H1-H9)
ILE C programs
The current value of the integer return code is returned by the last ILE C return statement in an ILE C program.