2011 Feb 22 2:57 AM
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
2011 Feb 22 3:12 AM
try changing the declaration of msg to type C then use CONCATENATE instead.
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
2011 Feb 22 3:12 AM
try changing the declaration of msg to type C then use CONCATENATE instead.
2011 Feb 22 3:21 AM
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
2011 Feb 22 3:41 AM
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
2011 Feb 22 3:47 AM
2011 Feb 22 3:48 AM
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.
2011 Feb 22 5:42 AM
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.
2011 Feb 22 11:02 AM
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
2011 Feb 22 6:01 AM
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.
2011 Feb 22 11:04 AM
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
2011 Feb 22 11:16 AM
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.
2011 Feb 22 11:20 AM
2011 Feb 22 12:24 PM
In se91 create a message like
Vehicle = & Speed = & max-speed = &.
Then raise the message like
message i(100) with id speed max_speed.
2011 Feb 22 8:27 PM
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.
2011 Feb 22 8:53 PM
&& is only available from 702 EhP2:
http://help.sap.com/abapdocu_702/en/abennews-71-string_processing.htm#!ABAP_MODIFICATION_3@3@
Regards,
Naimesh Patel