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

Lazy Copy in String Assignment/Move

Former Member
0 Likes
1,601

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,288

Lazy copy is not applied when a substring is assigned.

ABAP Debugger has memory inspector tool, that can be used to verify it.

6 REPLIES 6
Read only

Former Member
0 Likes
1,288

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

Read only

0 Likes
1,288

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

Read only

0 Likes
1,288

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

Read only

0 Likes
1,288

Hi,

If kernel has task to do then there would no any other best option available.

Avirat

Read only

Former Member
0 Likes
1,289

Lazy copy is not applied when a substring is assigned.

ABAP Debugger has memory inspector tool, that can be used to verify it.

Read only

0 Likes
1,288

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!