Der ABAP Befehl CONCATENATE wird sehr oft benötigt. In diesem kurzen Blog zeige ich anhand einiger Beispiele wie Zeichenketten im ABAP „concatendated“ werden können. In den Beispielen finden sich auch die „moderneren“ Formen mit && bzw. der Stringfunktion concat_lines_of. Ansonsten ist, denke ich. das Codingbeispiel eigentlich selbsterklärend und bedarf keiner weiteren Worte.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
REPORT zyfoes01. DATA l_string_1 TYPE string VALUE 'String 1'. DATA l_string_2 TYPE string VALUE 'String 2'. DATA l_hex1 TYPE x LENGTH 1 VALUE 01. DATA l_hex2 TYPE x LENGTH 1 VALUE 02. DATA l_hex_result TYPE x LENGTH 2. DATA l_char_1 TYPE c LENGTH 10 VALUE 'Char 1'. DATA l_char_2 TYPE c LENGTH 10 VALUE 'Char 2'. DATA l_string_result TYPE string. DATA lt_table LIKE TABLE OF l_string_1. APPEND 'Row1' TO lt_table. APPEND 'Row2' TO lt_table. APPEND 'Row3' TO lt_table. START-OF-SELECTION. * concatenate strings CONCATENATE l_string_1 l_string_2 INTO l_string_result. WRITE: / 'Example 1 :', l_string_result. * concatenate strings, respecting blanks. CONCATENATE l_string_1 l_string_2 INTO l_string_result RESPECTING BLANKS. WRITE: / 'Example 2 :', l_string_result. * concatenate strings, separated by character CONCATENATE l_string_1 l_string_2 INTO l_string_result SEPARATED BY ';'. WRITE: / 'Example 3 :',l_string_result. * concatenate char CONCATENATE l_char_1 l_char_2 INTO l_string_result. WRITE: / 'Example 4 :',l_string_result. * concatenate char, respecting blanks CONCATENATE l_char_1 l_char_2 INTO l_string_result RESPECTING BLANKS. WRITE: / 'Example 5 :', l_string_result. * concatenate char, separated by character CONCATENATE l_char_1 l_char_2 INTO l_string_result SEPARATED BY ';'. WRITE: / 'Example 6 :', l_string_result. * concatenate lines of a table CONCATENATE LINES OF lt_table INTO l_string_result. WRITE: / 'Example 7 :', l_string_result. * concatenate lines of a table separated by character CONCATENATE LINES OF lt_table INTO l_string_result SEPARATED BY ';'. WRITE: / 'Example 8 :', l_string_result. * concatenate hex, in BYTE MODE CONCATENATE l_hex1 l_hex2 INTO l_hex_result IN BYTE MODE. WRITE: / 'Example 9 :', l_hex_result. * chaining operator && l_string_result = l_char_1 && l_char_2 && l_string_1 && l_string_2. WRITE: / 'Example 10:', l_string_result. * concatenation function - concat_lines_of l_string_result = concat_lines_of( table = lt_table sep = ';' ). WRITE: / 'Example 11:', l_string_result. |