Selective Handling of the Buttons in ALV Grid Toolbar

Selective Handling of the Buttons in ALV Grid Toolbar

Selective Handling of the Buttons in ALV Grid Toolbar

By and large, on the off chance that the necessity is to eliminate the entire ALV framework toolbar, it’s quite simple as it requires setting one field (no_toolbar) in format as ‘X’. Let’s dive into the Selective Handling of the Buttons in ALV Grid Toolbar.

ALV Toolbars

Setting the no_toolbar would give the result as beneath. Kindly check, there is NO Toolbar in the ALV Result.

No Toolbar in ALV Report

We can pass this design as bringing in boundary for strategy ‘set_table_for_first_display’.

Be that as it may, in the event of Article Arranged ALV, debilitating a few fastens and empowering some can get bit precarious.

The objective of this article is to give a comprehensive picture with regards to meeting this prerequisite and sort of make it a solitary complete perspective for all engineers who need some assistance on this point.

As displayed above, in design, there is a field to eliminate the entire toolbar and we have no simple method for handicapping only a couple of buttons from the toolbar list. Selective Handling of the Buttons in ALV Grid Toolbar.

However, every time it isn’t 1 or 0 100% of the time. Here and there, we really want a center way.

Handicapping of a portion of the buttons is a greater amount of the genuine prerequisite you will get in execution projects as ALV network toolbar is an exceptionally useful asset to use it for capabilities like arranging, sifting, trading information to yield and so on.

Yet, how to accomplish it?

OK!!! So the response to this is Occasion Controllers. That’s it!!! Presently on the off chance that you are a novice to Drain Improvement, the occasion overseer is finished in ALV report advancements. In this article, we will attempt to make sense of the ideas and subtleties of occasion overseers however much as could be expected so that regardless of whether you are a fresher, you ought to have the option to figure out it and effectively execute it.

On a significant level, this execution can be isolated into underneath steps:

Making of ALV Framework, Compartment (This item will be alluded from standard kinds given by SAP) and Occasion overseer protests (This article will allude to nearby class).

Meaning of Occasion Overseer class with the technique to deal with toolbar.

Execution of the strategy.

Setting of the occasion controller and its setting off components.

The primary arrangement is there in sync four so we will cover that at the last. Just to ensure you read the total article and figure out the general picture.

Presently prior to going any additionally we should initially get our ideas clear about occasions overseers.

Occasion overseers are strategies which get called once their separate occasions are set off.

This setting off should be possible by means of programming utilizing “raise_event” strategy for the network.

In the first place, we will make matrix variable concerning cl_gui_alv_grid. We would likewise require a compartment to consume this framework.

DATA :  gref_alvgrid TYPE REF TO cl_gui_alv_grid ,              
gref_ccontainer TYPE REF TO cl_gui_custom_container .

Once this is done we need to do the object creation.

*----Creating custom container instance
    CREATE OBJECT gref_ccontainer 
      EXPORTING
        container_name              = con_custom_control_name
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6.
    IF sy-subrc <> 0.
*--Exception handling
    ENDIF.
*   checking instance existence, creating instance, setting for first display and refreshing
*----Creating ALV Grid instance
    CREATE OBJECT gref_alvgrid
      EXPORTING
        i_parent          = gref_ccontainer
      EXCEPTIONS
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        OTHERS            = 5.
    IF sy-subrc <> 0
*--Exception handling
    ENDIF.

Now for event handling, we will create a local class lcl_event_handler in the program.

DATA gref_event_handler TYPE REF TO lcl_event_handler .

In the beneath neighborhood class we can make a technique that will deal with our toolbar handling. We acquainted two additional techniques purposefully with further explain our idea about occasion controllers.

Event Handler Class

Presently prior to going for execution, we will likewise perceive how we can set overseers for this strategy.

Set Event Handler
ucomm in sap

As referenced, to raise an occasion, we will set off occasions utilizing ‘raise_event’ strategy which will call handle_user_command from our neighborhood controller class. Further handling should be possible in this technique execution utilizing ‘ucomm’ boundary.

