10-22-2008 12:36 AM
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.
10-22-2008 6:42 AM
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.
10-22-2008 1:00 AM
yes, you need to sort before loop; and after READ table gt_vbak check for sy-subrc = 0.
10-22-2008 4:43 AM
Hi,
Yes!!!
Before using binary search you should always use sort or you should take a sorted internal table.
Regards,
Pooja
10-22-2008 4:48 AM
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.
10-22-2008 4:49 AM
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.
10-22-2008 5:01 AM
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
10-22-2008 6:42 AM
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.