Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Item Level Total

Hi guys,

want the summation at the item level with out using the AT end of controls statements inside my internal table.

I have writen code for the same below. Could any one give inputs to modify my code to get the summation for each item of an SO.

Example:-

(VBELN) (POSNR) ZDMENGE

100 10 100

100 10 400

100 20 600

100 30 50

100 30 150

200 10 400

200 20 300

200 20 200

Result must be as below(summation per item):

VBELN POSNR ZDMENGE

100 10 500

100 20 600

100 30 200

200 10 400

200 20 500

My current code:-

TYPES : BEGIN OF wa1_zmmt0006 ,

vbeln TYPE zmmt0006-vbeln,

posnr TYPE zmmt0006-posnr ,

zdmenge TYPE zmmt0006-menge ,

END OF wa1_zmmt0006 .

DATA : wa2_zmmt0006 TYPE wa1_zmmt0006 ,

wa_zmmt0006 TYPE wa1_zmmt0006 ,

it2_zmmt0006 TYPE wa1_zmmt0006 ,

it_zmmt0006 TYPE wa1_zmmt0006 .

SELECT vbeln posnr menge

FROM zmmt0006

INTO TABLE it2_zmmt0006

FOR ALL ENTRIES IN it_c_t_data

WHERE vbeln = it_c_t_data-vbeln

AND posnr = it_c_t_data-posnr

AND status = u2018 u2018 .

LOOP AT it2_zmmt0006 INTO wa2_ zmmt0006 .

wa_zmmt0006-posnr = wa2_zmmt0006-posnr .

wa_zmmt0006-zdmenge = wa2_zmmt0006-zdmenge .

wa_zmmt0006-zstatus = wa2_zmmt0006-zstatus .

Collect wa_zmmt0006 into it_zmmt0006 .

Endloop .

SORT it_zvitr_item_im BY vbeln ASCENDING posnr ASCENDING menge DESCENDING .

Regards,

Sonam

Edited by: sonamrata on Apr 14, 2010 4:33 PM

Former Member
Former Member replied

Hi Sonam,

Here you can try this aswell.

TABLES: zmmt0006 .

DATA : it_c_t_data TYPE TABLE OF mc11va0itm .

TYPES : BEGIN OF wa1_zmmt0006 ,

vbeln TYPE zmmt0006-vbeln,

posnr TYPE zmmt0006-posnr ,

zdmenge TYPE zmmt0006-menge ,

END OF wa1_zmmt0006 .

FIELD-SYMBOLS : <wa_ zmmt0006> TYPE wa1_zmmt0006 .

DATA : it_zmmt0006 TYPE wa1_zmmt0006 ,

DATA : l_vbeln2 TYPE zmmt0006-vbeln ,

l_posnr2 TYPE zmmt0006-posnr ,

l_zdmenge TYPE zmmt0006-menge VALUE 0.

it_c_t_data[] = c_t_data[].

IF NOT it_c_t_data[] IS INITIAL.

SORT it_c_t_data BY vbeln posnr.

SELECT vbeln posnr menge

FROM zmmt0006

INTO TABLE it_zmmt0006

FOR ALL ENTRIES IN it_c_t_data

WHERE vbeln = it_c_t_data-vbeln

AND posnr = it_c_t_data-posnr

AND status = u2018 u2018 .

IF sy-subrc EQ 0.

SORT it_zmmt0006 BY vbeln posnr.

ENDIF.

ENDIF.

LOOP AT it_zmmt0006 ASSIGNING <wa_zmmt0006>.

IF l_vbeln2 NE <wa_zmmt0006>-vbeln OR l_posnr2 NE

<wa_zmmt0006>-posnr.

l_zdmenge = 0.

ENDIF.

l_vbeln2 = <wa_zmmt0006>-vbeln.

l_posnr2 = <wa_zmmt0006>-posnr.

l_zdmenge = l_zdmenge + <wa_zmmt0006>-zdmenge .

<wa_zmmt0006>-vbeln = l_vbeln2.

<wa_zmmt0006>-posnr = l_posnr2.

<wa_zmmt0006>-zdmenge = l_zdmenge.

ENDLOOP.

SORT it_zmmt0006 BY vbeln ASCENDING posnr ASCENDING zdmenge

DESCENDING.

DELETE ADJACENT DUPLICATES FROM it_zmmt0006 COMPARING vbeln posnr.

LOOP AT it_zmmt0006 ASSIGNING <wa_zmmt0006>.

WRITE :/ <wa_zmmt0006>-vbeln , <wa_zmmt0006>-posnr , <wa_zmmt0006>-zdmenge.

ENDLOOP.

Best regards,

Selina

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question