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

totals in classical report

Hi,

Please tell how to get totals of a field in classical report.

please help with sample code.

thanks in advance.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 06:18 AM

    you can use some control commands like At Endof <Feild>. or At New < Feild>

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 06:19 AM

    hi,

    use ctrl - break stmts.

    ex:

    at new matnr.

    sum.

    at end of matnr.

    write :/ v_netwr.

    v_netwr = sum.// here sum will add all the values of netwr and store it in v_netwr.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 06:20 AM

    Hi Kiran,

    You can use CONTROL BREAK statement in a LOOP.

    Control break statements are

    1) at first...end at

    2) at last...end at

    3) at new...end at

    4) at end of ...end at.

    thanks & regards

    Kishore Kumar Maram

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 06:21 AM

    Hi,

    Use SUM with combination of control break statements.

    Thanks,

    Sri

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 06:52 AM

    HI,

    refer the code:

    reward fi help ful

    Umakanth

    -


    &----


    *& Report ZSD_SALES_INTER_REPORT1

    *&

    &----


    *&

    *&

    &----


    REPORT ZSD_SALES_INTER_REPORT1 NO STANDARD PAGE HEADING MESSAGE-ID ZMSG44

    LINE-SIZE 230 LINE-COUNT 65(3).

    **************************************************************************

    • Tables

    **************************************************************************

    TABLES : VBKD,VEPVG. "Sales document business data

    "Delivery Index

    *************************************************************************

    • Internal table

    *************************************************************************

    DATA : BEGIN OF I_SALES OCCURS 0,

    CH TYPE CHECKBOX,

    VBELN LIKE VBAK-VBELN, "Sales document no

    NETWR LIKE VBAK-NETWR, "Net value of the sales order in Document currency

    WAERK LIKE VBAK-WAERK, "SD Document currency

    MATNR LIKE VBAP-MATNR, "Material no

    AUDAT LIKE VAPMA-AUDAT, "DOCUMENT DATE

    END OF I_SALES .

    data : NEWSALES LIKE I_SALES OCCURS 0 WITH HEADER LINE.

    DATA : AMOUNT LIKE VBAK-NETWR.

    DATA : V_LIN TYPE I . "Screens vertical cursor position at PAI

    DATA : CHECKBOX TYPE C.

    DATA : DATE LIKE VAPMA-AUDAT.

    DATA : V_SEL LIKE SY-LISEL.

    ******************************************************************************

    • SELECTION-SCREEN

    ******************************************************************************

    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

    PARAMETERS : P_VKORG LIKE VEPVG-VKORG. "value check . "Sales organization

    PARAMETERS : P_VTWEG LIKE VEPVG-VTWEG ."value check. "Distribution channel

    PARAMETERS : P_SPART LIKE VEPVG-SPART ."Value check. "Division

    SELECT-OPTIONS : S_DATE FOR VBKD-BSTDK DEFAULT SY-DATUM TO SY-DATUM OBLIGATORY.

    SELECTION-SCREEN END OF BLOCK B1.

    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

    SELECTION-SCREEN BEGIN OF LINE.

    PARAMETERS : CHK AS CHECKBOX .

    selection-screen comment 5(20) text-003 for field chk.

    SELECTION-SCREEN END OF LINE.

    PARAMETERS : P_KUNNR LIKE VBPA-KUNNR MODIF ID S2. "Customer

    SELECTION-SCREEN END OF BLOCK B2.

    START-OF-SELECTION.

    set pf-status 'UKG9'.

    IF CHK <> 'X'.

    IF P_VKORG <> ''.

    PERFORM ORGANIZATION.

    ELSE.

    PERFORM ORGANIZATION_ELSE.

    ENDIF.

    ELSE.

    IF P_VKORG <> ''.

    PERFORM CUST_ORGA.

    ELSE.

    PERFORM CUST_ORGA_ELSE.

    ENDIF.

    ENDIF.

    • Displaying the contents with some alterations

    sort i_sales by AUDAT.

    • LOOP AT I_SALES.

    • WRITE : / I_SALES-CH,I_SALES-VBELN,I_SALES-NETWR,I_SALES-WAERK,I_SALES-MATNR,I_SALES-AUDAT.

    • ENDLOOP.

    • WRITE : / '******************************************************************************************'.

    LOOP AT I_SALES.

    ON CHANGE OF I_SALES-AUDAT.

    IF SY-TABIX = 1.

    WRITE : / SY-VLINE,I_SALES-CH AS CHECKBOX,I_SALES-AUDAT.

    CLEAR AMOUNT.

    ELSE.

    WRITE : SY-VLINE,AMOUNT,60 sy-vline,/ SY-VLINE,I_SALES-CH AS CHECKBOX,I_SALES-AUDAT.

    CLEAR AMOUNT.

    ENDIF.

    ENDON.

    AMOUNT = AMOUNT + I_SALES-NETWR.

    AT LAST.

    WRITE : SY-VLINE,AMOUNT,60 sy-vline.

    uline at /2(60).

    • ULINE.

    SUM.

    FORMAT COLOR = 3.

    WRITE : /'TOTAL AMOUNT: ' ,I_SALES-NETWR UNDER AMOUNT .

    ENDAT.

    ENDLOOP.

    ******************************************************************************************

    • top-of-page

    ******************************************************************************************

    top-of-page.

    uline at /2(60).

    write : / sy-vline,3 'Document date' ,16 sy-vline ,17 'Amount(net value of the sales document )' ,60 sy-vline .

    uline at /2(60).

    at user-command.

    if sy-ucomm = 'DISP'.

    LOOP AT I_SALES.

    REFRESH NEWSALES.

    V_LIN = SY-TABIX + 3.

    READ LINE V_LIN FIELD VALUE I_SALES-CH INTO CHECKBOX.

    IF CHECKBOX = 'X'.

    newsales-ch = 'X'.

    NEWSALES-VBELN = I_SALES-VBELN.

    NEWSALES-NETWR = I_SALES-NETWR.

    NEWSALES-WAERK = I_SALES-WAERK.

    NEWSALES-MATNR = I_SALES-MATNR.

    NEWSALES-AUDAT = I_SALES-AUDAT.

    APPEND NEWSALES.

    CLEAR NEWSALES.

    LOOP AT NEWSALES where audat = i_sales-audat .

    WRITE : / NEWSALES-CH as checkbox,NEWSALES-VBELN,NEWSALES-NETWR,NEWSALES-WAERK,NEWSALES-MATNR,NEWSALES-AUDAT.

    ENDLOOP.

    perform selection.

    ENDIF.

    ENDLOOP.

    ENDIF.

    &----


    *& Form ORGANIZATION

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM ORGANIZATION .

    SELECT F~VBELN

    C~NETWR

    C~WAERK

    P~MATNR

    P~AUDAT

    INTO CORRESPONDING FIELDS OF TABLE I_SALES

    FROM ( VAKPA AS F INNER JOIN VBAK AS C ON FVBELN = CVBELN )

    INNER JOIN VAPMA AS P ON FVBELN = PVBELN

    WHERE P~AUDAT IN S_DATE

    AND P~VKORG = P_VKORG.

    ENDFORM. " ORGANIZATION

    &----


    *& Form ORGANIZATION_ELSE

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM ORGANIZATION_ELSE .

    SELECT F~VBELN

    C~NETWR

    C~WAERK

    P~MATNR

    P~AUDAT

    INTO CORRESPONDING FIELDS OF TABLE I_SALES

    FROM ( VAKPA AS F INNER JOIN VBAK AS C ON FVBELN = CVBELN )

    INNER JOIN VAPMA AS P ON FVBELN = PVBELN

    WHERE P~AUDAT IN S_DATE.

    ENDFORM. " ORGANIZATION_ELSE

    &----


    *& Form CUST_ORGA

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM CUST_ORGA .

    SELECT F~VBELN

    C~NETWR

    C~WAERK

    P~MATNR

    P~AUDAT

    INTO CORRESPONDING FIELDS OF TABLE I_SALES

    FROM ( VAKPA AS F INNER JOIN VBAK AS C ON FVBELN = CVBELN )

    INNER JOIN VAPMA AS P ON FVBELN = PVBELN

    WHERE P~AUDAT IN S_DATE

    AND P~VKORG = P_VKORG

    and P~KUNNR = P_KUNNR.

    ENDFORM. " CUST_ORGA

    &----


    *& Form CUST_ORGA_ELSE

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM CUST_ORGA_ELSE .

    SELECT F~VBELN

    C~NETWR

    C~WAERK

    P~MATNR

    P~AUDAT

    INTO CORRESPONDING FIELDS OF TABLE I_SALES

    FROM ( VAKPA AS F INNER JOIN VBAK AS C ON FVBELN = CVBELN )

    INNER JOIN VAPMA AS P ON FVBELN = PVBELN

    WHERE P~AUDAT IN S_DATE

    AND P~KUNNR = P_KUNNR .

    ENDFORM. " CUST_ORGA_ELSE

    &----


    *& Form selection

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM selection .

    LOOP AT NEWSALES.

    ON CHANGE OF NEWSALES-AUDAT.

    IF SY-TABIX <> 1.

    WRITE : / SY-VLINE,NEWSALES-AUDAT,SY-VLINE,27 SY-VLINE,48 SY-VLINE.

    ELSE.

    WRITE : / SY-VLINE,NEWSALES-AUDAT,SY-VLINE,27 SY-VLINE,48 SY-VLINE.

    ENDIF.

    ENDON.

    WRITE : / SY-VLINE,2 NEWSALES-VBELN,13 SY-VLINE,14 NEWSALES-NETWR,30 SY-VLINE,31 NEWSALES-WAERK,37 SY-VLINE ,38 NEWSALES-MATNR,57 SY-VLINE,58 NEWSALES-AUDAT.

    at last.

    sum .

    uline.

    format color = 3.

    write : / sy-vline, 15 'Total amount:', newsales-netwr under newsales-netwr.

    format color off.

    uline.

    endat.

    ENDLOOP.

    v_lin = 1.

    free newsales.

    ENDFORM. " SELECTION

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 07:05 AM

    Hi,

    If you require subtotal then use At New < Feild> and SUM statement or if you want total of a field column use statement

    At Endof <Feild> and SUM statement.

    Help children of U.N World Food Program by rewarding them and encourage others to answer your queries

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 07:19 AM

    Hi kiran ,

    my intrenal table contains two fields with data like this

    f1 f2

    A 10

    B 10

    A 20

    B 20

    my final otuput look like this

    A 30

    B 30

    for this the sample code is ............

    data : begin of itab occurs 0,

    f1 type c,

    f2(3) type n,

    end of itab.

    DATA : TOTAL(10) TYPE N.

    itab-f1 = 'A'.

    ITAB-F2 = '10'.

    APPEND ITAB.

    itab-f1 = 'A'.

    ITAB-F2 = '20'.

    APPEND ITAB.

    itab-f1 = 'B'.

    ITAB-F2 = '10'.

    APPEND ITAB.

    itab-f1 = 'B'.

    ITAB-F2 = '20'.

    APPEND ITAB.

    SORT ITAB BY F1.

    LOOP AT ITAB.

    AT NEW F1.

    WRITE :/ ITAB-F1.

    ENDAT.

    TOTAL = TOTAL + ITAB-F2.

    AT END OF F1.

    WRITE TOTAL.

    CLEAR TOTAL.

    ENDAT.

    ENDLOOP.

    Reward if helpful

    Thanks,

    S.Gangi reddy

    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.