How to set the cell type as button in the SAP ALV List?

Button: The cell type of cl_gui_alv_grid=>mc_style_button resembles as a button in the user interface of the SAP ALV list. As the user clicks this button, any event can be executed like opening up a new window.

Dropdown List: It is used to provide a list of values as a dropdown list.

IMPLEMENTATION OF BUTTON:

              The following steps are necessary to implement the Button

  1. Extend the Internal table with the additional field of type LVC_T_STYL.
  2. Set the fields fieldname, style of lvc_t_styl to each row of the ALV List. The column is specified in the fieldname.
  3. The stylename field of the layout is assigned with the field style component.
  • Extension of Internal table with Fieldstyle component.

TYPES: BEGIN OF ty_contact.

              INCLUDE STRUCTURE ztt_db_table2.

TYPES: fieldstyle TYPE lvc_t_styl.

              END OF ty_contact.

  • Set the column in the SAP ALV List with the field style ‘cl_gui_alv_grid=>mc_style_button’.

DATA lt_contact TYPE TABLE OF ty_contact.

DATA ls_style TYPE lvc_s_styl.

FIELD_SYMBOLS <ls_contact> TYPE ty_contact.

LOOP AT lt_contact ASSIGNING <ls_contact>.

              ls_style-fieldname = ‘CONTACT_NAME’.

              ls_style-style = cl_gui_Alv_grid =>mc_style_button.

              APPEND ls_style TO <ls_contact>-fieldstyle.

ENDLOOP.

  • Setting the stylename field of the layout.

ls_layout-stylename = ’FIELDSTYLE’.