Skip to Content
author's profile photo Former Member
Former Member

to find subtotal column wise

hi all,

could u anyone guide me why the below code is working to find subtotal fieldwise.

Data: itab2 type table of string with header line.

DATA : x type p decimals 2, sum type p decimals 2.

IF NOT ITAB[] IS INITIAL.

SORT ITAB BY MTART KUNNR.

LOOP AT ITAB.

ON CHANGE OF ITAB-MTART.

SELECT SINGLE * FROM T134T CLIENT SPECIFIED

WHERE MANDT = SY-MANDT

AND SPRAS = SY-LANGU

AND MTART = ITAB-MTART.

WRITE:/ T134T-MTBEZ.

ENDON.

TEMP_MGF = itab-dmeng.

ITAB2 = TEMP_MGF.

append itab2.

at end of mtart.

loop at itab2.

sum = itab2.

x = sum + x.

write:/ 'subtotal',x.

endloop.

endat.

ENDLOOP.

FREE ITAB.

ENDIF.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 22, 2007 at 10:46 AM

    sorry, mistake in writting. it is not working

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 22, 2007 at 10:51 AM

    Hi

    You can do the Subtotals on fields of an internal table only in the loop of that ITAB and after sorting by the fields.

    see the following control break statements stuff and do the totals accordingly

    All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table

    FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.

    Some time you will get * when mopving data from this int table to other table using these commands

    so you have to use

    READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them

    DATA: sflight_tab TYPE SORTED TABLE OF sflight

    WITH UNIQUE KEY carrid connid fldate,

    sflight_wa LIKE LINE OF sflight_tab.

    SELECT *

    FROM sflight

    INTO TABLE sflight_tab.

    LOOP AT sflight_tab INTO sflight_wa.

    AT NEW connid.

    WRITE: / sflight_wa-carrid,

    sflight_wa-connid.

    ULINE.

    ENDAT.

    WRITE: / sflight_wa-fldate,

    sflight_wa-seatsocc.

    AT END OF connid.

    SUM.

    ULINE.

    WRITE: / 'Sum',

    sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

    SKIP.

    ENDAT.

    AT END OF carrid.

    SUM.

    ULINE.

    WRITE: / 'Carrier Sum',

    sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

    NEW-PAGE.

    ENDAT.

    AT LAST.

    SUM.

    WRITE: / 'Overall Sum',

    sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

    ENDAT.

    ENDLOOP.

    Regards

    Anji

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.