Application Development and Automation 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: 
Read only

Can't resolve the error for string operator && (concatenation )

Former Member
0 Likes
3,487

Hi All,

I am new to programming in ABAP and writing some code from some online tutorial available on SDN. I am receiving the following error with the code below


method SHOW.
Data  msg type string.
  msg = `Vehicle`       && |{ID}| &&
        `,Speed = `     && |{speed}| &&
        `,max-speed = ` && |{max_speed}|. 
  Message msg Type 'I'.
endmethod.

ID, speed and max_speed are of type integer. This code is supposed to give a message "Vehicle 7, speed 10, max-speed = 50" by concatenating the strings

However I receive the following error

Incorrect arithmetic or bit expression: Instead of "&&", an operator

(+, -, *, /, ... or BIT-AND, BIT-XOR, BIT-OR) was expected.

Read the online documentation and the code seem to be consistent with the guidelines.

What am i missing.

Thank

BRS

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,812

try changing the declaration of msg to type C then use CONCATENATE instead.

14 REPLIES 14
Read only

Former Member
0 Likes
2,813

try changing the declaration of msg to type C then use CONCATENATE instead.

Read only

0 Likes
2,812

Thank Jhaear,

I will try that options as well.

I was trying to figure out why this specific operator '&&' does not work.

If anyone can point out the error, let me know.

Thanks

BRS

Read only

0 Likes
2,812

Hi Jhaear,

I tried the concatenate key word. However that statement requires that variables ID, speed and max_speed be declared as char.

I don't want to change the type of the variables and hence the concatenate option will not work.

Any other options?

Thanks

Read only

0 Likes
2,812

Hi,

You can use

write to

Regards,

Jovito

Read only

0 Likes
2,812

hmm, right now i can't think of a more direct approach but you could try declaring some variables of type C then saving the values of ID, speed and max_speed in them, then use them for concatenation instead. that way you could keep ID, speed and max_speed as int.

Read only

Former Member
0 Likes
2,812

Hi,

This operator '&&' will not work in ABAP. Instead use CONCATENATE keyword. Just type that keyword, place the cursor over the keyword and press F1 key, you will get complete help for that. Hope this helps.

Regards,

Chandu.

Read only

0 Likes
2,812

Hi Chandu,

I found the following document online on SAP help and as per this document, it should be possible to use '&&' operator

Link: http://help.sap.com/abapdocu_702/en/abenstring_operators.htm

Thanks

BRS

Read only

former_member186491
Contributor
0 Likes
2,812

Hi,

method SHOW.

Data msg type string.

msg = `Vehicle` && || &&

`,Speed = ` && || &&

`,max-speed = ` && ||.

Message msg Type 'I'.

endmethod.

ID, speed and max_speed are of type integer. This code is supposed to give a message "Vehicle 7, speed 10, max-speed = 50" by concatenating the strings

With the assumptions that ID, SPEED and MAX_SPEED are variables and have already been populated, your code should be like --


method SHOW.
data msg type string.
msg = 'Vehicle'     & ID &
           ',Speed = ' & speed &
           ',max_speed = ' & max_speed   '.'

message msg type 'I'.
endmethod.

Try this; hope this will work.

Thanks.

Kumar Saurav.

Read only

0 Likes
2,812

Hi Saurav,

I tried your code and did a syntax check, but received the same error. As I mentioned earlier, the variables ID, speed and max_speed are of type integer.

Thanks

BRS

Read only

0 Likes
2,812

Hi,

Then, just do one thing - because you dont want to change types of your variables - use temporary variables for each of those having their types as STRING.

method SHOW.

data msg type string.

data: temp_id type string,

temp_speed type string,

temp_max_speed type string.

temp_id = id.

temp_speed = speed.

temp_max_speed = max_speed.

msg = 'Vehicle' & temp_ID &

',Speed = ' & temp_speed &

',max_speed = ' & temp_max_speed '.'

message msg type 'I'.

endmethod.

This way, you are not changing actual varibles and still harnessing advantages of string types.

Just give it a try. Hope this would certainly serve.

Thanks.

Kumar Saurav.

Read only

0 Likes
2,812

Hi Saurav,

I will try and let you know if it worked.

BRS

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,812

In se91 create a message like

Vehicle = & Speed = & max-speed = &.

Then raise the message like

message i(100) with id speed max_speed.

Read only

Former Member
0 Likes
2,812

I finally ended up using the concatenate key word and assigned the integer variable to a temporary string variable.

The code becomes a little less elegant with this options but works.

Also I think the && operator is available from AS 7.02 Ep1 so I guess its not possible in my system (7.0).

Thanks for all the responses.

Read only

0 Likes
2,812