In this blog I would like to talk about the class

CL_ALV_GRID_XT

which is an extension of the ALV grid class CL_GUI_ALV_GRID.This class provides the following additional functions

1.

A BADI

ALV_GRID_XT

is provided which can be used for customizing the ALV grid before displaying.

2.

Provides a toolbar management class

CL_ALV_GRID_TOOLBAR_MANAGER

for ALV toolbar administration.

3.

Output optimization (hide empty columns)
Using function module

ALV_OPTIMIZE_OUTPUT

In this blog I would like to demonstrate a small example implementing the BADI ALV_GRID_XT functionality of the ALV extension class.

1.Creating BADI Filter entry in table TALV_GRID

2. Implement the BADI ALV_GRID_XT IN SE19 transaction

A. Define the filter in the implementation

B. Define the implementing class

C. Class ZCL_BADI_EXT

-emphasize = ‘X’.

      WHEN OTHERS.

    ENDCASE.

  ENDLOOP.

*Change the layout

  cs_layout-zebra      = ‘X’.

  cs_layout-cwidth_opt = ‘X’.

ENDMETHOD.

METHOD on_toolbar .

  • In this method you can manipulate the toolbar that was provided

  • by the application that created the ALV grid, e.g. add your

  • own toolbar buttons

  •   Add application specific toolbar functions

  DATA: ls_tb TYPE stb_button.

  ls_tb-butn_type = 3.

  INSERT ls_tb INTO e_object->mt_toolbar INDEX 1.

  ls_tb-function  = ‘BUTTON1’.

  ls_tb-icon      =  icon_alert.

  ls_tb-quickinfo = ‘This is button 1’.

  ls_tb-butn_type = ‘0’.

  INSERT ls_tb INTO e_object->mt_toolbar INDEX 1.

  ls_tb-function  =  ‘BUTTON2’.

  ls_tb-icon      =  icon_bw_ra_setting_active.

  ls_tb-quickinfo = ‘This is button2’.

  ls_tb-butn_type = ‘0’.

  INSERT ls_tb INTO e_object->mt_toolbar INDEX 1.

  ls_tb-function  =  ‘BUTTON3’.

  ls_tb-icon      =  icon_close.

  ls_tb-quickinfo = ‘This is button3’.

  ls_tb-butn_type = ‘0’.

  APPEND ls_tb TO e_object->mt_toolbar.

ENDMETHOD.                    “ON_TOOLBAR

METHOD on_user_command .

  • In this method you can handle the function codes of toolbar buttons

  • that were added in the on_toolbar method

  CASE e_ucomm.

    WHEN ‘BUTTON1’.

      MESSAGE i000(0k) WITH ‘This is “ALERT” for fcode’ e_ucomm.

    WHEN ‘BUTTON2’.

      MESSAGE i000(0k) WITH ‘This is “SETTING” for fcode’ e_ucomm.

    WHEN ‘BUTTON3’.

      MESSAGE i000(0k) WITH ‘This is “CLOSE” for fcode’ e_ucomm.

  ENDCASE.

ENDMETHOD.

Test program using the CL_ALV_GRID_XT Class

REPORT  zcl_alv_grid_xt.DATA :ref_alv_ext   TYPE REF TO cl_alv_grid_xt,gt_sflight    TYPE TABLE OF sflight,gt_fcat       TYPE lvc_t_fcat,gwa_layout    TYPE lvc_s_layo,gv_gridid     TYPE talv_gridt-id VALUE ‘ZBADI_EXT’.SELECTION-SCREEN BEGIN OF SCREEN 9000.SELECTION-SCREEN END OF SCREEN 9000.START-OF-SELECTION.*Get the fieldcatalog  CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE’    EXPORTING      i_structure_name       = ‘SFLIGHT’    CHANGING      ct_fieldcat            = gt_fcat[]    EXCEPTIONS      inconsistent_interface = 1      program_error          = 2      OTHERS                 = 3.  IF sy-subrc <> 0.    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.  ENDIF.*Select some data  SELECT * FROM sflight INTO TABLE gt_sflight UP TO 15 ROWS.*Create an entry in TALV_GRID table for calling the BADI Methods*Create ALV Ext object  CREATE OBJECT ref_alv_ext    EXPORTING      i_parent          = cl_gui_container=>screen0      i_grid_id         = gv_gridid      i_toolbar_manager = ‘X’      i_optimize_output = space    EXCEPTIONS      error_cntl_create = 1      error_cntl_init   = 2      error_cntl_link   = 3      error_dp_create   = 4      grid_id_invalid   = 5      OTHERS            = 6.*Here as the grid ID is set the methods from the BADI(ALV_GRID_XT)*implementiong class ZCL_BADI_EXT are called*BADIs can be implemented using the transaction SE19.You can see*the definition in SE18*The BADI Filter is ZBADI_EXT defined in the table TALV_GRID*Display the ALV  CALL METHOD ref_alv_ext->set_table_for_first_display    EXPORTING      i_structure_name              = ‘SFLIGHT’      is_layout                     = gwa_layout    CHANGING      it_outtab                     = gt_sflight      it_fieldcatalog               = gt_fcat    EXCEPTIONS      invalid_parameter_combination = 1     program_error                 = 2      too_many_lines                = 3      OTHERS                        = 4.*Call the selection screen  CALL SELECTION-SCREEN 9000.

Additional Information

These additional functions are activated by the following parameters defined in the constructor of this class :

• I_GRID_ID

An entry from the TALV_GRID table is expected here. If this entry exists, then before executing the SET_TABLE_FOR_FIRST_DISPLAY or REFRESH_TABLE_DISPLAY methods, those methods from BADI ALV_GRID_XT that have the same names are called up.

• I_TOOLBAR_MANAGER

‘X’ = Switches on 3-level toolbar management

• I_OPTIMIZE_OUTPUT

‘X’ = Switches on display optimization, using the ALV_OPTIMIZE_OUTPUT function module.

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !