‎2006 Jul 21 9:35 PM
Hello,
i have a really weird error message here:
say I define 2 dta type c objects:
data: tot_str(50) type c,
sub_str(20) type c.
then I do
tot_str = 'ABCDEF' & substr
assuming both tot_str and sub_str are already initialized.
However, the error message I got is:
Incorrect arithmetic or bit expression: Instead of "&", an operator (+, -, *, /, ... or BIT-AND, BIT-XOR, BIT-OR) was expected.)
Why is it so? I thought & is the standard concatenation character for ABAP. And BTW, when I changed to +, it will give me a run-time error saying that the 2 strings can not be added....
Thanks a lot!
Regards,
Anyi
‎2006 Jul 21 9:41 PM
Hi there,
Using cancatenate str1 str2 into Tot_string.
Hope this helps
‎2006 Jul 21 9:41 PM
Hi there,
Using cancatenate str1 str2 into Tot_string.
Hope this helps
‎2006 Jul 21 9:41 PM
wa_test(100) type c.
concatenate tot_str sub_str into wa_test.
Regds
Manohar
‎2006 Jul 21 9:45 PM
CONCATENATE 'ABCDEF' SUBSTR INTO TOT_STR.
the above should resolve your issue.
U can surely use SEPARATED BY SPACE or any other delimiter.
Regards
Anurag
‎2006 Jul 21 10:21 PM
‎2006 Jul 21 10:30 PM
HI
good
data: tot_str(50) type c,
sub_str(20) type c.
then I do
tot_str = 'ABCDEF' & substr
this is your codes
-
ANSWER
data: tot_str(50) type c,
sub_str(20) type c,
XYZ(20) TYPE C VALUE 'ABCDEF'.
ONCATENATE XYZ sub_str INTO TOT_STR.
thanks
mrutyun
‎2006 Jul 22 9:56 AM
hi,
try this simple one,
data: first(10),middle,last(10),name(21).
write:/41 first color 7,middle color 7,last color 7.
concatenate first middle last into name separated by space.
write:/41 first color 6,middle color 6,last color 6.
best of luck,
regards,
kcc
‎2006 Jul 22 10:37 AM
Hi Anyi,
you try to use & as an operator for concatenation of strings.
Unfortunately, & and + are not defined as operators for character type variables. & is not defined as an operator in ABAP. AFAIK & is not used in ABAP for anything.
As the other guys recommended, you have to use concatenate for this purpose. But note that concatenate will remove leading and trailing blanks from the strings concatenated.
If you need the blanks, then use offsets, i.e.
tot_str = 'ABCDEF'.
tot_str+6 = substr.
Best regards,
Clemens
‎2006 Jul 22 5:49 PM
<i>Unfortunately, & and + are not defined as operators for character type variables. & is not defined as an operator in ABAP. AFAIK & is not used in ABAP for anything.</i>
& is used in ABAP. It is used to put two or more literals into a string.
report zrich_0001.
data: str type string.
str = 'This is one part of the string' &
' This is another part of the string' &
' And here is another part of the string'.
write:/ str.Regards,
Rich Heilman
‎2006 Jul 22 6:03 PM
OOPS!
Sorry, Rich, you are right and I learned something.
I searched all SAP Help material available online but could not find any reference to operator &.
This is a good replacement for concatenate as it does not remove leading and trailing blanks.
Thanks a lot!
Since when do they have & in ABAP?
Regards,
Clemens Li
P.S.: I just saw that it's for literals only - so not much more than useless
Message was edited by: Clemens Li
‎2006 Jul 22 6:12 PM
Thanks everyone for their replies.
However, I was kind of confused with Clemen's post, so if I am correct here, it means that the & is used to concatenate to string literals, i.e.,
'abcd'&'efgh' is acceptable in ABAP, and if my understanding is correct, this & is already out-dated and no longer used.
but concatenate is used in concatention of strings.
say for example
concatenate 'abcd' str1 str2.
However, the problem with concatenate is that it will remove all the leading blank spaces.
Is my understanding correct?
Thanks a lot guys!
Regards,
Anyi
> <i>Unfortunately, & and + are not defined as
> operators for character type variables. & is not
> defined as an operator in ABAP. AFAIK & is not used
> in ABAP for anything.</i>
>
> & is used in ABAP. It is used to put two or more
> literals into a string.
>
>
>
>
>
>
report zrich_0001.
>
> data: str type string.
>
>
> str = 'This is one part of the string' &
> ' This is another part of the string' &
> ' And here is another part of the string'.
>
> write:/ str.>
>
> Regards,
> Rich Heilman
‎2006 Jul 22 7:37 PM
Hi Anyi,
yes you are right. I found it in SAP help hidden somewhere in the data objects section:
"If you want to enter a character literal in the ABAP Editor that is longer than a single editor line, ABAP syntax allows you to enter several character literals and link them using the & character. "
So this was just a crutch to bypass the (meanwhile obsolete) editor line length limit.
I the section "Processing Character Strings", chapter "Concatenating Character Strings", they say:
"The CONCATENATE statement combines two or more separate strings into one.
CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].
This statement concatenates the character fields <c1> to <cn> and assigns the result to <c>. The system ignores spaces at the end of the individual source strings.
The addition SEPARATED BY <s> allows you to specify a character field <s> which is placed in its defined length between the individual fields."
That means that all leading and trailing spaces will disappear except the ones in the separator string <sep>.
So it depends on the result you want as how to do the concatenation. if you want a fixed position regardless of blanks, then you must work with offset and length addition.
Kind regards,
Clemens