CTRLCHAR: Returning a Non-Printable Control Character

How to:

The CTRLCHAR function returns a nonprintable control character specific to the running operating environment, based on a supported list of keywords. The output is returned as variable length alphanumeric.

Syntax: How to Return a Non-Printable Control Character

CTRLCHAR(ctrl_char)

where:

ctrl_char

Is one of the following keywords.

  • NUL returns a null character.
  • SOH returns a start of heading character.
  • STX returns a start of text character.
  • ETX returns an end of text character.
  • EOT returns an end of transmission character.
  • ENQ returns an enquiry character.
  • ACK returns an acknowledge character.
  • BEL returns a bell or beep character.
  • BS returns a backspace character.
  • TAB or HT returns a horizontal tab character.
  • LF returns a line feed character.
  • VT returns a vertical tab character.
  • FF returns a form feed (top of page) character.
  • CR returns a carriage control character.
  • SO returns a shift out character.
  • SI returns a shift in character.
  • DLE returns a data link escape character.
  • DC1 or XON returns a device control 1 character.
  • DC2 returns a device control 2 character.
  • DC3 or XOFF returns a device control 3 character.
  • DC4 returns a device control 4 character.
  • NAK returns a negative acknowledge character.
  • SYN returns a synchronous idle character.
  • ETB returns an end of transmission block character.
  • CAN returns a cancel character.
  • EM returns an end of medium character.
  • SUB returns a substitute character.
  • ESC returns an escape, prefix, or altmode character.
  • FS returns a file separator character.
  • GS returns a group separator character.
  • RS returns a record separator character.
  • US returns a unit separator character.
  • DEL returns a delete, rubout, or interrupt character.

Example: Using the CTRLCHAR Function to Insert Control Characters Into a String

The following request defines a field with carriage return (CTRLCHAR(CR)) and line feed (CTRLCHAR(LF)) characters inserted between the words HELLO and GOODBYE. To show that these characters were inserted, the output is generated in PDF format and the StyleSheet attribute LINEBREAK='CRLF' is used to have these characters respected and print the field value on two lines.

DEFINE FILE WF_RETAIL_LITE
MYFIELD/A20 WITH COUNTRY_NAME='HELLO' | CTRLCHAR(CR) | CTRLCHAR(LF) | 'GOODBYE';
END 
TABLE FILE WF_RETAIL_LITE
SUM MYFIELD 
ON TABLE PCHOLD FORMAT PDF
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
TYPE=REPORT,LINEBREAK='CRLF',$
ENDSTYLE
END

The output is shown in the following image.