Available Languages: reporting, Maintain
The CTRFLD function centers a character string within a field. The number of leading spaces is equal to or one less than the number of trailing spaces.
CTRFLD is useful for centering the contents of a field and its report column, or a heading that consists only of an embedded field. HEADING CENTER centers each field value including trailing spaces. To center the field value without the trailing spaces, first center the value within the field using CTRFLD.
Limit: Using CTRFLD in a styled report (StyleSheets feature) generally negates the effect of CTRFLD unless the item is also styled as a centered element. Also, if you are using CTRFLD on a platform for which the default font is proportional, either use a non-proportional font, or issue SET STYLE=OFF before running the request.
CTRFLD(source_string, length, output)
Is the character string enclosed in single quotation marks, or a field or variable that contains the character string.
Is the number of characters in source_string and output, or a field that contains the length. This argument must be greater than 0. A length less than 0 can cause unpredictable results.
Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.
CTRFLD centers LAST_NAME and stores the result in CENTER_NAME:
SET STYLE=OFF TABLE FILE EMPLOYEE PRINT LAST_NAME AND COMPUTE CENTER_NAME/A12 = CTRFLD(LAST_NAME, 12, 'A12'); WHERE DEPARTMENT EQ 'MIS' END
The output is:
LAST_NAME CENTER_NAME --------- ----------- SMITH SMITH JONES JONES MCCOY MCCOY BLACKWOOD BLACKWOOD GREENSPAN GREENSPAN CROSS CROSS