02-12-2008 9:36 AM
hiiiiiiiiiiiiiiiiiiiiii
pls tell me how to write the syntex for counter for particular field to sum of all the enteries of that paticular field.
after that synatx for average for that total sum corresponding no. of entries.
02-12-2008 9:40 AM
02-12-2008 9:40 AM
02-12-2008 10:02 AM
02-12-2008 10:10 AM
02-12-2008 9:40 AM
data : count type i ,
value type ANSAL_15,
average type ANSAL_15.
Loop at itab.
value = value + itab- value.
endloop.
describe table itab lines count.
if not count is initial.
average = value / count.
endif.
02-12-2008 9:41 AM
U can use Control breas to calculate sums
sample
SORT GT_MVMT BY BWART.
LOOP AT GT_MVMT INTO GS_MVMT.
AT new BWART.
SUM.
case gs_mvmt-bwart.
when '101'.
GV_101_QTY = GS_MVMT-LSMNG.
when '102'.
GV_102_QTY = GS_MVMT-LSMNG.
endcase.
endat.
clear gs_mvmt.
ENDLOOP.
Reward if useful
02-12-2008 9:41 AM
data: sum type i.
data: var type i.
data: avg type i.
loop at tab
sum = sum + field.
var = var + 1.
endloop.
avg = sum / var.
02-12-2008 9:46 AM
Hi,
If that field is in itab.....
DATA : BEGIN OF itab OCCURS 0,
fld1 TYPE char5,
fld2 TYPE p,
END OF itab.
DATA count.
itab-fld1 = 'hi'.
itab-fld2 = 10.
APPEND itab.
itab-fld1 = 'hello'.
itab-fld2 = 15.
APPEND itab.
itab-fld1 = 'hi'.
itab-fld2 = 10.
APPEND itab.
itab-fld1 = 'hello'.
itab-fld2 = 15.
APPEND itab.
DESCRIBE TABLE itab LINES count.
WRITE : / 'No of items = ',count.
LOOP AT itab.
AT LAST.
SUM.
WRITE : / 'sum = ',itab-fld2.
ENDAT.
ENDLOOP.
Cheers,
jose.
02-12-2008 9:57 AM
hiiiiiiiiiiiiiii
but in that coding there is no any internal table
then how i write sntax for counter for that particular field
thanks
02-12-2008 9:58 AM
02-12-2008 10:07 AM
hiiiiiiiii
in follwing code i want to calculate the average tonnage.
*Zproduction
REPORT ztotalprod1 LINE-SIZE 350 no standard page heading.
tables: zprdnrec,
zhrslitdet,
zcoilst,
zhrordlink,
zppsotr,
kna1,
zhrcdet,
MARA.
selection-screen begin of block block1 with frame title text-001 .
selection-screen skip 1.
select-options date for zprdnrec-dates.
select-options shft for zprdnrec-shift.
select-options wrkc for zprdnrec-wcenter.
selection-screen skip 4.
parameters: coilwise radiobutton group g1 default 'X'.
parameters: wrkcwise radiobutton group g1.
parameters: sftwise radiobutton group g1.
selection-screen end of block block1.
data: cno like zprdnrec-coilno , slid like zprdnrec-slitid,
scr like vbrp-fkimg,scr1 like vbrp-fkimg,scr2 like vbrp-fkimg,
rol like zprdnrec-ROLFINISH,
vendor like qals-SELLIFNR,
matnr like qals-SELmatnr,
name1 like lfa1-name1.
data : rem like zprdnrec-remarks,
field(15).
data: v_ordno(10) TYPE n.
data: a type p decimals 3,
******added on 03.05.04 by Jagmeet Singh ON Request of Mr Sanjay Gupta
for average width and average thickness.
*****************************************************************
bt type p decimals 3,
b2 like bseg-wrbtr,
b3 like bseg-wrbtr,
b4 like bseg-wrbtr,
G2 LIKE BSEG-WRBTR,
G3 LIKE BSEG-WRBTR,
G4 LIKE BSEG-WRBTR,
******************************************************
a2 like bseg-wrbtr, " for width
a3 like bseg-wrbtr, " for input thickness
a4 like bseg-wrbtr, " for output thickness
a5 like bseg-wrbtr, " for width in line sel
a6 like bseg-wrbtr, " for input thickness in line sel
a7 like bseg-wrbtr, " for output thickness in line sel
b like zprdnrec-wcenter,e like
zprdnrec-dates , c like zprdnrec-shift , d like zwrkcenter-details,
f like zwrkcenter-details,
s(16) type p decimals 3, " LIKE vbrp-fkimg
s2(16) type p decimals 3, " LIKE vbrp-fkimg " for total wtd ithick
s3(16) type p decimals 3, " LIKE vbrp-fkimg " for total wtd fthick
s4(16) type p decimals 3. " LIKE vbrp-fkimg " for % reduction
write: ' TOTAL PRODUCTION'.
write: /.
if coilwise ='X'.
format color 1.
uline.
write: / 'WORKCENTER NAME ',' DATE',
' SHIFT', 'COILNO', ' SLITID',67 ' TONNAGE', 83 'Width',90
'Thick',97 'Finish ' , 'Remarks',150 'ROLFINISH',172 'Wtd Width',
189 'Wtd Thick' ,204 'Wtd fthick', 225 'SOURCE' , 265 'MATNR'.
added average thickness & average width
by Narinder Paul Gogna on 9.jan.2004
as asked by mr Saxena
uline.
write: / .
select coilno slitid tonnage wcenter shift dates remarks ROLFINISH into
(cno,slid,a,b,c,e,rem,rol ) from zprdnrec
where
dates in date and shift in shft and wcenter in wrkc order by wcenter
ascending shift ascending .
**************change by manpreet*******************
*counter
********************end manpreet***********************
s = s + a.
bt = bt + a.
select single * from zhrslitdet where coilno = cno and slitid = slid.
select details into d from zwrkcenter where wcenter = b.
*********change by vijay date 20.06.2007*********
select SELLIFNR into (vendor) from qals
where charg = cno.
select name1 from LFA1 into (name1)
where lifnr = vendor.
*********************end********************************
*********change by vijay date 12.10.2007******************
SELECT ordno linenum INTO (zhrordlink-ordno, zhrordlink-linenum)
FROM zhrordlink WHERE coilno = zhrslitdet-coilno
AND slitid = zhrslitdet-slitid.
v_ordno = zhrordlink-ordno.
CLEAR zppsotr.
SELECT SINGLE kunnr matnr INTO (zppsotr-kunnr, zppsotr-matnr)
FROM zppsotr WHERE vbeln EQ v_ordno
AND posnr EQ zhrordlink-linenum.
endselect.
endselect.
endselect.
***************end.******************************
compute weighted average & weighted thickness etc.
a2 = a * zhrslitdet-width.
b2 = b2 + a2.
a3 = a * zhrslitdet-hrthick.
b3 = b3 + a3.
a4 = a * zhrslitdet-fthick.
b4 = b4 + a4.
*****
format color 2.
write: / d,e,' ',c,' ',cno, slid, 65 a , 83 zhrslitdet-width,
90 zhrslitdet-hrthick, 97 zhrslitdet-fthick , rem ,
rol,168 a2,185 a3,
200 a4,225 NAME1, 260 ZPPSOTR-MATNR.
" azhrslitdet-width, azhrslitdet-hrthick , a*zhrslitdet-fthick .
scr1 = '7.85'.
clear scr.
if b = '03'.
scr = zhrslitdet-width * zhrslitdet-hrthick * 6200 * scr1 * ( 1 /
1000000000 ).
scr2 = scr2 + scr.
write :150 scr.
endif.
clear scr.
if b = '04'.
scr = zhrslitdet-width * zhrslitdet-hrthick * 9050 * scr1 * ( 1 /
1000000000 ).
scr2 = scr2 + scr.
write :150 scr.
endif.
endselect.
endselect.
format color 1.
write: /1 'Total Tonnage =',16 s.
write: 55 'Average weight = '.
write: /150 scr2.
***********************************changed on 03.05.04
G2 = B2 / bt.
G3 = B3 / bt.
G4 = B4 / bt.
write 😕 'Average width = ',G2 , 'Average Input Thickness = ',G3 ,
'Average output thickness = ', G4 .
clear : scr,scr2.
elseif wrkcwise = 'X'.
format color 6.
write: / 'WORKCENTER NAME',' TONNAGE '.
write: / .
select sum( tonnage ) wcenter into (a,b) from zprdnrec
where dates in date and shift in shft and wcenter in wrkc group by
wcenter .
GROUP BY WCENTER SHIFT dates tonnage.
s = s + a.
select details into d from zwrkcenter where wcenter = b.
format color 2.
write: / d,a .
endselect.
endselect.
format color 1.
write: /'Total Tonnage =' ,
16 s.
else.
format color 6.
write: / 'WORKCENTER NAME ',' SHIFT',' TONNAGE '.
write: / .
select sum( tonnage ) wcenter shift into (a,b,c) from zprdnrec
where dates in date and shift in shft and wcenter in wrkc group by
wcenter shift .
GROUP BY WCENTER SHIFT dates tonnage.
s = s + a.
select details into d from zwrkcenter where wcenter = b.
format color 2.
write: / d,c,' ',a .
endselect.
endselect.
format color 1.
write: /8 'Total Tonnage =' ,
24 s.
endif.
********************sachin sachdeva 19/11/03*************************
change by vijay tcode ztp date 24.09.2006
*at line-selection.
if sy-lsind = 1.
at line-selection.
sy-lsind = 2.
end
*addition by mandeep to link tcode YQHIST tcode
get cursor field field.
if field = 'CNO'.
submit ZQUALI with coilno = sy-lisel+51(10)
with slitid = sy-lisel+62(1)
and return.
exit.
endif.
*end
clear:s ,a,b.
read current line field value d into f.
select single wcenter into b from zwrkcenter where details = f.
format color 1.
uline.
write: / 'WORKCENTER NAME ',' DATE',
' SHIFT', 'COILNO', ' SLITID',65 ' TONNAGE', 70 'Width',90
'Thick',97 'Finish ' , 'Remarks',150 'ROLFINIS',172 'Wtd Width',
189 'Wtd Thick' ,204 'Wtd fthick'.
uline.
write: / .
select coilno slitid tonnage wcenter shift dates remarks ROLFINISH into
(cno,slid,a,b,c,e,rem,rol) from zprdnrec where
dates in date and shift in shft and wcenter = b order by wcenter
ascending shift ascending .
s = s + a.
select single * from zhrslitdet where coilno = cno and slitid = slid.
select details into d from zwrkcenter where wcenter = b.
compute weighted average & weighted thickness etc.
a5 = a * zhrslitdet-width.
a6 = a * zhrslitdet-hrthick.
a7 = a * zhrslitdet-fthick.
s2 = s2 + a6. " add wtd input thickness.
s3 = s3 + a7. " add wtd output thickness.
*****
format color 2.
write: / d,e,' ',c,' ',cno, slid, 65 a , 80 zhrslitdet-width,
90 zhrslitdet-hrthick, 97 zhrslitdet-fthick , rem ,rol,168 a5, 185
a6
, 200 a7.
azhrslitdet-width, azhrslitdet-hrthick , a*zhrslitdet-fthick .
scr1 = '7.85'.
clear scr.
if b = '03'.
scr = zhrslitdet-width * zhrslitdet-hrthick * 6200 * scr1 * ( 1 /
1000000000 ).
scr2 = scr2 + scr.
write :150 scr.
endif.
clear scr.
if b = '04'.
scr = zhrslitdet-width * zhrslitdet-hrthick * 9050 * scr1 * ( 1 /
1000000000 ).
scr2 = scr2 + scr.
write :150 scr.
endif.
endselect.
endselect.
format color 1.
write: / ' ',
******************************************man
'Total Tonnage =',67 s .
write: /.
write: /150 scr2.
write: / 'Total weighted input thickness ' , 165 s2 .
write: / 'Total weighted output / final thickness ' , 182 s3 .
*addition
if s2 is not initial.
s4 = ( ( s2 - s3 ) / s2 ) * 100 .
endif.
write: / .
write: /150 'Total % reduction = ',s4 .
clear : s2,s3,s4.
clear : scr,scr2.
endif.
endif.
02-12-2008 10:03 AM
Hi,
To Get the Numbe of items to get average you can use below statement :
Describe table itab lines sy-tfill.
To get the sum of particular column.
data : lv_amount like bsis-dmbtr value 0.
Loop at itab.
lv_amount = lv_amount + itab-fieldname.
endloop.
Thanks,
Sriram POnna.
endloop.