Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP Programing: String Concatenation

kk_india_2023
Explorer
0 Kudos
693

Hi,

*Code for string concatenation.

DATA: S5, S6 TYPE STRING.

S5 = 'SAP'.
S6 = 'ABAP'.
WRITE / S5 && S6.

OUTPUT: SABAP

WHY ONLY FIRST CHARACTER OF STRING 'S5' IS CONCATINATED WITH STRING 'S6' ?

PLEASE EXPLAIN.

THANK YOU.

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
595

You'd better use the debugger. You would see that the issue is not with && but with DATA (how you used it).

You need to learn the effect of the comma and the effect of declaring a variable without an explicit type (implicit typing):

DATA: S5, S6 TYPE STRING.

ABAP Keyword Documentation: Chained Statements

ABAP Keyword Documentation: DATA, TYPE abap_type

7 REPLIES 7

AlexGourdet
Product and Topic Expert
Product and Topic Expert
595

Thank you for visiting SAP Community to get answers to your questions.

As you're looking to get most out of your community membership, please consider include a profile picture to increase user engagement & additional resources to your reference that can really benefit you:

I hope you find this advice useful, and we're happy to have you as part of SAP Community!

All the best,

Alex

Sandra_Rossi
Active Contributor
596

You'd better use the debugger. You would see that the issue is not with && but with DATA (how you used it).

You need to learn the effect of the comma and the effect of declaring a variable without an explicit type (implicit typing):

DATA: S5, S6 TYPE STRING.

ABAP Keyword Documentation: Chained Statements

ABAP Keyword Documentation: DATA, TYPE abap_type

0 Kudos
595

or use the good quote

data(S5) = `SAP`.<br>data(S6) = `ABAP`.<br>WRITE / S5 && S6.

0 Kudos
595

Thank You Sandra Rossi...

595

Hi Sandra Rossi,

DATA: S5, S6 TYPE STRING.

Here Object S5 is not a STRING data type.

By default S5 is declared as a Character data type and hence S5 can store only single character.

This was the reason why I was getting the Warning: The VALUE specification is longer than the corresponding field. The VALUE specification will only be passed to the field length!

I thought that, I must declare S5 as a character array by specifying its length to store multiple characters such as:

DATA: S5(5), S6 TYPE STRING.

I corrected my mistake by self learning. If my understanding is still wrong, please correct me.

Thank You.

595

kk_india_2023 I'm glad to see that you have solved the issue. Yes you're right in everything you said. Congrats and thanks for the feedback 😄

For information, concerning S5(5), the trend is to avoid this short syntax form and to use the explicit longest one S5 TYPE C LENGTH 5.

(ABAP documentation says: "For reasons of legibility, it is best to include all information and always use the addition LENGTH instead of parentheses to specify the length len.")

595

Hi Sandra Rossi,

Yes I will follow the explicit longest syntax. Thanks a lot for correcting my mistakes. 😄

Best Regards,

KIRANKUMAR