Repository navigation
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
|
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) 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 4On 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 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).
- Installation
- Quick Start
- CLI Reference
- Language Basics
- Data Types
- Variables and Constants
- Data Structures
- Arrays
- Varying-Dimension Arrays
- Control Flow
- Procedures
- Procedure Overloading
- Built-In Functions
- Error Handling
- Operation Extenders
- Enumerations
- Program Status Data Structure
- Data Areas
- SND-MSG
- Embedded SQL
- Record-Level Access
- Display Files (WORKSTN)
- Program-Described Files (I-Specs and O-Specs)
- DATA-INTO and DATA-GEN
- XML-INTO
- Fixed-Format Source
- Database Connections
- Multi-Module Programs
- Environment Variables
- Testing
- Complete Example: Employee Report
- IBM i Conformance Results
- IBM i Execution Results