Sign in

docs RPG Guide

Displaying the Return Value from a Procedure

Displaying the Return Value from a Procedure

If Control keyword DEBUG(*RETVAL) is specified, you can evaluate special variable _QRNU_RETVAL to see or change the value that the procedure will return.

Set a breakpoint on the last statement of the procedure to view or change the value of this variable.

  • In free-form code, set the breakpoint on the END-PROC statement.
  • In fixed-form code, set the breakpoint on the Procedure-End specification.

_QRNU_RETVAL is defined the same as the return value from the procedure.

  • If the return value is a data structure, _QRNU_RETVAL is also a data structure.

    For example, if the return value is defined with keyword LIKEDS(myDs), and myDs has subfields id and addr:

    • You can display the entire data structure

      EVAL _QRNU_RETVAL
    • You can display or change individual subfields

      EVAL _QRNU_RETVAL.addr
      EVAL _QRNU_RETVAL.id = 12345
  • If the return value is an array, _QRNU_RETVAL is an array. For example, if the return value is defined with keyword DIM(5):

    • You can display the entire array

      EVAL _QRNU_RETVAL
    • You can display or change individual elements

      EVAL _QRNU_RETVAL(1)
      EVAL _QRNU_RETVAL(2) = 25.3

For example, a programmer is debugging the following procedure.

  1. The procedure returns the value ‘abcde’.
  2. The programmer sets a breakpoint on the END-PROC statement.
  3. In the debug session, the programmer displays the return value.
CTL-OPT DEBUG(*RETVAL);
...
DCL-PROC myProc;
   DCL-PI *n CHAR(10) END-PI;

   RETURN 'abcde';  1 
END-PROC;           2 
  1. In the debug session at the END-PROC statement, the programmer displays the return value.
  2. Then the programmer changes the return value to ‘12345’.
  3. The value ‘12345’ is returned from the procedure.
> EVAL _qrnu_retval                     1 
  _QRNU_RETVAL = 'abcde     '
> EVAL _qrnu_retval = '12345'           2 
  _QRNU_RETVAL = '12345' = '12345     '