EDIT: Converting the Format of a Field

Available Languages: reporting

The EDIT function converts an alphanumeric field that contains numeric characters to numeric format or converts a numeric field to alphanumeric format.

This function is useful for manipulating a field in an expression that performs an operation that requires operands in a particular format.

When EDIT assigns a converted value to a new field, the format of the new field must correspond to the format of the returned value. For example, if EDIT converts a numeric field to an alphanumeric format, you must give the new field an alphanumeric format:

DEFINE ALPHAPRICE/A6 = EDIT(PRICE);

EDIT deals with a symbol in the following way:

  • When an alphanumeric field is converted to numeric format, a sign or decimal point in the field is stored as part of the numeric value.

    Any other non-numeric characters are invalid, and EDIT returns the value zero.

  • When converting a floating-point or packed-decimal field to alphanumeric format, EDIT removes the sign, the decimal point, and any number to the right of the decimal point. It then right-justifies the remaining digits and adds leading zeros to achieve the specified field length. Converting a number with more than nine significant digits in floating-point or packed-decimal format may produce an incorrect result.

EDIT also extracts characters from or add characters to an alphanumeric string. For more information, see EDIT: Extracting or Adding Characters.

Convert the Format of a Field

EDIT(fieldname);

where:

fieldname

Alphanumeric or Numeric

Is the field name.

Converting From Numeric to Alphanumeric Format

EDIT converts HIRE_DATE (a legacy date format) to alphanumeric format.

EDIT(HIRE_DATE)

For 82/04/01, the result is 820401.

For 81/11/02, the result is 811102.

EDIT converts HIRE_DATE (a legacy date format) to an alphanumeric format. CHGDAT is then able to use the field, which it expects in alphanumeric format:

TABLE FILE EMPLOYEE
PRINT HIRE_DATE AND COMPUTE
ALPHA_HIRE/A17 = EDIT(HIRE_DATE); NOPRINT AND COMPUTE
HIRE_MDY/A17 = CHGDAT('YMD', 'MDYYX', ALPHA_HIRE, 'A17');
BY LAST_NAME BY FIRST_NAME
WHERE DEPARTMENT EQ 'MIS';
END

The output is:

LAST_NAME  FIRST_NAME  HIRE_DATE  HIRE_MDY 
---------  ----------  ---------  -------- 
BLACKWOOD  ROSEMARIE   82/04/01   APRIL 01 1982 
CROSS      BARBARA     81/11/02   NOVEMBER 02 1981 
GREENSPAN  MARY        82/04/01   APRIL 01 1982 
JONES      DIANE       82/05/01   MAY 01 1982 
MCCOY      JOHN        81/07/01   JULY 01 1981 
SMITH      MARY        81/07/01   JULY 01 1981