The EditWord procedure dynamically converts numeric data to an edited character value. That character value is suitable for: displaying on a 5250 device, printed output, HTML web page, EDI, writing to a file as text data or any other purpose.
The EditWord procedure performs a function similar to the %EDITW built-in function except the edit word can be stored in a program variable and the data type, length and decimal positions are passed to this procedure.
varying-length-char-value EditWord( pSrcValue * VALUE DataType 1A Const nSrcLen 5I 0 Const nSrcDecPos 5I 0 Const EditWord 256A Const VARYING ) |
| Symbolic Named Constant | Value |
| T_Signed or T_Integer | X'00' |
| T_Zoned | X'02' |
| T_Packed | X'03' |
If the function succeeds, the return value is the edited form of the numeric value specified on the pSrcValue parameter. The value returned is edited using the edit code specified. If the TrimBlanks parameter was specified and is equal to *ON, then trailing and leading blanks (if any) are removed before the value is returned to the caller. The return value may be assigned to a character field (with or without the VARYING attribute).
If the function fails, the return value is empty.
This procedure provides a way to edit values using an edit code stored in a character field, it also allows a dynamic value to be specified for the first parameter since it is a pointer.
In the example that follows, the EditWord procedure is used to extract a packed decimal value from a flat-file record. That numeric value, referred to as amount due is converted to character and copied to the szDue field.
H DftActGrp(*NO) BNDDIR('XTOOLS/RPGLIB')
/INCLUDE QCPYSRC,UTILS
.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++++++++++
D szDue S 12A
D AmtDue S 7P 2 Inz(45.50)
D ew S 1A Inz(' 0 . ')
** Dynamically edit the AMTDUE field with the 'J' edit code.
.....C..n01..............OpCode(ex)Extended-factor2++++++++++++++++++++++++++
C Eval szDue = EditWord(%Addr(AmtDue) :
C T_PACKED : 7 : 2 : ew : '$')
The value returned to the szDue field is: '045.50'