Tab character as delimiter in ABAP string

转自: http://www.kerum.pl/infodepot/00014


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 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.
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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值