Aside from bringing the occasion up in our program with above strategy, a few unexpected occasions are remembered for standard SAP class CL_GUI_ALV_GRID.

Class CL_GUI_ALV_GRID will set off an occasion for toolbar inside through technique ‘SET_TABLE_FOR_FIRST_DISPLAY’ and we will deal with that brought occasion up in our nearby class strategy execution.

To show records in ALV we use strategy ‘SET_TABLE_FOR_FIRST_DISPLAY’ which calls technique ‘REFRESH_TABLE_DISPLAY’ which thusly calls strategy ‘SOFT_REFRESH_TABLE_DISPLAY’ that further calls strategy ‘SET_TOOLBAR’. This SET_TOOLBAR raises the occasion for toolbar taking care of.

We will deal with this occasion through our custom strategy.

Handle_toolbar strategy as e_object as bringing in boundary. Network toolbar data gets put away in table ‘e_object->mt_toolbar’. This data incorporates Capability, Symbol, Data, Kind of button, Cripple Banner and so on.

To handicap the button it is expected to alter this table ‘e_object->mt_toolbar’ with Cripple Banner with ‘X’. Comparatively to empower button which is crippled by Framework, this banner should be reset.

In beneath technique, we are handicapping not many buttons as well as empowering one button which was debilitating as a matter of course in the framework. Sections of this table will seem to be this.

disable toolbar buttons

Every one of the buttons with their data get put away in table ‘e_object->mt_toolbar’ as displayed underneath.

The end-product will look something like this.

In the event that you are a novice, underneath is the bit by bit process for you.

  1. Create a program in t-code SE38.

Go to t-code SE80 and create a Screen. (Selective Handling of the Buttons in ALV Grid Toolbar)

create a Screen

Give the screen number.

Give a description and hit the Layout.

Click on the Custom Control and drag it across to the layout. (Selective Handling of the Buttons in ALV Grid Toolbar)

how to create custom control in ALV

Give the Custom Control some name. We give it the name as CC_ALV. This name would be utilized in the program.

how to create custom control in ALV

In the program, we have given similar name to customs control.

This finishes the screen and customs control plan. Presently we want to compose our program to deal with it.

Use the below program (at the bottom of this article) and activate your code.

Let’s test it.

OOPs.. we get no output.

What did we miss?

Since your ALV Custom Holder showed nothing. Let us take a quick trip and see the PBO PAI screen.

Uncomment the PBO and PAI modules and retest.

OOPs, again no output.

What did we miss now?

On the off chance that you take a gander at the program intently, the MODULE Show has not yet been characterized in that frame of mind on the screen.

Go to the screen and add the Presentation module in PBO.

Presently test it one final time. At last, you can see the ALV yield.

If you have any desire to analyze, when Occasion Overseers, you would see the underneath distinction.

Trust this article was adequately clear to explain how to utilize custom regulators and compartments. You currently know how to utilize the occasion controllers. Likewise, it ought to have given you enough knowledge to deal with the device bar fastens unequivocally.

 

Complete Code Snippet.

*&---------------------------------------------------------------------*
*& Program to show ALV Grid Display with Some Toolbar buttons disabled *
*&---------------------------------------------------------------------*
REPORT ztest_alv_grid_test NO STANDARD PAGE HEADING
                  LINE-SIZE  132
                  LINE-COUNT 65.
*--------------------------------------------------------------------*
* Tables
*--------------------------------------------------------------------*
TABLES : mara.
*--------------------------------------------------------------------*
* Types
*--------------------------------------------------------------------*
TYPES : BEGIN OF tty_mara,
          matnr TYPE matnr,
          ernam TYPE ernam,
          mtart TYPE mtart,
          matkl TYPE matkl,
        END OF tty_mara.
