Monday, December 20, 2010
IT_SORT table has to be passed through REUSE_ALV_GRID_DISPLAY.


REPORT zovh_alv_subtot.
DATA:
      BEGIN OF it_tab OCCURS 0,
        bukrs TYPE t001-bukrs,
        dmbtr TYPE dmbtr,
      END OF it_tab.
*ALV Declarations
TYPE-POOLS:slis.
TYPES:
      ty_fieldcat TYPE slis_fieldcat_alv,
      ty_events   TYPE slis_alv_event,
      ty_layout   TYPE slis_layout_alv,
      ty_sort     TYPE slis_sortinfo_alv.
DATA:
      wa_fieldcat TYPE ty_fieldcat,
      wa_events   TYPE ty_events,
      wa_layout   TYPE ty_layout,
      wa_sort     TYPE ty_sort.
DATA:
      it_events   TYPE STANDARD TABLE OF ty_events,
      it_fieldcat TYPE STANDARD TABLE OF ty_fieldcat,
      it_sort     TYPE STANDARD TABLE OF ty_sort.
DATA:
      g_program TYPE sy-repid.

START-OF-SELECTION.
  DO 100 TIMES.
    IF sy-index <= 20.
      it_tab-bukrs = 100.
      it_tab-dmbtr = 100.
    ELSEIF sy-index <= 50.
      it_tab-bukrs = 101.
      it_tab-dmbtr = 101.
    ELSE.
      it_tab-bukrs = 102.
      it_tab-dmbtr = 102.
    ENDIF.
    APPEND it_tab.
    CLEAR it_tab.
  ENDDO.

  DEFINE fieldcat.
    wa_fieldcat-fieldname = &1.
    wa_fieldcat-tabname   = &2.
    wa_fieldcat-seltext_m = &3.
    wa_fieldcat-do_sum    = &4.  "To get totals
    append wa_fieldcat to it_fieldcat.
    clear  wa_fieldcat.
  END-OF-DEFINITION.
  fieldcat:'BUKRS' 'IT_TAB' 'BUKRS' '',
           'DMBTR' 'IT_TAB' 'DMBTR' 'X'.

  wa_layout-colwidth_optimize = 'X'.

  "Events
  wa_events-name = 'TOP_OF_PAGE'.
  wa_events-form = 'TOP_OF_PAGE'.
  APPEND wa_events TO it_events.
  CLEAR wa_events.

  "Sort
  wa_sort-fieldname = 'BUKRS'.
  wa_sort-tabname   = 'IT_TAB'.
  wa_sort-up        = 'X'.     "Ascending order
  wa_sort-group     = '*'.     "Page break
  wa_sort-subtot    = 'X'.
  APPEND wa_sort TO it_sort.
  CLEAR wa_sort.
  g_program = sy-repid.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program = g_program
      is_layout          = wa_layout
      it_fieldcat        = it_fieldcat
      it_events          = it_events
      it_sort            = it_sort
    TABLES
      t_outtab           = it_tab. 

0 comments:

Post a Comment

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.