2019 Feb 21 10:35 AM
Hi Team,
The below code is taking lot of time. How can i improve the performance for this code -
SELECT venum AS venum,
exidv AS exivd
INTO TABLE @DATA(it_vekp)
FROM vekp
FOR ALL ENTRIES IN @it_vepo
WHERE venum = @it_vepo-unvel.
LOOP AT it_vekp INTO DATA(wa_vekp).
UPDATE vekp SET erlkz = 'X' WHERE venum = wa_vekp-venum.
IF sy-subrc = 0.
COMMIT WORK.
ENDIF.
ENDLOOP.
Hi Badu,
Despite all the comments about your question, and by the way, they are totally right, if we look just on the performance side, using update inside a loop is not a good idea (without even mention the commit!). Try to use modify, like below, and check if performance improves.
select *
into table @data(it_vekp)
from vekp
for all entries in @it_vepo
where venum = @it_vepo-unvel.
data ls_vekp like line of it_vekp.
ls_vekp-erlkz = 'X'.
modify it_vekp from ls_vekp transporting erlkz where erlkz is initial.
modify vekp from table it_vekp.
Regards,
Rafael
2019 Feb 21 11:01 AM
Babu - this is not an answer to your question but a comment on the code you shared:
Hard updates to SAP-tables like you do here are not a good idea and shouldn't be done as you run at least the risks of a) creating inconsistencies and b) circumvent tracking of table changes.
2019 Feb 21 11:34 AM
2019 Feb 21 12:08 PM
Also, if you corrupt your database somehow, then SAP will charge you $$$$ to fix, and you may well be violating license conditions.
2019 Feb 21 2:13 PM
Hi Badu,
Despite all the comments about your question, and by the way, they are totally right, if we look just on the performance side, using update inside a loop is not a good idea (without even mention the commit!). Try to use modify, like below, and check if performance improves.
select *
into table @data(it_vekp)
from vekp
for all entries in @it_vepo
where venum = @it_vepo-unvel.
data ls_vekp like line of it_vekp.
ls_vekp-erlkz = 'X'.
modify it_vekp from ls_vekp transporting erlkz where erlkz is initial.
modify vekp from table it_vekp.
Regards,
Rafael
2019 Feb 21 6:28 PM
Your solution doesn't compile because the components of IT_VEKP (3 columns as far as I can see) don't correspond to (all) the columns of VEKP.
To use MODIFY vekp, you must use an internal table with all the columns of VEKP.
2019 Feb 21 8:51 PM
2019 Feb 21 6:30 PM
Please provide the execution plan (SQL EXPLAIN) of both the SELECT and UPDATE.
2019 Apr 03 10:12 AM
2019 Apr 05 1:37 PM
You can also restrict the data set adding erlkz = space.
Less data to process.
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |