Friday 29 September 2017

ABAP: Concatenate two strings

'CONCATENATE' function is used to concatenate two (or) more strings into one string.

Syntax
CONCATENATE  str1 str2 str3 ... strN INTO result.
CONCATENATE  str1 str2 str3 ... strN INTO result SEPARATED BY ' '.

Second version of the CONCATENATE function is used to concatenate strings using given separator.

Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*& Report Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_HELLO_WORLD.

DATA: str1 TYPE STRING VALUE 'Hello',
      str2 TYPE STRING VALUE 'World',
      str3 TYPE STRING VALUE 'to',
      str4 TYPE STRING VALUE 'ABAP Programming'.

DATA result TYPE STRING.

CONCATENATE str1 str2 str3 str4 INTO result.

Write: / 'Value of str1 is : ', str1.
Write: / 'Value of str2 is : ', str2.
Write: / 'Value of str3 is : ', str3.
Write: / 'Value of str4 is : ', str4.
Write: / 'Value of result is : ', result.
As you see the ouput, string are concatenated. It looks clear if we add some spaces while appending the string. Use the second version of the CONCATENATE function.

Below statement separates every string by a space while concatenating.
CONCATENATE str1 str2 str3 str4 INTO result SEPARATED BY ' '.


Z_HELLO_WORLD

*&---------------------------------------------------------------------*
*& Report Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_HELLO_WORLD.

DATA: str1 TYPE STRING VALUE 'Hello',
      str2 TYPE STRING VALUE 'World',
      str3 TYPE STRING VALUE 'to',
      str4 TYPE STRING VALUE 'ABAP Programming'.

DATA result TYPE STRING.

CONCATENATE str1 str2 str3 str4 INTO result SEPARATED BY ' '.

Write: / 'Value of str1 is : ', str1.
Write: / 'Value of str2 is : ', str2.
Write: / 'Value of str3 is : ', str3.
Write: / 'Value of str4 is : ', str4.
Write: / 'Value of result is : ', result.




Previous                                                 Next                                                 Home

No comments:

Post a Comment