有时候会有些类似的字符串:A10010001-A10020001+A10020002+A41030001+A43990001
需要解析为
+ A10010001
- A10020001
+
A10020002
+
A41030001
+
A43990001
可以参考以下算法:
FORM
zform_get_kemu_r TABLES t_right_kemu_list STRUCTURE str_right_kemu_list
USING u_str_hkonts .
DATA:
BEGIN OF zstr_kume_sign,
bjh_hkont TYPE zbjh_hkont,
zoperator TYPE zoperator,
END OF zstr_kume_sign.
DATA:
l_tmp TYPE string,
l_move TYPE int4.
DATA:
lt_kemu LIKE TABLE OF zstr_kume_sign WITH HEADER LINE.
DATA:
l_wa_kemu_list LIKE str_right_kemu_list.
l_tmp = u_str_hkonts.
"临时保存
REPLACE ALL OCCURRENCES OF '+' IN u_str_hkonts WITH '$'."替换掉加减法符号
REPLACE ALL OCCURRENCES OF '-' IN u_str_hkonts WITH '$'.
WHILE u_str_hkonts IS NOT INITIAL.
FIND '$' IN u_str_hkonts
MATCH OFFSET l_move.
"获取科目
IF sy-subrc <> 0.
"如果只有一项,没有其他的项目加减
lt_kemu-bjh_hkont = u_str_hkonts.
ELSE.
lt_kemu-bjh_hkont = u_str_hkonts+0(l_move).
"如果有多项,
ENDIF.
"第一个是正
IF sy-index = 1.
lt_kemu-zoperator = '+'.
APPEND lt_kemu.
ENDIF.
"第一个之后
IF sy-index > 1 AND u_str_hkonts IS NOT INITIAL.
lt_kemu-zoperator = l_tmp(1).
"获取符号
APPEND lt_kemu.
SHIFT: