Edit Using an Edit Word

EditWord

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
)

See also: EditCode, NumToChar, CharToNum

Parameters

pSrcValue
[input PTR value]  Any numeric field may be specified, enclosed in the %ADDR() built-in function. That is a pointer to the numeric field must be passed on this parameter. Packed, zoned and integer ("binary") are supported.
 
DataType
[input Char/Hex const] Specifies the data-type of the field specified on the pSrcValue parameter. Either a hexadecimal literal may be passed or one of the predefined named constants illustrated in the table that follows:
 
Symbolic Named Constant Value
T_Signed or T_Integer X'00'
T_Zoned X'02'
T_Packed X'03'
nSrcLen
[input int(2) const]  Specify the number of digits for the field specified on the pSrcValue parameter. This is the actual number of decimal digits (field length) of the numeric field specified on the pSrcValue parameter. The valid range is 1 to 31. You may also use the %LEN built-in function. For example, if you specify a field named AMT for pSrcValue parameter, you could specified %LEN(AMT) for this parameter.
nSrcDecPos
[input int(2) const]  Specify the number of decimal positions for the field specified on the pSrcValue parameter. The valid range is 0 to 30. If the value contains zero decimal positions, this parameter is optional. You may also use the %DECPOS built-in function. For example, if you specify a field named AMT for pSrcValue parameter, you could specified %DECPOS(AMT) for this parameter.
EditWord
[input vchar(256) const]  Specify any valid edit word to be used to format the resulting value. 

 

Return Value

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.

Remarks

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.

Example

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'