10-07-2019 3:40 PM
I am trying to avoid loop to update a table.
loop at lt_ztable assigning <lf_zme_prepa_usr> .
<lf_zme_prepa_usr>-bname = ls_record-new_username.
endloop.
*how I used to modify the internal table
ls_ztable-bname = ls_record-new_username.
modify lt_ztable from ls_ztable transporting bname .
When I run the code inspector:
In the table "LT_Ztable" a row was to be changed, deleted or inserted. It is not possible to determine statically if a LOOP is active over "LT_Ztable"
Is it okay to modify an internal table like this and more importantly is it more performant than the field symbol?
10-07-2019 3:48 PM
The following line must be inside a LOOP AT or it will raise a runtime error, because it means that it updates the line of the current iteration (inside LOOP AT lt_ztable):
modify lt_ztable from ls_ztable transporting bname .
What you probably want to do is to modify several lines (outside any loop at - Adding WHERE makes MODIFY behave completely differently):
modify lt_ztable from ls_ztable transporting bname where bname <> ls_ztable-bname.
10-07-2019 3:48 PM
The following line must be inside a LOOP AT or it will raise a runtime error, because it means that it updates the line of the current iteration (inside LOOP AT lt_ztable):
modify lt_ztable from ls_ztable transporting bname .
What you probably want to do is to modify several lines (outside any loop at - Adding WHERE makes MODIFY behave completely differently):
modify lt_ztable from ls_ztable transporting bname where bname <> ls_ztable-bname.
10-08-2019 8:55 AM
...WHERE bname is NOT INITIAL. does it count? and more importantly is it faster than the field symbol?
10-08-2019 2:32 PM
...WHERE bname <> ls_ztable-bname works in all cases, while WHERE bname IS NOT INITIAL prevents the lines with an initial BNAME from being modified.
My rule-of-thumb is that ONE statement is performed by the kernel in one shot, while using field symbols will require more than one statement. So I guess DELETE ... WHERE ... will be faster (maybe 20% faster - A test can be done easily...)
10-08-2019 6:17 AM
As explained by Sandra Rossi, MODIFY statements behave differently with different statements. The two Statements above helps in understanding concept better.
I feel using FIELD SYMBOL is still more efficient than the MODIFY statements, since the FIELD SYMBOL uses the Memory concept for replacing the value the data gets changed in the internal table as soon as it is assigned to the field symbol.
You need to ensure that the field Symbol is unassigned after the required operation in the Loop.
Regards
10-08-2019 9:00 AM
so you think that looping using field symbol is better than one modify statement?
10-08-2019 10:07 AM
Hello Jonathan Blavatsky,
Compared to MODIFY Statements used inside a LOOP, its always better to go with Field Symbols. Here we are talking about updating all entries in the internal table.
In case you need to MODIFY only one entry from the internal table then you may use below CODE as already suggested. In this scenario we need not go for Looping itself as we just need to MODIFY only one entry and we are aware of its where condition.
modify lt_ztable from ls_ztable transporting bname where bname <> ls_ztable-bname.
Based on the scenario we deal with we have to decide what Logic shall we use.
Regards
10-08-2019 2:14 PM
actually I have to modify all the rows of one column ,does modify do this faster?
10-09-2019 5:00 AM