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: 

Please validate me

Former Member
0 Kudos

My below read stmt is to working if I use BINARY SEARCH in READ STMT .

Do I need to use

SORT table gt_vbak BY vbeln kunn2 ?

just before

LOOP at gt_vbpa INTO wa_vbpa.

to get use of Binary search ?

My code :

BEGIN OF t_vbak,

vbeln TYPE vbeln,

vkorg TYPE vkorg,

bstnk TYPE bstnk,

kunnr TYPE kunnr,

j_3adepm TYPE j_3adepm,

zzactcnt TYPE zadi_v_cr535_actual_cnt,

zzstatus TYPE zadi_v_cr535_status,

*For logic 4 -S

j_3astcu TYPE j_3astcu,

name2 TYPE NAME2_GP,

*For logic 4 -E

kunn2 TYPE kunn2,

count TYPE i,

END OF t_vbak,

-


BEGIN OF t_vbpa,

vbeln TYPE vbeln,

kunnr TYPE kunnr,

parvw TYPE parvw,

*code add- start -20081020

name2 TYPE NAME2_GP,

J_3ASTCU TYPE J_3ASTCU,

*code add- End -20081020

END OF t_vbpa.

I have delcared below itabs and workareas using above types

*Bring j_3ASTCU NAME2 fields into gt_vbpa from gt_vbak

LOOP at gt_vbpa INTO wa_vbpa.

READ table gt_vbak INTO wa_vbak
                     WITH KEY vbeln = wa_vbpa-vbeln
                              kunn2 = wa_vbpa-kunnr
*BINARY SEARCH

.

wa_vbpa-j_3astcu = wa_vbak-j_3astcu.

wa_vbpa-name2 = wa_vbak-name2.

MODIFY gt_vbpa FROM wa_vbpa

TRANSPORTING j_3ASTCU NAME2

where vbeln = wa_vbpa-vbeln

AND kunnr = wa_vbpa-kunnr

AND parvw = wa_vbpa-parvw.

ENDLOOP. " LOOP at gt_vbpa INTO wa_vbpa

THANKS IN ADV.

1 ACCEPTED SOLUTION

rainer_hbenthal
Active Contributor
0 Kudos

The performance is much better if you use assigning clause instead of into, this is much faster and on the other hand you dont need to use the modify statement.

And if your inner internal table is only read by the read statement you should use a hased table instead of a sorted table. This will speed up your loop dramatically, and you do not need to sort the inner table.

6 REPLIES 6

Former Member
0 Kudos

yes, you need to sort before loop; and after READ table gt_vbak check for sy-subrc = 0.

Former Member
0 Kudos

Hi,

Yes!!!

Before using binary search you should always use sort or you should take a sorted internal table.

Regards,

Pooja

Former Member
0 Kudos

Hello,

When ever you are using BINARY SEARCH you sorting should be based on the conditions which u r giving on the read statement.

sort gt_vbak by vbeln kunn2.

loop at .........

READ table gt_vbak INTO wa_vbak

WITH KEY vbeln = wa_vbpa-vbeln

kunn2 = wa_vbpa-kunnr

binary search.

if sy-subrc eq 0.

u r logic....................

endif.

endloop.

Former Member
0 Kudos

Re: Please validate me

Posted: Oct 22, 2008 5:48 AM in response to: sam kumar Edit E-mail this message Reply

Hello,

When ever you are using BINARY SEARCH you sorting should be based on the conditions which u r giving on the read statement.

sort gt_vbak by vbeln kunnr.

loop at .........

READ table gt_vbak INTO wa_vbak

WITH KEY vbeln = wa_vbpa-vbeln

kunn2 = wa_vbpa-kunnr

binary search.

if sy-subrc eq 0.

u r logic....................

endif.

endloop.

Former Member
0 Kudos

Hi,

Yes you have to sort the table begore you go for Binary search for that table in read statement.

Dont forget that the order in which you sort your internal table should be same as Key which you are using in Read statement.

i.e. if you are sorting your internal table

SORT t_vbak by vbeln kunnr

Then you can use binary search for theses read statements.

LOOP at t_vbpa.

1) Read table t_vbpa with key vbeln = t_vbpa-vbeln

kunnr = t_vbpa-kunnr

Binary search.

2)Read table t_vbpa with key vbeln = t_vbpa-vbeln

Binary search.

Endloop.

But you cant use Binary search if the read statement is like this

1) Read table t_vbpa with key kunnr = t_vbpa-kunnr

vbeln = t_vbpa-vbeln

Binary search.

2)Read table t_vbpa with key Kunnr = t_vbpa-kunnr

Binary search.

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

Regards,

Syed

rainer_hbenthal
Active Contributor
0 Kudos

The performance is much better if you use assigning clause instead of into, this is much faster and on the other hand you dont need to use the modify statement.

And if your inner internal table is only read by the read statement you should use a hased table instead of a sorted table. This will speed up your loop dramatically, and you do not need to sort the inner table.