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

Logic taking too much time to execute

Former Member
0 Likes
939

Dear Friends,

My i_bkpf internal table has approx. 3 lakh records another table i_del has 2 lakh records. I have to delete these 2 lakh records of i_del from i_bkpf.

I'd written the following piece of code for the same but it takes hell lot of time and ultimately I encounter a timeout.

Kindly have a look at the following code and suggest how can I improve it.

**********************

sort i_bkpf by belnr.

sort i_del by belnr.

loop at i_del.

DELETE I_BKPF WHERE BELNR = I_DEL-BELNR AND

GJAHR = I_DEL-GJAHR AND

BUKRS = I_DEL-BUKRS.

ENDLOOP.

**********************

Regards,

Alok.

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
917


sort i_del by belnr gjahr bukrs.
loop at i_bkpf.
v_tabix = sy-tabix.
read table i_del with key belnr = i_bkpf-belnr
                                    gjahr = i_bkpf-gjahr
                                    bukrs = i_bkpf-bukrs
                                    binary search.
if sy-subrc eq 0.
   delete i_bkpf index v_tabix.
endif.
endloop.

aRs

Dear Friends,

My i_bkpf internal table has approx. 3 lakh records another table i_del has 2 lakh records. I have to delete these 2 lakh records of i_del from i_bkpf.

I'd written the following piece of code for the same but it takes hell lot of time and ultimately I encounter a timeout.

Kindly have a look at the following code and suggest how can I improve it.

**********************

sort i_bkpf by belnr.

sort i_del by belnr.

loop at i_del.

DELETE I_BKPF WHERE BELNR = I_DEL-BELNR AND

GJAHR = I_DEL-GJAHR AND

BUKRS = I_DEL-BUKRS.

ENDLOOP.

**********************

Regards,

Alok.

6 REPLIES 6
Read only

Former Member
0 Likes
917

hi Alok,

Try to Include all the primary keys in the where condition and sort by these fields.

REgards,

Santosh

Read only

Former Member
0 Likes
917

hi,

try like this,

sort i_bkpf by belnr.

sort i_del by belnr.

loop at i_bkpf.

DELETE adjacent duplicates of I_BKPF WHERE BELNR = I_DEL-BELNR AND GJAHR = I_DEL-GJAHR AND BUKRS = I_DEL-BUKRS.

ENDLOOP.

if helpful reward some points.

with regards,

suresh.

Read only

Former Member
0 Likes
917

Hi

do like this

sort i_bkpf by bukrs belnr gjahr.

sort i_del by bukrs belnr gjahr.

loop at i_del.

read table I_BKPF With key BUKRS = I_DEL-BUKRS

BELNR = I_DEL-BELNR

GJAHR = I_DEL-GJAHR

binary search.

if sy-subrc = 0.

delete i_bkpf index sy-tabix.

endif..

ENDLOOP.

<b>Reward points for useful Answers</b>

Regards

Anji

Read only

former_member194669
Active Contributor
0 Likes
918


sort i_del by belnr gjahr bukrs.
loop at i_bkpf.
v_tabix = sy-tabix.
read table i_del with key belnr = i_bkpf-belnr
                                    gjahr = i_bkpf-gjahr
                                    bukrs = i_bkpf-bukrs
                                    binary search.
if sy-subrc eq 0.
   delete i_bkpf index v_tabix.
endif.
endloop.

aRs

Read only

Former Member
0 Likes
917

<b>sort i_bkpf by belnr GJAHR BUKRS.</b>

sort i_del by belnr.

loop at i_del.

DELETE I_BKPF WHERE BELNR = I_DEL-BELNR AND

GJAHR = I_DEL-GJAHR AND

BUKRS = I_DEL-BUKRS.

ENDLOOP.

Read only

Former Member
0 Likes
917

hi

I think u can do like this. :

loop at i_del.

if i_del is not initial.

loop at i_bkpf where <conditions>

if sy-subrc = 0.

delete i_bkpf index sy-tabix.

endif.

endloop.

endif.

endloop.

hope it helps ....