BAP分割字符串时,处理双字节截取出现的乱码,有三种方法:
1、调用函数STRING_SPLIT_AT_POSITION
原码:
CALL FUNCTION 'STRING_SPLIT_AT_POSITION'
EXPORTING
STRING = T_ITEMS-MAKTX
POS = 28
LANGU = SY-LANGU
IMPORTING
STRING1 = maktx2
STRING2 = maktx3
POS_NEW = pos
EXCEPTIONS
STRING1_TOO_SMALL = 1
STRING2_TOO_SMALL = 2
POS_NOT_VALID = 3
OTHERS = 4.
clear maktx3.
说明:
被分割字符串小于POS时,POS_NEW为零;当指定位置出现乱码时,POS_NEW小于POS
2、自己写代码
代码:
data: l_length type i,
out(11) type c,
in(20) type c..
l_length = charlen(in+10(*)).
if l_length = 2.
move in+0(10) to out.
else.
move in+0(11) to out.
endif.
3、使用函数TEXT_SPLIT
代码:
DATA: str_a(10) TYPE c VALUE '孟玉新',
str_result(10) TYPE c,
str_rest(10) TYPE c,
str_result2(10) TYPE c.
CALL FUNCTION 'TEXT_SPLIT'
EXPORTING
length = '3'
text = str_a
* AS_CHARACTER =
IMPORTING
line = str_result
rest = str_rest.
*Defect
str_result2 = str_a+0(3).
WRITE: / 'str_result = ', str_result,
/ 'str_rest = ' , str_rest,
/ 'str_result2 = ', str_result2.
*The result is list below.
*str_result = 孟
*str_rest = 玉新
*str_result2 = 孟<
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23495244/viewspace-688146/
,如需转载,请注明出处,否则将追究法律责任。