‎2006 Jul 24 6:22 AM
hi experts
i have got stuck in performance tuning osf one query
how can i tune this query by breaking it into two parts
SELECT a~vguid
b~vbeln
b~posnr
b~charg
b~bwtar
c~kunnr
b~kwmeng
INTO TABLE i_sales
FROM vlccuorder AS a
INNER JOIN vbap AS b
ON ( avbeln EQ bvbeln
AND aposnr EQ bposnr )
INNER JOIN vbak AS c
ON ( bvbeln EQ cvbeln )
JOIN lqua AS d
ON ( bcharg EQ dcharg )
WHERE b~vbeln IN s_vbeln
AND c~kunnr IN s_kunnr
AND d~werks IN s_werks
AND c~auart EQ 'ZOR'
AND b~abgru EQ space.
wherin primary key fields of tables are:
a)vlccuorder is vguid
b)vbap is vbeln and posnr
c)vbak is vbeln
thanks in advance.
‎2006 Jul 24 6:26 AM
Hi Kunal ,
first get the SO from VBAK+VBAP and then for <b>vlccuorder</b>.
Regards
Prabhu
‎2006 Jul 24 7:59 AM
it will be helpful if u send me some doc. related that can be helpful.
please also tell me how to use index in tuning a query.
thanks
‎2006 Jul 24 8:06 AM
Before advising on how to tune it would be helpful to know how many rows will there usually be in the result table?
Will the s_ variables have many entries in them or just a few?
Also how big is the table 'a'? i.e. how many rows in vlccuorder?
‎2006 Jul 24 8:17 AM
result table, u mean final result internal table will
be having few entries.
table vlccuorder is having around 200 rows
vbap and vbpa tables are having entries around 800 each
thanks
‎2006 Jul 24 8:44 AM
with such low numbers I don't think the sql needs breaking up. I think it's just innefficient because the joins to LQUA is not specified at a low enough level AND does not specify the material, only the batch(CHARG) so hitting this table will be very inefficient. I also think it should be restructured to work down the hierarchy from top to bottom.
This might be better:
SELECT vlccvguid vbapvbeln vbapposnr vbapcharg
vbapbwtar vbakkunnr vbap~kwmeng
INTO corresponding fields of TABLE i_sales
FROM
vlccuorder AS vlcc
INNER JOIN vbap
ON ( vlccvbeln EQ vbapvbeln
AND vlccposnr EQ vbapposnr )
INNER JOIN vbak
ON ( vbapvbeln EQ vbakvbeln )
JOIN lqua
ON ( vbapcharg EQ lquacharg )
WHERE vbap~vbeln IN s_vbeln
AND vbak~kunnr IN s_kunnr
AND lqua~werks IN s_werks
AND vbak~auart EQ 'ZOR'
AND vbap~abgru EQ space.
FROM vbak
JOIN vbap
ON ( vbapvbeln EQ vbakvbeln )
join vlccuorder as vlcc
ON ( vlccvbeln EQ vbapvbeln
AND vlccposnr EQ vbapposnr )
JOIN lqua
ON ( lquamatnr eq vbapmatnr
and lquawerks eq vbapwerks
and lquacharg EQ vbapcharg )
WHERE vbak~vbeln IN s_vbeln
AND vbak~kunnr IN s_kunnr
AND vbak~auart EQ 'ZOR'
AND vbap~abgru EQ space.
AND vbap~werks IN s_werks.
‎2006 Jul 24 6:29 AM
Hi Kunal,
Check whether you have used all the KEY FIELDS for Where Condition you hav eused in your Select Query.
Cheers,
Prashanth
‎2006 Jul 24 6:37 AM
the query fields in where condition are covered,
idea is i want to break two tables- vbap and vbak
by using "for all entries in" or may be "using corresponding fields of"
thanks if u can guide
‎2006 Jul 24 8:09 AM
Hi,
Use The following logic;
Select all the VBELN's and details on join of VBAK and VBAP into table itab. Do For All Entries on that ITAB to get the vguiid from vlccuorder into another table. Move all the entries of both the table to a final table.
Hope this Helps
Anirban
‎2006 Jul 24 8:14 AM
<b>just copy and paste ...</b>
data: begin of i_sales occurs 0,
vbeln like vbap-vbeln,
posnr like vbap-posnr,
charg like vbap-charg,
bwtar like vbap-bwtar,
kunnr like vbak-kunnr,
kwmeng like vbap-kwmeng,
vguid like vlccuorder-vguid,
end of i_sales.
data:begin of itab occurs 0,
vbeln type vbeln,
vguid type vguid,
end of itab.
select b~vbeln
b~posnr
b~charg
b~bwtar
c~kunnr
b~kwmeng
INTO TABLE i_sales
FROM vbap AS b
INNER JOIN vbak AS c
ON b~vbeln EQ c~vbeln
inner JOIN lqua AS d
ON b~charg = d~charg
WHERE b~vbeln IN s_vbeln
AND c~kunnr IN s_kunnr
AND d~werks IN s_werks
AND c~auart EQ 'ZOR'
AND b~abgru EQ space.
if not i_sales[] is initial.
select vbeln vguid into table itab from vlccuorder
for all entries in i_sales
where vbeln = i_sales-vbeln.
endif.
sort itab .
loop at i_sales .
read table itab binary search with key vbeln = i_sales-vbeln
i_sales-vguid = itab-vguid.
modify i_sales.
endloop.