ABAP string processing
ABAP cheat sheets .
https://github.com/SAP-samples/abap-cheat-sheets
Concatenating Strings
"&& and string template DATA(s1) = `AB` && `AP`. "ABAP DATA(s2) = `ab` && `ap` && ` ` && s1. "abap ABAP DATA(s3) = |{ s1 }. { s2 }!|. "ABAP. abap ABAP! "CONCATENATE statements CONCATENATE s1 s2 INTO s3. "ABAPabap ABAP "Multiple data objects and target declared inline CONCATENATE s1 ` ` s2 INTO DATA(s5). "ABAP abap ABAP CONCATENATE s1 s2 s5 INTO DATA(s6). "ABAPabap ABAPABAP abap ABAP "You can also add a separation sign using the addition SEPARATED BY CONCATENATE s1 s2 INTO s3 SEPARATED BY ` `. "ABAP abap ABAP CONCATENATE s1 s2 INTO s3 SEPARATED BY `#`. "ABAP#abap ABAP "Keeping trailing blanks in the result when concatenating fixed length "strings. The ones of variable length strings are respected by default. CONCATENATE 'a ' 'b ' 'c ' INTO DATA(ch) RESPECTING BLANKS. "'a b c ' "Concatenating lines of internal tables into a string CONCATENATE LINES OF itab INTO t SEPARATED BY ` `. "Using concat_lines_of s1 = concat_lines_of( table = itab ). "Without separator s1 = concat_lines_of( table = itab sep = ` ` ). "With separator
Splitting Strings
DATA(s1) = `Hallo,world,123`. DATA: s2 TYPE string, s3 TYPE string, s4 TYPE string. SPLIT s1 AT `,` INTO s2 s3 s4. "s2 = Hallo / s3 = world / s4 = 123 "Less data objects than possible splittings SPLIT s1 AT `,` INTO s2 s3. "s2 = Hallo / s3 = world,123 "Splitting into internal table DATA itab TYPE TABLE OF string. SPLIT s1 AT ',' INTO TABLE itab. "Strings are added to itab in individual lines without comma "String function segment returning the occurrence of a segment "index parameter: number of segment s2 = segment( val = s1 index = 2 sep = `,` ). "world

浙公网安备 33010602011771号