It can be a bit difficult to use tabulator character (hex code 0x0009) in ABAP strings.
On the other hand it is often used as separator in various interface files
and you need tab character to split the lines into fields or insert it into
the strings as delimiter.
If you need to fulfill the unicode check, you have to use special approach to combine hex code and string. Otherwise you will get the syntax error from compiler:
"TAB" must be a character-like data object (data type C, N, D, T, or STRING)
If you need to fulfill the unicode check, you have to use special approach to combine hex code and string. Otherwise you will get the syntax error from compiler:
"TAB" must be a character-like data object (data type C, N, D, T, or STRING)
Here three examples, how the tab character can be used in combination with string in abap.
You can use similar approach for other difficult characters, for example ENTER.
Example 1: can be used in non-unicode and unicode systems:
(tabulator hex code is defined in class CL_ABAP_CHAR_UTILITIES as constants HORIZONTAL_TAB)
DATA:
tab type c value cl_abap_char_utilities=>horizontal_tab,
str TYPE string.
CONCATENATE 'aaa' 'bbb' INTO str SEPARATED BY tab.
tab type c value cl_abap_char_utilities=>horizontal_tab,
str TYPE string.
CONCATENATE 'aaa' 'bbb' INTO str SEPARATED BY tab.
Here other useful constants defined in class CL_ABAP_CHAR_UTILITIES:
Name | Length | Hex-Value | Dec-Value |
BACKSPACE | 1 | 0x08 | 8 |
HORIZONTAL_TAB | 1 | 0x09 | 9 |
VERTICAL_TAB | 1 | 0x0B | 11 |
FORM_FEED | 1 | 0x0C | 12 |
NEWLINE | 1 | 0x0A | 10 |
CR_LF | 2 | 0x0D0A | 13 10 |
Example 2: it also works in non-unicode and unicode systems:
DATA:
tab TYPE x VALUE '09',
chr TYPE c,
str TYPE string.
FIELD-SYMBOLS:
<fs> TYPE ANY.
ASSIGN chr TO <fs> CASTING TYPE x.
<fs> = tab.
CONCATENATE 'aaa' 'bbb' INTO str SEPARATED BY chr.
tab TYPE x VALUE '09',
chr TYPE c,
str TYPE string.
FIELD-SYMBOLS:
<fs> TYPE ANY.
ASSIGN chr TO <fs> CASTING TYPE x.
<fs> = tab.
CONCATENATE 'aaa' 'bbb' INTO str SEPARATED BY chr.
Exapmle 3: it will only work in non-unicode system:
DATA:tab TYPE x VALUE '09',
str TYPE string.
CONCATENATE 'aaa' 'bbb' INTO str SEPARATED BY tab.
댓글 없음:
댓글 쓰기