[ABAP] How do I manipulate strings in ABAP (e.g., concatenation, length)?

In ABAP, you can manipulate strings using various string functions and methods. Here are some examples of how to perform common string operations like concatenation and length calculation:

  1. Concatenation:

    • Using the CONCATENATE statement:
      1CONCATENATE 'Hello' 'World' INTO lv_string.
    • Using the & operator:
      1lv_string = 'Hello' & 'World'.
  2. Length Calculation:

    • Using the STRLEN function:
      1DATA(lv_length) = STRLEN( lv_string ).
  3. Substring Extraction:

    • Using the SUBSTRING function:
      1DATA(lv_substring) = SUBSTRING( lv_string FROM 3 FOR 5 ).
  4. String Replacement:

    • Using the REPLACE function:
      1DATA(lv_new_string) = REPLACE( lv_string 'old' 'new' ).
  5. Case Conversion:

    • Using the CONV method:
      1DATA(lv_uppercase) = lv_string->CONV( |U| ).
    • Using the TRANSLATE function:
      1DATA(lv_uppercase) = TRANSLATE( lv_string TO UPPER CASE ).
  6. Padding:

    • Using the CONCATENATE statement:
      1CONCATENATE lv_string ' ' INTO lv_padded_string.
    • Using the CONDENSE statement:
      1CONDENSE lv_string.

These are just a few examples of string manipulation in ABAP. There are many more functions and methods available in the ABAP language for different string operations.