‎2008 May 02 10:15 AM
data : lv_zgdmeng TYPE i.
SELECT SUM( zgdmeng )
INTO lv_zgdmeng
FROM zgdpw
WHERE matnr EQ ls_prores-matnr
AND charg EQ lv_batch.
and in table zgdmeng is numc
i m getting an error saying sum can be used with numeric fields..
how to do this..
thanks and regards
‎2008 May 02 10:19 AM
hi Neha,
do this way...select entire data and loop through the data to calculate the sum of it ...
SELECT zgdmeng
INTO table it_zgdpw
FROM zgdpw
WHERE matnr EQ ls_prores-matnr
AND charg EQ lv_batch.
loop at it_zgdpw.
lv_zgdmeng = lv_zgdmeng + it_zgdpw-zgdmeng.
endloop.Regards,
Santosh
‎2008 May 02 10:20 AM
1. select all the zgdmeng in a internal table.
SELECT zgdmeng
INTO table lt_zgdmeng
FROM zgdpw
WHERE matnr EQ ls_prores-matnr
AND charg EQ lv_batch.
2. The loop the table and add all the quantities.
Loop lt_zgdmeng to lw_zgdmeng.
tot_zgdmeng = tot_zgdmeng + lw_zgdmeng.
clear: lw_zgdmeng.
endloop.
‎2008 May 02 10:27 AM
hi
i think SUM clause will work with I , F or P only not with NUMC ,so try it with the change .
reward if helpful.
‎2008 May 02 10:30 AM
Hi Neha,
just define lv_zgdmeng like ztablaename-zgdmeng
your problem will be resolved.
Gaurav
‎2008 May 02 10:33 AM
hi neha,
If you only want to use data for calculations, it is often more efficient to use the aggregate functions of the SELECT clause than to read the individual entries from the database and perform the calculations in the ABAP program.
Aggregate functions allow you to find out the number of values and find the sum, average, minimum, and maximum values. Following an aggregate expression, only its result is transferred from the database.
ex:-
DATA RESULT TYPE P DECIMALS 2.
SELECT <agg>( [DISTINCT] COL_2 )
INTO RESULT
FROM TEST.
WRITE RESULT.
The arithmetic operators AVG and SUM only work with numeric fields like f, i ,p not other than this .
*The spaces between the parentheses and the arguments of the aggregate expressions must not be left out.
thanks regard ,
sandeep patel
award point if it is helpful.