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

regarding sub totaling in alv

hi,

i am making report in alv in which i have to display the sub totals and den full total.

is it possible to display sub total in ALV acccording to material type wise or itemid wise.

plzz help me with some example.

If find useful he or she will definately rewarded.........

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2008 at 08:07 AM

    Hi,

    The following example for sub totall for ALV report..

    u have to pass do_sum = 'X'. for perticuler fileds.

    if it is use full answer reward me a points..

    &----


    *& Report ZDEL_ALV1

    *

    *

    *Description: This ALV interactive report is display Delivary

    • status

    ----


    REPORT zdel_alv1 NO STANDARD PAGE HEADING LINE-SIZE 255 LINE-COUNT 60.

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

    *TABLE DECLARATION

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

    TABLES : likp, "Delivery Header Data

    lips, "Delivery item Data

    vbup. "sales document item status

    TYPE-POOLS : slis.

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

    *SRUCTURE DECLARATION

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

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

    *THIS TABLE FOR HEADER DETAILS

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

    TYPES : BEGIN OF t_likp ,

    vbeln LIKE likp-vbeln, "Delivery number

    kosta like vbup-kosta,

    kunnr LIKE likp-kunnr, "Customer number

    wadat LIKE likp-wadat, "Planned goods movement date

    ernam LIKE likp-ernam, "Name of person

    vkorg LIKE likp-vkorg, "Sales organization

    lfart LIKE likp-lfart, "DELIVERY TYPE

    ntgew LIKE likp-ntgew, "NET WEIGHT

    END OF t_likp.

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

    *THIS TABLE FOR ITEM DETAILS

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

    TYPES : BEGIN OF t_lips ,

    vbeln LIKE lips-vbeln, "Delivery number

    posnr LIKE lips-posnr, "delivery item

    matnr LIKE lips-matnr, "Material number

    lfimg LIKE lips-lfimg, "Actual quantity delivered

    ntgew LIKE lips-ntgew, "Net weight

    exbwr LIKE lips-exbwr, "Externally entered posting amount

    arktx LIKE lips-arktx, "Short text SO Item

    END OF t_lips.

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

    *THIS IS FOR FINAL OUTPUT

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

    TYPES : BEGIN OF t_vbup ,

    vbeln LIKE likp-vbeln, "Delivery number

    kosta LIKE vbup-kosta, "Picking status/Putaway status

    posnr LIKE vbup-posnr, "delivery item

    matnr LIKE lips-matnr, "Material number

    lfimg LIKE lips-lfimg, "Actual quantity delivered

    ntgew LIKE lips-ntgew, "Net weight

    exbwr LIKE lips-exbwr, "Externally entered posting amount

    arktx LIKE lips-arktx, "SHORT text SO Item

    description(20), "for display text

    END OF t_vbup.

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

    *INTERNAL TABLES

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

    DATA : i_likp TYPE STANDARD TABLE OF t_likp.

    DATA : i_lips TYPE STANDARD TABLE OF t_lips.

    DATA : i_vbup TYPE STANDARD TABLE OF t_vbup.

    DATA : repid LIKE sy-repid.

    DATA : delivar1(10) TYPE c.

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

    *WORK AREA

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

    DATA : wa_likp TYPE t_likp.

    DATA : wa_lips TYPE t_lips.

    DATA : wa_vbup TYPE t_vbup.

    DATA: i_vbup1 LIKE wa_vbup OCCURS 0 WITH HEADER LINE.

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

    *SLIS TABLE DECLARATIONS

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

    DATA: i_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,

    i_events TYPE slis_t_event,

    w_events TYPE slis_alv_event,

    i_fieldcat1 TYPE slis_t_fieldcat_alv WITH HEADER LINE,

    i_layout TYPE slis_layout_alv.

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

    *SELECTING RANGE OF VALUES

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

    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

    SELECT-OPTIONS : s_vbeln FOR likp-vbeln,

    s_kunnr FOR likp-kunnr,

    s_wadat FOR likp-wadat.

    SELECTION-SCREEN END OF BLOCK b1 .

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

    *CHOOSE ONE CHECK BOX FOR DISPLAYING THE DELIVARY STATUS

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

    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

    PARAMETERS : cb_kostc AS CHECKBOX,"DEFAULT 'X',

    cb_kosta AS CHECKBOX,

    cb_kostb AS CHECKBOX.

    SELECTION-SCREEN END OF BLOCK b2.

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

    *INTIALIZATION CHECK

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

    INITIALIZATION.

    repid = sy-repid.

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

    *START-OF-SELECTION

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

    START-OF-SELECTION.

    PERFORM get_data.

    PERFORM get_field.

    • PERFORM GET_EVENTS.

    PERFORM display.

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

    *END-OF-SELECTION

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

    END-OF-SELECTION.

    &----


    *& Form RUCOMM

    &----


    • This form getting details from lips table for displaying

    • the item details and all select statements for delivary status

    ----


    • -->R_UCOMM text

    • -->RS_SELFIELDtext

    ----


    FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE

    slis_selfield.

    IF rs_selfield-fieldname = 'VBELN'.

    delivar1 = rs_selfield-value.

    ENDIF.

    IF cb_kostc = 'X'.

    • SELECT VBELN KOSTA FROM VBUP

    • INTO TABLE I_VBUP

    • WHERE VBELN IN DELIVAR

    • AND KOSTA = 'C'.

    • SELECT VBELN MATNR LFIMG EXBWR INTO TABLE I_LIPS FROM LIPS

    • WHERE VBELN EQ DELIVAR1.

    REFRESH i_vbup1[].

    CLEAR i_vbup1.

    SELECT avbeln akosta bposnr bmatnr blfimg bntgew b~exbwr

    b~arktx

    INTO TABLE i_vbup

    FROM vbup AS a INNER JOIN lips AS b

    ON avbeln = bvbeln

    WHERE a~vbeln EQ delivar1

    AND kosta = 'C'.

    ELSEIF cb_kosta = 'X'.

    • SELECT VBELN KOSTA FROM VBUP

    • INTO TABLE I_VBUP

    • WHERE VBELN IN DELIVAR

    • AND KOSTA = 'A'.

    SELECT avbeln akosta bposnr bmatnr blfimg bntgew b~exbwr

    b~arktx

    INTO TABLE i_vbup

    FROM vbup AS a INNER JOIN lips AS b

    ON avbeln = bvbeln

    WHERE a~vbeln EQ delivar1

    AND kosta = 'A'.

    ELSEIF cb_kostb = 'X'.

    • SELECT VBELN KOSTA FROM VBUP

    • INTO TABLE I_VBUP

    • WHERE VBELN IN DELIVAR

    • AND KOSTA = 'B'.

    SELECT avbeln akosta bposnr bmatnr blfimg bntgew b~exbwr

    b~arktx

    INTO TABLE i_vbup

    FROM vbup AS a INNER JOIN lips AS b

    ON avbeln = bvbeln

    WHERE a~vbeln EQ delivar1

    AND kosta = 'B'.

    ENDIF.

    CLEAR i_vbup1.

    LOOP AT i_vbup INTO wa_vbup.

    i_vbup1-vbeln = wa_vbup-vbeln.

    i_vbup1-kosta = wa_vbup-kosta.

    IF wa_vbup-kosta = 'C'.

    i_vbup1-description = 'COMPLETELY PROCESSED'.

    ELSEIF wa_vbup-kosta = 'B'.

    i_vbup1-description = 'PARTIALLY PROCESSED'.

    ELSEIF wa_vbup-kosta = 'A'.

    i_vbup1-description = 'NOT YET PROCESSED'.

    ENDIF.

    i_vbup1-posnr = wa_vbup-posnr.

    i_vbup1-matnr = wa_vbup-matnr.

    i_vbup1-lfimg = wa_vbup-lfimg.

    i_vbup1-ntgew = wa_vbup-ntgew.

    i_vbup1-exbwr = wa_vbup-exbwr.

    i_vbup1-arktx = wa_vbup-arktx.

    APPEND i_vbup1 .

    ENDLOOP.

    SORT i_vbup1 BY vbeln matnr lfimg.

    DELETE ADJACENT DUPLICATES FROM i_vbup1 COMPARING vbeln matnr lfimg.

    • SELECT VBELN MATNR LFIMG EXBWR INTO TABLE I_LIPS FROM LIPS

    • WHERE VBELN EQ DELIVAR1.

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

    *This function module for displaying the item details

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

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = repid

    it_fieldcat = i_fieldcat1[]

    i_callback_top_of_page = 'TOP_OF_PAGE'

    i_callback_user_command = 'USER_COMMAND1'

    it_events = i_events

    TABLES

    t_outtab = i_vbup1

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    CLEAR i_vbup1.

    ENDFORM. "RUCOMM

    &----


    *& Form USER_COMMAND1

    &----


    • text

    ----


    • -->R_UCOMM1 text

    • -->RS_SELFIELDtext

    ----


    FORM user_command1 USING r_ucomm1 LIKE sy-ucomm rs_selfield1 TYPE

    slis_selfield.

    DATA: deliv(10) TYPE c.

    IF rs_selfield1 = 'VBELN'.

    deliv = rs_selfield1-value.

    ENDIF.

    SET PARAMETER ID 'VL' FIELD delivar1.

    CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.

    ENDFORM. "USER_COMMAND1

    &----


    *& Form GET_DATA

    &----


    • This form for getting the data from likp table

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM get_data .

    • SELECT VBELN KUNNR WADAT FROM LIKP INTO TABLE I_LIKP

    • WHERE VBELN IN S_VBELN

    • AND KUNNR IN S_KUNNR

    • AND WADAT IN S_WADAT.

    REFRESH i_likp[].

    CLEAR i_likp.

    IF cb_kostc = 'X' AND cb_kosta = ' ' AND cb_kostb = ''.

    SELECT avbeln akosta bkunnr bwadat bernam bvkorg blfart bntgew

    INTO TABLE i_likp

    FROM vbup AS a INNER JOIN likp AS b

    ON avbeln = bvbeln

    WHERE

    b~kunnr IN s_kunnr

    AND b~vbeln IN s_vbeln

    AND b~wadat IN s_wadat

    AND a~kosta = 'C'.

    ELSEIF cb_kosta = 'X' AND cb_kostb = ' ' AND cb_kostc = ''.

    SELECT avbeln akosta bkunnr bwadat bernam bvkorg blfart bntgew

    INTO TABLE i_likp

    FROM vbup AS a INNER JOIN likp AS b

    ON avbeln = bvbeln

    WHERE

    b~kunnr IN s_kunnr

    AND b~vbeln IN s_vbeln

    AND b~wadat IN s_wadat

    AND a~kosta = 'A'.

    ELSEIF cb_kostb = 'X' AND cb_kosta = '' AND cb_kostc = ''.

    SELECT avbeln akosta bkunnr bwadat bernam bvkorg blfart bntgew

    INTO TABLE i_likp

    FROM vbup AS a INNER JOIN likp AS b

    ON avbeln = bvbeln

    WHERE

    b~kunnr IN s_kunnr

    AND b~vbeln IN s_vbeln

    AND b~wadat IN s_wadat

    AND kosta = 'B'.

    ELSEIF cb_kostc = 'X' AND cb_kosta = 'X' AND cb_kostb = 'X'.

    SELECT avbeln akosta bkunnr bwadat bernam bvkorg blfart bntgew

    INTO TABLE i_likp

    FROM vbup AS a INNER JOIN likp AS b

    ON avbeln = bvbeln

    WHERE

    b~kunnr IN s_kunnr

    AND b~vbeln IN s_vbeln

    AND b~wadat IN s_wadat

    AND kosta NE ' '.

    ENDIF.

    DELETE ADJACENT DUPLICATES FROM i_likp.

    ENDFORM. " GET_DATA

    &----


    *& Form GET_FIELD

    &----


    • This form for defining the every fields from likp & lips tables

    ----


    FORM get_field .

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

    *This fields are retrieving from header table(likp)

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

    CLEAR i_fieldcat.

    i_fieldcat-fieldname = 'VBELN'.

    i_fieldcat-seltext_m = 'SALES ORDER NO'.

    APPEND i_fieldcat TO i_fieldcat.

    CLEAR i_fieldcat.

    i_fieldcat-fieldname = 'KUNNR'.

    i_fieldcat-seltext_m = 'CUSTOMER NO'.

    APPEND i_fieldcat TO i_fieldcat.

    CLEAR i_fieldcat.

    i_fieldcat-fieldname = 'WADAT'.

    i_fieldcat-seltext_m = 'DATE'.

    APPEND i_fieldcat TO i_fieldcat.

    CLEAR i_fieldcat.

    i_fieldcat-fieldname = 'ERNAM'.

    i_fieldcat-seltext_m = 'NAME OF PERSON'.

    APPEND i_fieldcat TO i_fieldcat.

    CLEAR i_fieldcat.

    i_fieldcat-fieldname = 'VKORG'.

    i_fieldcat-seltext_m = 'SALES ORGANIZATION'.

    APPEND i_fieldcat TO i_fieldcat.

    CLEAR i_fieldcat.

    i_fieldcat-fieldname = 'LFART'.

    i_fieldcat-seltext_m = 'DELIVERY TYPE'.

    APPEND i_fieldcat TO i_fieldcat.

    CLEAR i_fieldcat.

    i_fieldcat-fieldname = 'NTGEW'.

    i_fieldcat-seltext_m = 'NET WEIGHT'.

    i_fieldcat-do_sum = 'X'.

    APPEND i_fieldcat TO i_fieldcat.

    CLEAR i_fieldcat.

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

    *This fields are retrieving from item table(lips)

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

    CLEAR i_fieldcat1.

    i_fieldcat1-fieldname = 'VBELN'.

    i_fieldcat1-seltext_m = 'DELIVAR NO'.

    APPEND i_fieldcat1 TO i_fieldcat1.

    CLEAR i_fieldcat1.

    i_fieldcat1-fieldname = 'POSNR'.

    i_fieldcat1-seltext_m = 'DELIVERY ITEM'.

    APPEND i_fieldcat1 TO i_fieldcat1.

    CLEAR i_fieldcat1.

    i_fieldcat1-fieldname = 'MATNR'.

    i_fieldcat1-seltext_m = 'MATERIAL NO'.

    APPEND i_fieldcat1 TO i_fieldcat1.

    CLEAR i_fieldcat1.

    i_fieldcat1-fieldname = 'LFIMG'.

    i_fieldcat1-seltext_m = 'ACTUAL QUANTITY'.

    i_fieldcat1-do_sum = 'X'.

    APPEND i_fieldcat1 TO i_fieldcat1.

    CLEAR i_fieldcat1.

    i_fieldcat1-fieldname = 'NTGEW'.

    i_fieldcat1-seltext_m = 'NET WEIGHT'.

    i_fieldcat1-do_sum = 'X'.

    APPEND i_fieldcat1 TO i_fieldcat1.

    CLEAR i_fieldcat1.

    i_fieldcat1-fieldname = 'EXBWR'.

    i_fieldcat1-seltext_m = 'AMOUNT'.

    APPEND i_fieldcat1 TO i_fieldcat1.

    CLEAR i_fieldcat1.

    i_fieldcat1-fieldname = 'ARKTX'.

    i_fieldcat1-seltext_m = 'SHORT TEXT FOR so ITEM'.

    APPEND i_fieldcat1 TO i_fieldcat1.

    CLEAR i_fieldcat1.

    i_fieldcat1-fieldname = 'DESCRIPTION'.

    i_fieldcat1-seltext_m = 'PICKING STATUS'.

    APPEND i_fieldcat1 TO i_fieldcat1.

    CLEAR i_fieldcat1.

    ENDFORM. " GET_FIELD

    &----


    *& Form GET_EVENTS

    &----


    • This form defining the events

    ----


    *FORM GET_EVENTS .

    *

    • CLEAR W_EVENTS.

    *

    • W_EVENTS-NAME = 'USER_COMMAND'.

    *

    • W_EVENTS-FORM = 'RUCOMM'.

    *

    • APPEND W_EVENTS TO I_EVENTS.

    *

    *ENDFORM. " GET_EVENTS

    &----


    *& Form DISPLAY

    &----


    • This form is going to display header details from likp table

    ----


    FORM display .

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

    *This function module for displaying the header details

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

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = repid

    i_callback_top_of_page = 'TOP-OF-PAGE'

    i_callback_user_command = 'USER_COMMAND'

    it_fieldcat = i_fieldcat[]

    i_save = 'X'

    it_events = i_events

    TABLES

    t_outtab = i_likp

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    ENDFORM. " DISPLAY

    &----


    *& Form TOP-OF-PAGE

    &----


    • This form is going to display top-of-page header text

    ----


    FORM top-of-page.

    DATA: i_list_comments TYPE slis_t_listheader.

    DATA: w_list_comments TYPE slis_listheader.

    CLEAR: i_list_comments[].

    w_list_comments-typ = 'H'. "H=Header, S=Selection, A=Action

    w_list_comments-info = 'DELIVERY ORDER DETAILS'.

    APPEND w_list_comments TO i_list_comments.

    w_list_comments-typ = 'A'. " H = Header, S = Selection, A = Action

    w_list_comments-info = 'Basic list'.

    APPEND w_list_comments TO i_list_comments.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    i_logo = 'enjoy'

    it_list_commentary = i_list_comments.

    ENDFORM. "TOP-OF-PAGE

    &----


    *& Form TOP_OF_PAGE

    &----


    • This form is going to display top-of-page item text

    ----


    FORM top_of_page.

    DATA: i_list_comments TYPE slis_t_listheader.

    DATA: w_list_comments TYPE slis_listheader.

    DATA : i_line LIKE w_list_comments-info.

    CONCATENATE 'DELIVERY ITEM DETAILS :' delivar1 INTO i_line .

    • SEPARATED BY SPACE.

    CLEAR: i_list_comments[].

    w_list_comments-typ = 'H'. "H=Header, S=Selection, A=Action

    w_list_comments-info = i_line.

    APPEND w_list_comments TO i_list_comments.

    w_list_comments-typ = 'A'. " H = Header, S = Selection, A = Action

    w_list_comments-info = 'Secondary list'.

    APPEND w_list_comments TO i_list_comments.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    i_logo = 'enjoy'

    it_list_commentary = i_list_comments.

    ENDFORM. "TOP_OF_PAGE

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      HI,

      Thanks for ur reply but i am using d different concept i.e. single itab den i am not using any standard table concept.

      can anybody provide me example of it.

      if i click on any field i.e. mtart den corresponding total of it should be displyed.

      plzz help me its urgent.

  • Posted on Jan 10, 2008 at 07:46 AM

    Hi,

    Check the belwo link ..

    http://www.sapdev.co.uk/reporting/alv/alvgrid_sort.htm

    Regards,

    Nagaraj

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2008 at 07:49 AM

    HI,

    While building the fieldcat, for particular column you need to total you need to use do_sum = 'X'.

    and for subtotal :

    data: it_sortcat type slis_sortinfo_alv occurs 1,

    wa_sort like line of it_sortcat.

    wa_sort-spos = 1.

    wa_sort-fieldname = 'Fieldname'.

    wa_sort-SUBTOT = 'X'. "subtotals any totals column by this field

    APPEND wa_sort TO it_sortcat.

    simiarly for other field also.

    And pass it_sortcat to it_sort to alv FM.

    And please refer to the link below :

    http://www.sapdev.co.uk/reporting/alv/alvgrid_sort.htm

    Thanks,

    Sriram Ponna.

    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.