Thursday, August 12, 2010

Multiple ALV grids in Single report Output

How to display two different ALV grids in single output report.


************************************************************************
*                       ALV DECLARATION                                *
************************************************************************
DATA: i_fieldcatalog TYPE slis_t_fieldcat_alv,
      w_layout       TYPE slis_layout_alv,
      w_eve          TYPE slis_alv_event,
      i_eve          TYPE slis_t_event,
      i_sort         TYPE slis_t_sortinfo_alv,
      i_grid_event   TYPE slis_t_event,
* Internal table for ALV filter display rows
      i_filter       TYPE slis_t_filter_alv,
      w_grid_event   TYPE slis_alv_event,
      w_variant      LIKE disvariant,
      i_icons        TYPE slis_t_extab.



Initiate Top of page Events for each ALV lists: 
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE1
*&---------------------------------------------------------------------*
FORM top_of_page1.

  FORMAT COLOR COL_NEGATIVE.
  WRITE:/ 'Error Report:'.
  FORMAT COLOR OFF .

ENDFORM"top_of_page

*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE2
*&---------------------------------------------------------------------*
FORM top_of_page2.

  FORMAT COLOR COL_POSITIVE.
  WRITE / 'Success Report:'.
  FORMAT COLOR OFF.

ENDFORM"top_of_page


Build field catalogs for each ALV grid.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELD_CATALOG_E
*&---------------------------------------------------------------------*

*
FORM build_field_catalog_e .

  DATA: l_position      TYPE  i,
        lw_fieldcatalog TYPE  slis_fieldcat_alv.

  CONSTANTS: c_table(7VALUE 'I_ERROR',
             c_fcval1(5VALUE 'BBYNR'.

  CLEAR lw_fieldcatalog.
  l_position = l_position + 1.
  lw_fieldcatalog-fieldname = c_fcval1.        "'BBYNR'.
  lw_fieldcatalog-tabname   = c_table.
  lw_fieldcatalog-col_pos   = l_position.
  lw_fieldcatalog-seltext_l  = text-012.     "'Bonus Buy'.
  lw_fieldcatalog-outputlen  = '12'.
  APPEND lw_fieldcatalog TO i_fieldcatalog.

  CLEAR lw_fieldcatalog.
  l_position = l_position + 1.
  lw_fieldcatalog-fieldname = c_fcval25.        "'VKORG'.
  lw_fieldcatalog-tabname   = c_table.
  lw_fieldcatalog-col_pos   = l_position.
  lw_fieldcatalog-seltext_l  = text-041.     "'Sales Org'.
  APPEND lw_fieldcatalog TO i_fieldcatalog.


ENDFORM.                    " BUILD_FIELD_CATALOG_E



Here is the sample code:


  DATA lv_repid LIKE sy-repid.
* Start of Multiple ALV steps
  lv_repid = sy-repid.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
    EXPORTING
      i_callback_program = lv_repid.

  REFRESH: i_fieldcatalog[],i_eve.
  CLEAR: w_eve.
  w_eve-name = 'TOP_OF_PAGE'.
  w_eve-form = 'TOP_OF_PAGE1'.
  APPEND w_eve TO i_eve.

  PERFORM build_field_catalog_e.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      is_layout   = w_layout
      it_fieldcat = i_fieldcatalog[]
      i_tabname   = 'I_ERROR'
      it_events   = i_eve
    TABLES
      t_outtab    = i_error[].

  REFRESH: i_fieldcatalog[],i_eve.
  CLEAR: w_eve.
  w_eve-name = 'TOP_OF_PAGE'.
  w_eve-form = 'TOP_OF_PAGE2'.
  APPEND w_eve TO i_eve.

  PERFORM build_field_catalog.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      is_layout   = w_layout
      it_fieldcat = i_fieldcatalog[]
      i_tabname   = 'I_FINAL'
      it_events   = i_eve
    TABLES
      t_outtab    = i_final[].

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.




No comments:

Post a Comment