2013 Dec 03 7:31 PM
I know from reading the help that a string assignment via the move statement or = operator will do a lazy copy operation, i.e. both resulting variables will point to the same memory space until a change is made via one of the two variables. Only then is an actual copy of the memory made.
My question is: does this still apply when assigning a portion of a string to another variable like so:
data lv_string1 type string.
data lv_string2 type string.
lv_string1 = 'This is a string'.
lv_string2 = lv_string1+5.
or does the previous code immediately make a copy of the memory starting at an offset of 5 in lv_string1 and assign the copy to lv_string2?
Thanks,
-Chris
2013 Dec 04 9:48 AM
Lazy copy is not applied when a substring is assigned.
ABAP Debugger has memory inspector tool, that can be used to verify it.
2013 Dec 03 7:40 PM
I'm pretty sure it is immediate. I suppose that someone could prove me wrong however.
To clarify, I'd always assumed that it was immediate. What would be the worry if it weren't? I'm quite interested in your concern...
Neal
2013 Dec 03 9:18 PM
My concern is performance. If it is doing a lazy copy, then I can assign lv_string2 = lv_string1+5 with no concern about performance impact as long as I never alter the contents of lv_string2. However, if the copy is immediate in this case, then there can be a performance impact for very large strings.
I also suspect that it is immediate, because the syntax will not allow you to pass lv_string1+5 as a parameter, at least not by reference. It also does not allow you to assign lv_string1+5 to a field-symbol. Both of these facts lead me to suspect that ABAP can't handle a reference to anything but the beginning of a string. The documenation does not seem to address this scenario, though.
Thanks for your input.
-Chris
2013 Dec 03 9:53 PM
When I have done large numbers of string manipulations, I have noticed more impact than I was expecting, so I would have to agree with you.
Neal
2013 Dec 04 5:06 AM
Hi,
If kernel has task to do then there would no any other best option available.
Avirat
2013 Dec 04 9:48 AM
Lazy copy is not applied when a substring is assigned.
ABAP Debugger has memory inspector tool, that can be used to verify it.
2014 May 12 9:49 PM
Over a year later, I finally had the chace to follow up on this. I learned how to use the memory inspector and can see that, yes, assignment of a substring makes an immediate copy, even though assignment of the full string does a lazy copy.
The memory inspector is a very valuable tool. Thanks, Manish!