Skip to content

Operation Extenders

Daniel Long edited this page Sep 29, 2026 · 3 revisions

Operation Extenders

Operation extenders modify the behavior of EVAL, EVALR, and CALLP. They are written in parentheses after the opcode. Each opcode takes its own set, and any other extender is rejected, as on IBM i (RNF5049):

Opcode Extenders
EVAL H, M, R
EVALR M, R
CALLP E, M, R

(H) — Half-Adjust (Round)

Rounds the result to the target precision before assignment:

DCL-S a PACKED(7:1) INZ(7.0);
DCL-S b PACKED(7:0) INZ(2);
DCL-S result INT(10);

EVAL(H) result = a / b;   // 7.0 / 2 = 3.5, rounds to 4
DSPLY %CHAR(result);       // 4

(M) and (R) — Precision Rules

(M) and (R) choose the precision rules for intermediate results in the expression: (M) the default "maximum digits" rules, (R) the "result decimal position" rules. Neither rounds; only (H) does:

EVAL(R) result = a / b;   // 7.0 / 2 = 3.5, truncated to 3
EVAL(MH) result = a / b;  // combined with H: rounds to 4

(E) — Error Capture

On CALLP, prevents an error in the call from halting the program. After the call, check %ERROR to see if it failed; %STATUS holds the status, 202 when the error happened inside the called procedure. EVAL takes no (E); put the statement in a MONITOR group instead:

CALLP(E) riskProc(arg);
IF %ERROR;
  DSPLY ('Call failed: ' + %CHAR(%STATUS));
ENDIF;

MONITOR;
  x = someCalc();
ON-ERROR;
  DSPLY 'Calc error';
ENDMON;

EVALR with Extenders

EVALR right-adjusts a character value into the target. It takes (M) and (R); there is nothing to round, so (H) is rejected:

DCL-S target CHAR(10);
EVALR(M) target = 'ABC';   // '       ABC'

(P) and (N) are not EVAL extenders; (N) belongs to file operations such as CHAIN(N).

Clone this wiki locally