Tab character as delimiter in ABAP string

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)
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 constant HORIZONTAL_TAB)
DATA:
  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.
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.
See other related notes in my infodepot:
Split ABAP string to internal table retaining whole words Save internal table as CSV file delimited by Tab
Full list of examples in my infodepot

If you have a question, have found an error or just want to contact me, please use this form.

Copyright (C) 2010 http://www.kerum.pl/infodepot/

Disclaimer: I am not affiliated or related to any division or subsidiary of SAP AG.
Trademarks or registered trademarks of any products or companies referred to on this site belong to those companies.
Anyone using the given solutions, is doing it under his/her own responsibility and at own risk.