*--------------------------------------------------------------------*
* Data
*--------------------------------------------------------------------*
DATA : g_tab_mara TYPE STANDARD TABLE OF tty_mara.
*--- Object for ALV grid
DATA gref_alvgrid TYPE REF TO cl_gui_alv_grid .
*--- Object for Custom container
DATA gref_ccontainer TYPE REF TO cl_gui_custom_container .
*--- Name of the custom control added on the screen
CONSTANTS con_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
*--- Field catalog
DATA g_tab_fieldcat TYPE lvc_t_fcat .
*--- Field catalog structure
DATA g_wa_fieldcat TYPE lvc_s_fcat .
*----Layout
DATA g_str_layout TYPE lvc_s_layo.
*--- Event handler class
CLASS lcl_event_handler DEFINITION DEFERRED.
*--- Object for Event Handler
DATA gref_event_handler TYPE REF TO lcl_event_handler .
*--------------------------------------------------------------------*
* Local Class Definition for Event Handler
*--------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
  PUBLIC SECTION .
    CLASS-DATA alv_err TYPE subrc.
    METHODS
*     Event handler for toolbar in alvgrid.
      handle_toolbar
                    FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING e_object.
ENDCLASS.
*--------------------------------------------------------------------*
* Local Class Implementation for Event Handler
*--------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION .
* Method for toolbar handling
  METHOD handle_toolbar.

    DATA : l_wa_toolbar TYPE stb_button.

*   Disabling some Buttons
    MOVE 'X' TO l_wa_toolbar-disabled.
*   This sets the data
    MODIFY e_object->mt_toolbar FROM l_wa_toolbar TRANSPORTING disabled
    WHERE function = '&DETAIL' OR function = '&MB_SUM' OR function = '&MB_VIEW'
    OR function = '&MB_SUBTOT' OR function = '&PRINT_BACK' OR function = '&COL0'
    OR function = '&GRAPH' OR function = '&INFO' OR function = '&REFRESH'
    OR function = '&LOCAL&CUT' OR function = '&LOCAL&COPY' OR function = '&LOCAL&PASTE'
    OR function = '&LOCAL&UNDO' OR function = '&LOCAL&APPEND' OR function = '&LOCAL&INSERT_ROW'
    OR function = '&LOCAL&DELETE_ROW' OR function = '&LOCAL&COPY_ROW' .

*   Enabling some Buttons
    MOVE ' ' TO l_wa_toolbar-disabled.
*   This sets the data
    MODIFY e_object->mt_toolbar FROM l_wa_toolbar TRANSPORTING disabled
    WHERE function = '&FIND_MORE'.

  ENDMETHOD.                    "handle_toolbar
ENDCLASS .

*--------------------------------------------------------------------*
* Selection Screen
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bm WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_matnr FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK bm.

*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION.
* Fetch data
  PERFORM get_testdatafordisplay.

*--------------------------------------------------------------------*
* End of Selection
*--------------------------------------------------------------------*
END-OF-SELECTION.
* Field Catalog
  PERFORM create_fieldcat CHANGING g_tab_fieldcat.
* Layout
  PERFORM create_layout CHANGING g_str_layout.
* Display Report
  PERFORM display_report.

*&---------------------------------------------------------------------*
*&      Form  GET_TESTDATAFORDISPLAY
*&---------------------------------------------------------------------*
FORM get_testdatafordisplay .
  SELECT matnr ernam mtart matkl
    FROM mara
  INTO CORRESPONDING FIELDS OF TABLE g_tab_mara
  WHERE matnr IN s_matnr  .
