‎2006 Nov 20 6:21 AM
Hello,
i have a join query and i am selecting fields from different table(one field is the material number and second is bsad-wrbtr, on which i am doing the SUM). Now i cant store material number in a variable, cause i will be getting many material numbers(against 'vbeln') and sum( bsad-wrbtr ) will be stored collectively in a variable.
Shud i be using an internal table to store both of them ? , cause i have to display all the material numbers retrieved . If yes, the how ? what will be the query like ?
My current select/join query is,
select sum( bd~wrbtr ) into l_cramt
from ( ( bsis as bs
inner join bsad as bd on bs~bukrs = bd~bukrs and
bs~belnr = bd~augbl and
bs~bldat = bd~augdt )
inner join vbrp as vb on vb~vbeln = bd~belnr )
where bs~blart = 'DZ' and bs~hkont = p_hkont.
Waiting for your replies, thank..
Shehryar Dahar
‎2006 Nov 20 6:25 AM
u have to use internal table to store the material and sum cause u have to display in the output....try to use internal table and pass on the data to it...
‎2006 Nov 20 6:39 AM
Hello,
Ramesh, please show me what the query will be ?
Palak, is it bdmatnr or vbmatnr ?
Vijay, your query is giving a dump. Says 'few fields in the INTO clause' .
Thanks,
Shehryar Dahar
‎2006 Nov 20 6:41 AM
You should extract the data into internal table containing 2 fields of Matnr and wrbrt
‎2006 Nov 20 6:50 AM
Vijay,
the internal table is showing the sum grouped by material wise. I want to display each material and the SUM.
Thanks,
Shehryar Dahar
‎2006 Nov 20 6:56 AM
I don't think u can extract the material and the sum within the same query.
One solution might be again apply sum for the all the entries in the internal table, by this u will the materials as well as its sum.
‎2006 Nov 20 7:19 AM
‎2006 Nov 20 6:28 AM
Hi,
Do this way. Use collect statement.
Define internal table which stores 2 fields
material number
wrbtr value
Now define
select bd~matnr
bd~wrbtr into <internal table>
from ( ( bsis as bs
inner join bsad as bd on bsbukrs = bdbukrs and
bsbelnr = bdaugbl and
bsbldat = bdaugdt )
inner join vbrp as vb on vbvbeln = bdbelnr )
where bsblart = 'DZ' and bshkont = p_hkont.
COLLECT <internal table>
ENDSELECT.
-
This will sum up value for each same material.
*REWARD all helpful answers
‎2006 Nov 20 6:33 AM
Use <b>group by</b> clause in the select stmt. It gives sum for the particular field
My current select/join query is,
select <b> material</b> sum( bd~wrbtr ) into l_cramt
from ( ( bsis as bs
inner join bsad as bd on bsbukrs = bdbukrs and
bsbelnr = bdaugbl and
bsbldat = bdaugdt )
inner join vbrp as vb on vbvbeln = bdbelnr )
where bsblart = 'DZ' and bshkont = p_hkont
<b>group by material.</b>
‎2006 Nov 20 7:32 AM
Hi Shehryar
You cannot select and sum the values using a single query coz you query will return multiple materials.
This should be done in two steps,
1) select your required data into the internal tables
2) Then use SUM or Collect to get the required sum for the materials and display that.
This would be a better approach,
wa_temp.
loop at itab.
wa_temp-material = itab-material.
sum.
at end of material.
wa_temp-wrbtr = itab-wrbtr.
append wa_temp into itab2.
endat.
endloop.
Note: You do not have material number in your selection. It is required if you want to display the sum for materials.
Hope this solves your problem.
Regards
Kathirvel
‎2006 Nov 20 7:52 AM
Hi,
If you want to have a list of materials and sum for each of them try this:
types: begin of t_list,
matnr like vbrp-matnr,
wrbtr like bsad-wrbtr,
end of t_list.
data: i_list type table of t_list.
...
select vbmatnr sum( bdwrbtr ) into table i_list
from ( ( bsis as bs
inner join bsad as bd on bsbukrs = bdbukrs and
bsbelnr = bdaugbl and
bsbldat = bdaugdt )
inner join vbrp as vb on vbvbeln = bdbelnr )
where bsblart = 'DZ' and bshkont = p_hkont
group by vb~matnr.
If you want to have a sum for a given material try this:
select vbmatnr sum( bdwrbtr ) into (v_matnr, v_wrbtr )
from ( ( bsis as bs
inner join bsad as bd on bsbukrs = bdbukrs and
bsbelnr = bdaugbl and
bsbldat = bdaugdt )
inner join vbrp as vb on vbvbeln = bdbelnr )
where bsblart = 'DZ' and bshkont = p_hkont
and vb~matnr = p_matnr.