%EDITC (Edit Value Using an Editcode)
%EDITC(numeric : editcode {: *ASTFILL | *CURSYM | currency-symbol})
This function returns a character result representing the numeric
value edited according to the edit code. In general, the rules for
the numeric value and edit code are identical to those for editing
numeric values in output specifications. The third parameter is optional,
and if specified, must be one of:
- *ASTFILL
- Indicates that asterisk protection is to be used. This means that leading zeros are replaced with asterisks in the returned value. For example, %EDITC(-0012.5 : 'K' : *ASTFILL) returns '***12.5-'.
- *CURSYM
- Indicates that a floating currency symbol is to be used. The actual symbol will be the one specified on the control specification in the CURSYM keyword, or the default, '$'. When *CURSYM is specified, the currency symbol is placed in the the result just before the first significant digit. For example, %EDITC(0012.5 : 'K' : *CURSYM) returns ' $12.5 '.
- currency-symbol
- Indicates that floating currency is to be used with the provided currency symbol. It must be a 1-byte character constant (literal, named constant or expression that can be evaluated at compile time). For example, %EDITC(0012.5 : 'K' : 'X') returns ' X12.5 '.
The result of %EDITC is always the same length, and may contain leading and trailing blanks. For example, %EDITC(NUM : 'A' : '$') might return '$1,234.56CR' for one value of NUM and ' $4.56 ' for another value.
Float expressions are not allowed in the first parameter (you can use %DEC to convert a float to an editable format). In the second parameter, the edit code is specified as a character constant; supported edit codes are: 'A' - 'D', 'J' - 'Q', 'X' - 'Z', '1' - '9'. The constant can be a literal, named constant or an expression whose value can be determined at compile time.
For more information, see Conversion Operations or Built-in Functions.
A common requirement is to edit a field as follows:
- Leading zeros are suppressed
- Parentheses are placed around the value if it is negative
The following accomplishes this using an %EDITC in a subprocedure: