Application Development 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: 

determine statically if a LOOP is active over "Ztable"

former_member2492
Active Participant
0 Kudos
1,263

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?

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
265

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.
8 REPLIES 8

Sandra_Rossi
Active Contributor
266

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.

0 Kudos
265

...WHERE bname is NOT INITIAL. does it count? and more importantly is it faster than the field symbol?

265

...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...)

former_member1716
Active Contributor
265

Jonathan Blavatsk,

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

0 Kudos
265

so you think that looping using field symbol is better than one modify statement?

0 Kudos
265

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

0 Kudos
265

actually I have to modify all the rows of one column ,does modify do this faster?

0 Kudos
265
Jonathan Blavatsky,In that Case proceed with Field Symbols.Regards