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

Really Urgent: subtotal in alv report

hi,

i had made a ALV report which is working fine ,but now i wan to add the feature of SUBTOTAL in dis report. plzz help me out by giving the EXAMPLE of it as i am usnig the concept of INTERNAL TABLE and used only 1 internal table.

Help provided with sufficient example will be definately rewarded.

regards,

ric.s

Edited by: ric .s on Jan 20, 2008 7:30 AM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

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

    Hi

    In order to display an ALV report with specific columns already sorted by default you will need to build a

    sort catalogue. This is fairly straight forward and is done in the following way:

    Step 1. Add data declaration for sort catalogue

    Step 2. Add code to build sort catalogue table

    Step 3. Update 'REUSE_ALV_GRID_DISPLAY' FM call to include parameter 'it_sort'

    • ALV data declarations

    data: it_sortcat type slis_sortinfo_alv occurs 1,

    wa_sort like line of it_sortcat.

    perform build_sortcat.

    &----


    *& Form build_sortcat

    &----


    • Build Sort catalog

    ----


    FORM build_sortcat .

    wa_sort-spos = 1.

    wa_sort-fieldname = 'EBELN'.

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

    • gd_sortcat-tabname

    APPEND wa_sort TO it_sortcat.

    wa_sort-spos = 2.

    wa_sort-fieldname = 'EBELP'.

    • gd_sortcat-tabname

    APPEND wa_sort TO it_sortcat.

    ENDFORM. " build_sortcat

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    i_callback_program = gd_repid

    i_callback_top_of_page = 'TOP-OF-PAGE'

    is_layout = gd_layout

    it_fieldcat = fieldcatalog[]

    it_sort = it_sortcat

    i_save = 'X'

    tables

    t_outtab = it_ekko

    exceptions

    program_error = 1

    others = 2.

    Add a comment
    10|10000 characters needed characters exceeded

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

    You have to use ls_fieldcat-do_sum statement in your coding

    Check this sample coding

    code&----


    *& Report ZALVTOTAL *

    *& *

    &----


    *& *

    *& *

    &----


    REPORT ZALVTOTAL .

    TYPES :

    BEGIN OF ty_vbak,

    vkorg TYPE vbak-vkorg, " Sales organization

    kunnr TYPE vbak-kunnr, " Sold-to party

    vbeln TYPE vbak-vbeln, " Sales document

    netwr TYPE vbak-netwr, " Net Value of the Sales Order

    waerk TYPE vbak-waerk, " Document currency

    END OF ty_vbak.

    DATA:

    vbak TYPE vbak,

    gt_vbak TYPE TABLE OF ty_vbak.

    SELECT-OPTIONS :

    s_vkorg FOR vbak-vkorg, " Sales organization

    s_kunnr FOR vbak-kunnr, " Sold-to party

    s_vbeln FOR vbak-vbeln. " Sales document

    SELECTION-SCREEN :

    SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.

    PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.

    SELECTION-SCREEN END OF LINE.

    -


    INITIALIZATION.

    v_1 = 'Maximum of records to read'.

    -


    START-OF-SELECTION.

    PERFORM f_read_data.

    PERFORM f_display_data.

    -


    Form f_read_data

    -


    FORM f_read_data.

    SELECT vkorg kunnr vbeln netwr waerk

    UP TO p_max ROWS

    INTO TABLE gt_vbak

    FROM vbak

    WHERE kunnr IN s_kunnr

    AND vbeln IN s_vbeln

    AND vkorg IN s_vkorg.

    ENDFORM. " F_READ_DATA

    -


    Form f_display_data

    -


    FORM f_display_data.

    TYPE-POOLS: slis. " ALV Global types

    DEFINE m_fieldcat.

    add 1 to ls_fieldcat-col_pos.

    ls_fieldcat-fieldname = &1.

    ls_fieldcat-ref_tabname = 'VBAK'.

    ls_fieldcat-do_sum = &2.

    ls_fieldcat-cfieldname = &3.

    append ls_fieldcat to lt_fieldcat.

    END-OF-DEFINITION.

    DEFINE m_sort.

    add 1 to ls_sort-spos.

    ls_sort-fieldname = &1.

    ls_sort-up = 'X'.

    ls_sort-subtot = &2.

    append ls_sort to lt_sort.

    END-OF-DEFINITION.

    DATA:

    ls_fieldcat TYPE slis_fieldcat_alv,

    lt_fieldcat TYPE slis_t_fieldcat_alv,

    lt_sort TYPE slis_t_sortinfo_alv,

    ls_sort TYPE slis_sortinfo_alv,

    ls_layout TYPE slis_layout_alv.

    m_fieldcat 'VKORG' '' ''.

    m_fieldcat 'KUNNR' '' ''.

    m_fieldcat 'VBELN' '' ''.

    m_fieldcat 'NETWR' 'X' 'WAERK'.

    m_fieldcat 'WAERK' '' ''.

    m_sort 'VKORG' 'X'. " Sort by vkorg and subtotal

    m_sort 'KUNNR' 'X'. " Sort by kunnr and subtotal

    m_sort 'VBELN' ''. " Sort by vbeln

    ls_layout-cell_merge = 'X'.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    is_layout = ls_layout

    it_fieldcat = lt_fieldcat

    it_sort = lt_sort

    TABLES

    t_outtab = gt_vbak.

    ENDFORM. " F_DISPLAY_DATA[/code]

    Add a comment
    10|10000 characters needed characters exceeded

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

    Hi,

    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

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

    hi,

    please populate the fieldcat for that field with the parameter.

    ls_fcat-do_sum = 'X'.

    Regards,

    Sumanjeet.

    Add a comment
    10|10000 characters needed characters exceeded

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

    Hi,

    1. Sort the output based on a FIELD present in ur internal table.

    Data: int_sort TYPE slis_t_sortinfo_alv,

    fs_sort TYPE slis_sortinfo_alv.

    • Sort the output based on ORG UNIT.

    CLEAR fs_sort.

    fs_sort-fieldname = 'ORGEH'.

    fs_sort-subtot = 'X'.

    fs_sort-up = 'X'.

    APPEND fs_sort TO int_sort.

    2. Then, sum up the field which u want to sum based on the sorted field in Fieldcatalog.

    DATA: loc_fieldcat TYPE slis_fieldcat_alv.

    DEFINE define_field.

    clear loc_fieldcat.

    loc_fieldcat-fieldname = &1.

    loc_fieldcat-key = &2.

    loc_fieldcat-do_sum = &3.

    append loc_fieldcat to int_fieldcat.

    END-OF-DEFINITION.

    REFRESH int_fieldcat.

    CLEAR int_fieldcat.

    define_field 'PERNR' 'X' '8' ''.

    define_field 'ENAME' '' '40' ''.

    define_field 'SMPCNT' '' '' 'X'.

    3. Add the sorted internal table to the 'REUSE_ALV_GRID_DISPLAY' fm.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = sy-repid

    i_callback_top_of_page = 'TOP_OF_PAGE'

    it_sort = int_sort

    i_callback_pf_status_set = 'F_PF_STATUS_SET'

    i_callback_user_command = 'F_USER_COMMAND'

    it_fieldcat = int_fieldcat

    i_save = 'X'

    TABLES

    t_outtab = int_outputcpy

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    WRITE / 'error'.

    ENDIF.

    Thanks,

    Shanthi

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      hi everyone,

      dis is my code of the report which i had done for subtotal display:-

      DATA: lv_sort TYPE slis_sortinfo_alv,

      t_sort type slis_t_sortinfo_alv.

      DATA: t_subtot TYPE slis_t_sortinfo_alv,

      subtot LIKE LINE OF t_subtot.

      perform get_subtotals.

      FORM get_subtotals.

      CLEAR lv_sort.

      lv_sort-fieldname = 'MENGE'.

      *lv_sort-up = 'X'.

      lv_sort-subtot = 'X'.

      APPEND lv_sort TO t_sort.

      clear lv_sort.

      lv_sort-fieldname = 'WRTZL'.

      lv_sort-tabname = 'ITS1'.

      *lv_sort-up = 'X'.

      lv_sort-subtot = 'X'.

      APPEND lv_sort TO t_sort.

      clear lv_sort.

      lv_sort-fieldname = 'BUCHM'.

      lv_sort-tabname = 'ITS1'.

      lv_sort-spos = 1.

      *lv_sort-up = 'X'.

      lv_sort-subtot = 'X'.

      APPEND lv_sort TO t_sort.

      clear lv_sort.

      lv_sort-fieldname = 'WRTBM'.

      lv_sort-tabname = 'ITS1'.

      *lv_sort-up = 'X'.

      lv_sort-subtot = 'X'.

      APPEND lv_sort TO t_sort.

      clear lv_sort.

      lv_sort-fieldname = 'DIFFQTY'.

      lv_sort-tabname = 'ITS1'.

      *lv_sort-up = 'X'.

      lv_sort-subtot = 'X'.

      APPEND lv_sort TO t_sort.

      clear lv_sort.

      lv_sort-fieldname = 'DIFFVALUE'.

      lv_sort-tabname = 'ITS1'.

      *lv_sort-up = 'X'.

      lv_sort-subtot = 'X'.

      APPEND lv_sort TO t_sort.

      clear lv_sort.

      ENDFORM.

      PLZ HELP ME DAT IS DIS CODE IS CORRECT OR NOT?

      help provided will be definately rewarded.

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.