Copyright 2024 - BV TallVision IT

If a number or non-printable character is placed in a CHAR-variable, it will be displayed as a #.

SAP's way to say: the character could not be printed so it should be interpreted as a "number" (like #1 = number one). No problems so far, until this special character needs to be replaced by something else. Consider the following situation:

A Microsoft Write file with tabs was read into an internal table using the GUI_UPLOADĀ function module. The result was a table that looked like this:

0001  NAME#OCCUPATION#SALARY SCALE
0002
0003  Andrews#Engineer#M5
0004  Emst#Director#M12
0005  Claessens#Pilot#M11

Since the Microsoft Write file contained tabs, the # that is displayed is not really a #-character at all. The real value can be determined by doing this:

FIELD-SYMBOLS: <fs_CHAR_X> TYPE X.
data: lv_CHAR type c length 1.

* The TAB character
lv_CHAR = CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
ASSIGN lv_CHAR TO <fs_CHAR_X> CASTING TYPE X.
WRITE: / 'The tab character :' , <fs_CHAR_X>(1).

* The # character
lv_CHAR = '#'.
ASSIGN lv_CHAR TO <fs_CHAR_X> CASTING TYPE X.
WRITE: / 'A real # character:' , <fs_CHAR_X>(1).

The result would be something like:

The tab character : 09
A real # character: 23

So before using the REPLACE, SPLIT, TRANSLATE or string comparison operators like CA, CO or CS, make sure you're #-character is really filled with the "right" value !

The other way around: if you would like to put the TAB character in your string, here's how:

data: lv_tabulator_character.
FIELD-SYMBOLS: <fc_CHAR_X> TYPE X.

assign lv_tabulator_character TO <fc_CHAR_X> CASTING TYPE 'X'. 
move 9 to <fc_CHAR_X>. " 9 = The tabulator

Utilities for character strings in Abap Objects

When you're after more - make sure you check out the ABAP character utilities class (SE24) called CL_ABAP_CHAR_UTILITIES which also holds attributes for special characters like HORIZONTAL_TAB, VERTICAL_TAB, NEWLINE, CR_LF, FORM_FEED and BACKSPACE.