Abap - String manipulations

By xngo on February 21, 2019

Concatenation

Concatenate integers with strings:

REPORT  zconcatenate_int_string.
DATA:
      lv_string TYPE string,
      lv_int TYPE i VALUE 9.
 
*CONCATENATE works with string only.
* Therefore, you must cast the integer as a string 
*   by assigning the integer variable into a string variable.
lv_string = lv_int.
CONCATENATE 'The value is:' lv_string INTO lv_string.
 
WRITE: / lv_string.

Trimming

Remove leading and trailing spaces:

REPORT  Z_REMOVE_SPACES.
 
DATA: STR TYPE STRING.
STR = ' Hello, world ! '.
 
* Display the initial string with spaces.
WRITE:/ '|',STR,'|'.
 
* Remove space leading and trailing spaces from the string.
SHIFT STR LEFT DELETING LEADING SPACE.
SHIFT STR RIGHT DELETING TRAILING SPACE.
 
* Display end result.
WRITE:/ '|',STR,'|'.

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.