How to set the cell type as hotspots or Links in SAP ALV Display

The cell type of CL_GUI_ALV_GRID->MC_STYLE_HOTSPOT enables the user to navigate to a new page or session. It can also open a new window or display a list. It appears as a Link in the SAP ALV List.

The following steps are necessary to implement the HOTSPOT / LINKS

  1. Extent 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 fieldstyle component.

  • Extension of Internal table with Fieldstyle component

TYPES: BEGIN OF ty_contact_link.

              INCLUDE STRUCTURE ztt_db_table2.

TYPES: fieldstyle TYPE lvc_t_styl,

              END OF ty_contact_link.

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

DATA lt_contact TYPE TABLE OF ty_contact_link.

DATA ls_style TYPE lvc_s_styl.

FIELD SYMBOLS <ls_contact> TYPE ty_contact_link.

LOOP AT lt_contact ASSIGNING <ls_contact>.

ls_style-fieldname = ‘CONTACT_NAME’.

ls_style-style = cl_gui_alv_grid => mc_style_hotspot.

APPEND ls_style TO <ls_contact>-fieldstyle.

ENDLOOP

  • Setting the stylename field of the layout.

ls_layout-stylename = ’FIELDSTYLE’.

Note: The hotspot can be activated throught the field HOTSPOT of field catalog. The field HOTSPOT of the field catalog is set to ‘X’. The key advantage of this field is that the user does not have to add any additional field to the Internal table.

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’.