Skip to Content
avatar image
Former Member

Total and Subtotals in ALV GRID DISPLAY.

Hi,

I am facing a problem regarding total and sub-total in the REUSE_ALV_GRID_DISPLAY Function module.

Actually its not a problem, its a requirement.

In my report, i have several currencies like USD,SGD and JPY.

My BA told me to do subtotal of all the currencies, its not a big issue.

But she also wants Final Total will not be displayed, as it contains total from different currencies.

It means she only wants subtotal of different currencies as final total.

Like if report has 3 different currencies, then report will have 3 sub-totals as final totals.

Please help me.

Regards

Deepak.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    Apr 19, 2010 at 03:02 PM

    you must check you're alv structure. the field with the currency must also be connected to the field with the amount otherwise it is not clear that the amount belongs to a specific currency also

    look in se11 at you're structure the TAB currency/quantity fieldsand check if you see the the currency field at the reference structure and field name

    the reference structure is equal to the alv structure

    here an example of mine with articles where I could ofcourse also not totalize different articles with different units

    structure ZALV_AFREKENINGTUSSENORDER_2 under tab currency/quantity fields

    MENGE	MENGE_D	Hoeveelheid	QUAN	ZALV_AFREKENINGTUSSENORDER_2	MEINS
    MEINS	MEINS	Basishoeveelheidseenheid	UNIT	

    in this case it is impossible to get a grand total, all totals are summed according to their currency in you're case.

    kind regards

    arthur

    Edited by: A. de Smidt on Apr 19, 2010 5:19 PM

    Edited by: A. de Smidt on Apr 19, 2010 5:20 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 19, 2010 at 11:21 AM

    Please search you will get lots of solutions on this.

    Go this way:

     REFRESH gt_sort.
      CLEAR wa_sort.
      wa_sort-fieldname = 'fieldname'.<-----that you want to sort and subtotal
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      wa_sort-tabname = 'IT_OUTPUT'.
      APPEND wa_sort TO gt_sort.
    
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
        i_callback_program         = g_repid
        i_callback_top_of_page  = 'TOP_OF_PAGE'
        is_layout                          = gt_layout
        it_fieldcat                         = it_fcat
        it_sort                           = gt_sort[]
        TABLES
          t_outtab                      = it_output.

    At last in field catalog pass

     wa_fcat-do_sum    = 'X'

    .

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 19, 2010 at 02:54 PM

    Hi,

    how can you have subtotals w/o having totals? This does not make sense.

    But anyways, when you have three different currencies you will of cours get three totals. This is handeled by ALV because of your assignment of the value field to the currency field. If you get only 1 total line, then something is wrong.

    Kind regards,

    Thomas

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 19, 2010 at 03:57 PM

    Hi,

    Test the following code,it could solve your problem.

    TABLES : vbak.

    TYPE-POOLS: slis. " ALV Global types

    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.

    DATA:

    BEGIN OF gt_vbak OCCURS 0,

    vkorg LIKE vbak-vkorg, " Sales organization

    kunnr LIKE vbak-kunnr, " Sold-to party

    vbeln LIKE vbak-vbeln, " Sales document

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

    waerk LIKE vbak-waerk, " Document currency

    END OF gt_vbak.

    ----


    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 * INTO CORRESPONDING FIELDS OF TABLE gt_vbak

    FROM vbak

    UP TO p_max ROWS

    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.

    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

    Thanks.

    Ramya.

    Add comment
    10|10000 characters needed characters exceeded

    • please follow the steps below ..

      Assuming your internal table has the 2 fields

      total type DMBTR and

      WAERK type WAERK

      ..

      In your field catalog for totals should contain these fields ....

      wa_field-fieldname = 'TOTALS'.

      wa_field-cfieldname = 'WAERK'.

      wa_field-do_sum = 'X'.

      In your layout add line

      wa_layout-no_totalline = 'X'.

      Hope this solves your problem..

  • avatar image
    Former Member
    Apr 26, 2010 at 11:20 AM

    REFRESH gt_sort.

    CLEAR wa_sort.

    wa_sort-fieldname = 'fieldname'.<-----that you want to sort and subtotal

    wa_sort-up = 'X'.

    wa_sort-subtot = 'X'.

    wa_sort-tabname = 'IT_OUTPUT'.

    APPEND wa_sort TO gt_sort.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = g_repid

    i_callback_top_of_page = 'TOP_OF_PAGE'

    is_layout = gt_layout

    it_fieldcat = it_fcat

    it_sort = gt_sort[]

    TABLES

    t_outtab = it_output.

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 13, 2011 at 01:18 PM

    Hi,

    You have to hide Total Line in the layout structure

    Ex: IS_LAYOUT-NO_TOTALLINE = 'X'.

    Regards,

    Moqeeth.

    Add comment
    10|10000 characters needed characters exceeded