Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Sub total in OO ALV

Former Member
0 Kudos
155

Here is how i am getting my ALV output



DATA:      gt_fieldcat TYPE lvc_t_fcat,
               wa_fieldcat TYPE lvc_s_fcat.

  wa_layout-grid_title = sy-title.
  wa_layout-zebra      = 'X'.
  wa_layout-cwidth_opt = 'X'.
  wa_layout-sel_mode   = 'A'.
  wa_layout-info_fname = 'COLOR'.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'ZPS_NI_SAVING'
    CHANGING
      ct_fieldcat      = gt_fieldcat.

  CALL METHOD alv_grid->set_table_for_first_display
      EXPORTING
        i_structure_name              = 'ZPS_NI_SAVING'
        is_layout                     = wa_layout
*      it_toolbar_excluding          = t_ui_functions
      CHANGING
        it_outtab                     = it_output
        it_fieldcatalog               = gt_fieldcat
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

Structure ZPS_NI_SAVING contains

DIVISION

DIVISION_TXT

COST_CENTRE

PERNR

LEVEL

SCHEME

EES_SACRIFICE

ERS_CONTRIB

NI_SAVING

TOTAL_PEN_SAV

I want the subtotal of EES_SACRIFICE and ERS_CONTRIB for DIVISION

Please let me know how to get the subtotals

1 ACCEPTED SOLUTION

Former Member
0 Kudos
108

Hi,

data: gt_sort type LVC_T_SORT.

data: w_sort like line of gt_sort.

Just loop at athat fieldcat and pass the do-sum = 'X'.

Loop at gt_fieldcat into gw_fieldcat.

if gw_fieldcat-fieldname = 'DIVISION'.

gw_fieldcat-do_sum = 'X'.

modify gt_fieldcat from gw_fieldcat transportiong do_sum.

endif.

endloop.

W_SORT-FIELDNAME = 'EES_SACRIFICE'

W_SORT-UP = 'X'.

W_SORT-SUBTOT = 'X'.

APPEND W_SORT TO GT_SORT.

W_SORT-FIELDNAME = 'ERS_CONTRIB'

W_SORT-UP = 'X'.

W_SORT-SUBTOT = 'X'.

APPEND W_SORT TO GT_SORT.

Pass this gt_sort to IT_SORT in the method set_table_for_first_display.

I think it will be useful for you.

\[removed by moderator\]

Thanks & regards

Deepika

Edited by: Jan Stallkamp on Jun 10, 2008 1:42 PM

4 REPLIES 4

Former Member
0 Kudos
108

Hi,

Fill sortcat. In sortcat u wil find total .

fill total = 'X'

0 Kudos
108

I have found that i need to pass internal table of the type LVC_T_SORT

in my method

can you specify what to pass for what fields of my output?

Former Member
0 Kudos
109

Hi,

data: gt_sort type LVC_T_SORT.

data: w_sort like line of gt_sort.

Just loop at athat fieldcat and pass the do-sum = 'X'.

Loop at gt_fieldcat into gw_fieldcat.

if gw_fieldcat-fieldname = 'DIVISION'.

gw_fieldcat-do_sum = 'X'.

modify gt_fieldcat from gw_fieldcat transportiong do_sum.

endif.

endloop.

W_SORT-FIELDNAME = 'EES_SACRIFICE'

W_SORT-UP = 'X'.

W_SORT-SUBTOT = 'X'.

APPEND W_SORT TO GT_SORT.

W_SORT-FIELDNAME = 'ERS_CONTRIB'

W_SORT-UP = 'X'.

W_SORT-SUBTOT = 'X'.

APPEND W_SORT TO GT_SORT.

Pass this gt_sort to IT_SORT in the method set_table_for_first_display.

I think it will be useful for you.

\[removed by moderator\]

Thanks & regards

Deepika

Edited by: Jan Stallkamp on Jun 10, 2008 1:42 PM

Former Member
0 Kudos
108

Hi,

You need to fill i_sort internal table of type LVC_T_SORT, there you can pass 'FIELDNAME' and pass 'X' to 'SUBTOT', then last pass this internal table to IT_SORT of method 'SET_TABLE_FOR_FIRST_DISPLAY'.

Before this you need to pass 'X' to the field DO_SUM of field catelog.

Check the below code.....

wa-Fieldname = 'MATNR'.

wa-SORT = 'X'.

wa-up = 'X'.

append wa to i_sort.

Rgds,

Bujji