ENDFORM.                    " GET_TESTDATAFORDISPLAY
*&---------------------------------------------------------------------*
*&      Form  CREATE_FIELDCAT
*&---------------------------------------------------------------------*
FORM create_fieldcat CHANGING c_tab_fieldcat TYPE lvc_t_fcat.
  DATA : ls_fcat TYPE lvc_s_fcat.
  ls_fcat-col_pos = 0.
  ls_fcat-fieldname = 'MATNR'.
  ls_fcat-coltext = 'Material Number'.
  ls_fcat-seltext = 'Material Number'.
  ls_fcat-col_opt = 'X'.
  APPEND ls_fcat TO c_tab_fieldcat.
  ls_fcat-col_pos = 1.
  ls_fcat-fieldname = 'ERNAM'.
  ls_fcat-coltext = 'Created By'.
  ls_fcat-seltext = 'Created By'.
  ls_fcat-col_opt = 'X'.
  APPEND ls_fcat TO c_tab_fieldcat.
  ls_fcat-col_pos = 2.
  ls_fcat-fieldname = 'MTART'.
  ls_fcat-coltext = 'Material Type'.
  ls_fcat-seltext = 'Material Type'.
  ls_fcat-col_opt = 'X'.
  APPEND ls_fcat TO c_tab_fieldcat.
  ls_fcat-col_pos = 3.
  ls_fcat-fieldname = 'MATKL'.
  ls_fcat-coltext = 'Material Group'.
  ls_fcat-seltext = 'Material Group'.
  ls_fcat-col_opt = 'X'.
  APPEND ls_fcat TO c_tab_fieldcat.
ENDFORM.                    " CREATE_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  CREATE_LAYOUT
*&---------------------------------------------------------------------*
FORM create_layout CHANGING c_str_layout TYPE lvc_s_layo..
*  c_str_layout-no_toolbar = 'X'.
ENDFORM.                    " CREATE_LAYOUT

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_REPORT
*&---------------------------------------------------------------------*
FORM display_report .
  CALL SCREEN 100.
ENDFORM.                    " DISPLAY_REPORT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  DATA: l_var_valid      TYPE c,
        l_selected_cells TYPE STANDARD TABLE OF lvc_s_cell.

  CALL METHOD gref_alvgrid->check_changed_data
    IMPORTING
      e_valid = l_var_valid.

  CALL METHOD gref_alvgrid->get_selected_cells
    IMPORTING
      et_cell = l_selected_cells.

  CASE sy-ucomm.
    WHEN 'EXIT' OR 'ENDE' or 'ECAN'.
      LEAVE PROGRAM.
    WHEN 'BACK' OR 'E'.
      LEAVE TO SCREEN 0.
    WHEN 'INS'.
      CALL METHOD gref_alvgrid->raise_event
        EXPORTING
          i_ucomm = 'INS'.
    WHEN 'DELETE'.

    WHEN OTHERS.
  ENDCASE.

ENDMODULE.                 " DISPLAY  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  DISPLAY  OUTPUT
*&---------------------------------------------------------------------*
MODULE display OUTPUT.
  PERFORM display_test_alv.
ENDMODULE.                 " DISPLAY  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_TEST_ALV
*&---------------------------------------------------------------------*
FORM display_test_alv .
  IF gref_alvgrid IS INITIAL .
*----Creating custom container instance
    CREATE OBJECT gref_ccontainer
      EXPORTING
        container_name              = con_custom_control_name
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6.
    IF sy-subrc <> 0.
*--Exception handling
    ENDIF.
*   checking instance existence, creating instance, setting for first display and refreshing
*----Creating ALV Grid instance
    CREATE OBJECT gref_alvgrid
      EXPORTING
        i_parent          = gref_ccontainer
      EXCEPTIONS
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        OTHERS            = 5.
    IF sy-subrc <> 0.
*--Exception handling
    ENDIF.
*--Creating an instance for the event handler
    CREATE OBJECT gref_event_handler.
    SET HANDLER gref_event_handler->handle_toolbar FOR gref_alvgrid .

    CALL METHOD gref_alvgrid->set_table_for_first_display
      EXPORTING
        is_layout                     = g_str_layout
      CHANGING
        it_outtab                     = g_tab_mara
        it_fieldcatalog               = g_tab_fieldcat
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.
  ENDIF.
ENDFORM.                    " DISPLAY_TEST_ALV

 

YOU MAY LIKE THIS

What Companies Use SAP Software in India

AI and Machine Learning in SAP: A Practical Guide

Top SAP ABAP Reports Interview Questions: Be Prepared

Courses For Sap ABAP On HANA Training

 

WhatsApp WhatsApp us