Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

need to add (+) all values

Former Member
0 Kudos

I need to sum all values if groupname = setleaf-setname.

I need sum values p1,p2,p3,p4,p5,p6,p7.

Can any one help me how to resolve this one?

6 REPLIES 6

Former Member
0 Kudos

hi Priya,

Use <b>SUM</b> Statement

if groupname = setleaf-setname.

loop at itab. " here itab contains the parameters to be summed up

SUM

endloop.

endif.

Regards,

Santosh

Former Member
0 Kudos

Look at SUM, COLLECT keywords.

Without knowing your itab structure or your code, it will be difficult to tell what to use.

0 Kudos

DATA SEPARATOR(1) VALUE '~'.

select * from aufk into corresponding fields of table it_aufk

where aufnr in s_aufnr and

( auart = '5200' or auart = '5500' or auart = '5700'

or auart = '8500' or auart = '8700' ) .

LOOP AT IT_AUFK.

LOOP AT IT_GROUP.

CONCATENATE 'OR' IT_AUFK-AUFNR INTO OBJNR.

MOVE IT_GROUP-GROUPNAME TO COST.

SHIFT COST BY 3 PLACES LEFT.

SELECT * FROM COSS INTO TABLE IT_COSS WHERE

OBJNR = OBJNR AND

GJAHR = P_GJAHR AND

VERSN = P1_VERSN

AND

WRTTP = '01'.

LOOP AT IT_COSS.

select * from setleaf appending corresponding fields of table

it_setleaf

where setclass = '0102' and

subclass = 'CASA' and

setname = COST and

valfrom = it_coss-kstar.

if sy-subrc = 0.

LOOP AT IT_SETLEAF.

IF IT_SETLEAF-SETNAME = COST AND IT_SETLEAF-VALFROM = IT_COSS-KSTAR.

IT_M-M1 = IT_COSS-WKG001.

IT_M-M2 = IT_COSS-WKG002.

IT_M-M3 = IT_COSS-WKG003.

IT_M-M4 = IT_COSS-WKG004.

IT_M-M5 = IT_COSS-WKG005.

IT_M-M6 = IT_COSS-WKG006.

IT_M-M7 = IT_COSS-WKG007.

IT_M-M8 = IT_COSS-WKG008.

IT_M-M9 = IT_COSS-WKG009.

IT_M-M10 = IT_COSS-WKG010.

IT_M-M11 = IT_COSS-WKG011.

IT_M-M12 = IT_COSS-WKG012.

COLLECT IT_M.

APPEND IT_M.

WRITE : / IT_M, IT_COSS-KSTAR.

ENDIF.

ENDLOOP.

endif.

endloop.

ENDLOOP.

ENDLOOP.

this is my code if setname = cost .

i need to sum m1..m12 for example.

setname = 600100 and valfrom = 600dba,600dev.

i need to sum 600 dba with 600 dev.

can any one help me in this issue?

0 Kudos

hi Priya

Try Using <b>SUM IT_M.</b> instead of COLLECT IT_M.

Reward if it helps

Regards,

Santosh

0 Kudos

Priya,

Collect / SUM won't be working in this case.

Hence you need to add programitically


LOOP AT IT_SETLEAF.
IF IT_SETLEAF-SETNAME = COST AND IT_SETLEAF-VALFROM = IT_COSS-KSTAR

IT_M-M1 = IT_M-M1 + IT_COSS-WKG001.
-----
-------
at last.
APPEND IT_M.
WRITE : / IT_M, IT_COSS-KSTAR.
endat

endloop.

0 Kudos

> DATA SEPARATOR(1) VALUE '~'.

>

>

>

>

> select * from aufk into corresponding fields of

> f table it_aufk

> where aufnr in s_aufnr and

> ( auart = '5200' or auart = '5500' or

> uart = '5500' or auart = '5700'

> or auart = '8500' or auart = '8700'

> or auart = '8700' ) .

> LOOP AT IT_AUFK.

>

>

>

> LOOP AT IT_GROUP.

>

>

>

> CONCATENATE 'OR' IT_AUFK-AUFNR INTO OBJNR.

> MOVE IT_GROUP-GROUPNAME TO COST.

> SHIFT COST BY 3 PLACES LEFT.

>

> SELECT * FROM COSS INTO TABLE IT_COSS WHERE

> OBJNR = OBJNR AND

> GJAHR = P_GJAHR AND

> VERSN = P1_VERSN

> AND

> WRTTP = '01'.

> LOOP AT IT_COSS.

>

> select * from setleaf appending corresponding

> ng fields of table

> it_setleaf

> where setclass = '0102' and

> subclass = 'CASA' and

> setname = COST and

> valfrom = it_coss-kstar.

> if sy-subrc = 0.

>

>

> LOOP AT IT_SETLEAF.

> IF IT_SETLEAF-SETNAME = COST AND IT_SETLEAF-VALFROM =

> IT_COSS-KSTAR.

>

> IT_M-M1 = IT_COSS-WKG001.

> IT_M-M2 = IT_COSS-WKG002.

> IT_M-M3 = IT_COSS-WKG003.

> IT_M-M4 = IT_COSS-WKG004.

> IT_M-M5 = IT_COSS-WKG005.

> IT_M-M6 = IT_COSS-WKG006.

> IT_M-M7 = IT_COSS-WKG007.

> IT_M-M8 = IT_COSS-WKG008.

> IT_M-M9 = IT_COSS-WKG009.

> IT_M-M10 = IT_COSS-WKG010.

> IT_M-M11 = IT_COSS-WKG011.

> IT_M-M12 = IT_COSS-WKG012.

> COLLECT IT_M.

<i><b>> APPEND IT_M.<--- remove this. COLLECT takes care of appending after summing</b></i>

> WRITE : / IT_M, IT_COSS-KSTAR.

> ENDIF.

> ENDLOOP.

> endif.

> endloop.

> ENDLOOP.

> ENDLOOP.

> this is my code if setname = cost .

> i need to sum m1..m12 for example.

> setname = 600100 and valfrom = 600dba,600dev.

> i need to sum 600 dba with 600 dev.

> can any one help me in this issue?