Application Development and Automation 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: 
Read only

SUM materials with all sub components

Former Member
0 Likes
1,349

Hi all ,

<REMOVED BY MODERATOR>

I have a ztable called ZMC_CRE with following values.

Ztable : ZMC_CRE

MATERIAL COMPONENT ZCOS

800000000000000003 800000000000000002 00010

800000000000000004 800000000000000007 00020

800000000000000005 800000000000000007 00020

800000000000000007 800000000000000010 00010

800000000000000008 800000000000000005 00010

800000000000000010 800000000000000003 00010

I must write a program such that :

Material, component and ZCOs must be displayed .

Output should be displayed like this .

MATERIAL COMPONENT ZCOS(SUM)

800000000000000003 800000000000000002 00010

800000000000000004 800000000000000007 00050

800000000000000005 800000000000000007 00050

800000000000000007 800000000000000010 00030

800000000000000008 800000000000000005 00060

800000000000000010 800000000000000003 00020

Logic :

We need to calculate zcos(SUM) for a material with all sub components like.

Eg for Material 800000000000000004 and component 800000000000000007 cost ZCOS is = 00020

and again for material 800000000000000007 and component 800000000000000010 cost zcos is = 00010

and again for material 800000000000000010 and component 800000000000000003 cost ZCOS is = 00010

and again for material 800000000000000003 and component 800000000000000002 cost ZCOS is = 00010

-


Hence total cost for material 800000000000000004 and component 800000000000000007 total cost is = 00050

-


The above logic is applied for all the other materials .

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 10, 2008 1:42 PM

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
1,154

If I write a program for you, I want money, not points.

Gosh, I feel grumpy today...

If I write a program for you, I want money, not points.

Gosh, I feel grumpy today...

8 REPLIES 8
Read only

ThomasZloch
Active Contributor
0 Likes
1,155

If I write a program for you, I want money, not points.

Gosh, I feel grumpy today...

Read only

matt
Active Contributor
0 Likes
1,154

Solution [here|]

Read only

0 Likes
1,154

lol, same thoughts...I feel embarrassed about the two points though.

Read only

Sm1tje
Active Contributor
0 Likes
1,154

In a way Thomas is right, we are not here for writing whole reports/programs for you. But let me help you a bit out, look at:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/79b5e890-0201-0010-7f8e-b7c207ed...

Or else find sample reports for using FM: REUSE_ALV_LIST_DISPLAY / REUSE_ALV_GRID_DISPLAY in SAP System (Do a where used on function module).

Read only

Former Member
0 Likes
1,154

I may go to hell for this


TYPES: BEGIN OF this_table,
material(20),
component(20),
zcos(5),
sum(5),
END OF this_table.

DATA: itab TYPE TABLE OF this_table WITH HEADER LINE.
DATA: curr_line TYPE sy-tabix.
DATA: sum(5).

itab-material = 800000000000000003. itab-component = 800000000000000002.
itab-zcos = 00010. APPEND itab.
itab-material = 800000000000000004. itab-component = 800000000000000007.
itab-zcos = 00020. APPEND itab.
itab-material = 800000000000000005. itab-component = 800000000000000007.
itab-zcos = 00020. APPEND itab.
itab-material = 800000000000000007. itab-component = 800000000000000010.
itab-zcos = 00010. APPEND itab.
itab-material = 800000000000000008. itab-component = 800000000000000005.
itab-zcos = 00010.  APPEND itab.
itab-material = 800000000000000010. itab-component = 800000000000000003.
itab-zcos = 00010. APPEND itab.

LOOP AT itab.
  curr_line = sy-tabix.
  CLEAR sum.
  sum = itab-zcos.
  DO.
    READ TABLE itab WITH KEY material = itab-component.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
    sum = sum + itab-zcos.
  ENDDO.
  itab-sum = sum.
  MODIFY itab INDEX curr_line TRANSPORTING sum.
ENDLOOP.

There you got the logic, you only need the select now, it took me more time to paste the data than doing the loop.

Next time try it yourself, I hope you didn't wasted 5 years of your life in a school just to still ask people for code.

There's also better ways to ask this things

Read only

matt
Active Contributor
0 Likes
1,154

>

> I may go to hell for this

>

Yes, you will.

matt

Read only

Former Member
0 Likes
1,154

hi abdullah

check this code

data :sum type i,

wa_itab like line of itab.

loop itab.

sum = itab-zcos.

do.

read table itab into wa_itab with key material = itab-component.

if sy-subrc ne 0.

exit.

endif.

sum + = wa_itab-zcos

enddo.

itab-zcos = sum

modify itab.

write itab.

clear sum.

endloop.

Read only

Former Member
0 Likes
1,154

Thanks Guys