How to create Custom Buttons in NextTables

With NextTables Version 7.0, you can use a BAdI to add a user-defined button to the context menu or top menu. You can use this button to add custom functions in the back or front end. For example, user can execute a process chain at the push of a button or check its status. In addition, the user can differentiate whether all data or only the selected rows should be considered. After execution, messages can also be displayed to the user.

Custom Buttons example

Custom Buttons Parameter

Custom buttons can be created using the META Method of the Table Maintenance BAdI. In the article “How to implement a BAdI for NextTables” you will learn how to create a BAdI.

Following parameters must be defined: NAME, DESCR, ACTION and LOCATION. NAME represents the ID of the respective button, which can be used to differentiate the button pressed by the user and in defining submenus. DESCR represents the description of the button shown to the user.

ACTION parameter defines the action to be executed after the buttons was pressed. It can contain following values:

  • SEND_ALL - Constant CO_ACTION_SEND_ALL - Send all data for update (all data as if the user would click “Select all” checkbox. Meaning any local filter is applied). The values sent can be read in the Update Exit.
  • SEND_SEL - Constant CO_ACTION_SEND_SEL - Send selected rows for update
  • BUTTON - Constant CO_ACTION_BUTTON - Send the name of button clicked as I_BUTTON parameter. In the Update Exit, you can evaluate the I_BUTTON value and implement custom logic, for example start a process chain.
  • NO_ACTION - Constant CO_ACTION_NO_ACTION - No action (menu entry only). Used for submenus.

LOCATION parameter defines whether the button appears in the top or context menu. It can contain following values:

  • TOP - Constant CO_LOCATION_TOP - Top Menu
  • CONTEXT - Constant CO_LOCATION_CONTEXT - Context Menu

Furthermore, child entries in submenus contain parameters SORT_ORDER and PARENT. PARENT defines the top node of the menu, while SORT_ORDER influences the sequence of the entries. SORT_ORDER can be any numerical value.

How to leverage Custom Buttons?

Custom Button create a variety of options. You can read the value sent in the Update Exit and manipulate them based on a custom logic. There are no limits to the imagination. For example, you can implement a process that does something specific to selected rows like setting a status.

Read sent values

Furthermore, using the BUTTON action, you can evaluate the button name using the I_BUTTON parameter and execute another functionality for each button. For instance, you can start one process chain with the first button and another with the second. Using the third button, you can check the status of the first process chain and send a message to the user. Below you can find a code snippet as an example for process chain execution.

   METHOD /nly/if_editor~set_update_exit.

IF i_button IS NOT INITIAL.
CASE i_button.
WHEN 'BUTTON_URL_T_1' .
CALL FUNCTION 'RSPC_CHAIN_START'
EXPORTING
i_chain = 'ZDRS_PC_ZDREXMPL1'.
WHEN 'BUTTON_URL_T_2' .
CALL FUNCTION 'RSPC_CHAIN_START'
EXPORTING
i_chain = 'ZDRS_PC_ZDREXMPL2'.
ENDCASE.
ENDIF.

ENDMETHOD.

 

Submenu

You can also create submenus to group multiple custom buttons. Please note, that the parent node’s ACTION parameter must have NO_ACTION as value. Please refer to the code snippet below as an example.

  METHOD /nly/if_editor~set_meta_exit.

ch_s_table_info-buttons = VALUE #( BASE ch_s_table_info-buttons
"TOP MENU ENTRIES
( name = 'NO_ACTION_T' descr = 'Start Process Chain' action = /nly/cl_table_rest_v3=>co_action_no_action location = /nly/cl_table_rest_v3=>co_location_top )

"TOP MENU CHILD ENTRIES
( name = 'BUTTON_URL_T_1' descr = 'Process Chain 1' action = /nly/cl_table_rest_v3=>co_action_button location = /nly/cl_table_rest_v3=>co_location_top sort_order = '0' parent = 'NO_ACTION_T' )
( name = 'BUTTON_URL_T_2' descr = 'Process Chain 2' action = /nly/cl_table_rest_v3=>co_action_button location = /nly/cl_table_rest_v3=>co_location_top sort_order = '1' parent = 'NO_ACTION_T' )
).


ENDMETHOD.

Submenu Top

Submenus for the context menu work in the same way.

  METHOD /nly/if_editor~set_meta_exit.

ch_s_table_info-buttons = VALUE #( BASE ch_s_table_info-buttons
"CONTEXT MENU ENTRIES
( name = 'NO_ACTION_C' descr = 'Start Process Chain' action = /nly/cl_table_rest_v3=>co_action_no_action location = /nly/cl_table_rest_v3=>co_location_context )

"CONTEXT MENU CHILD ENTRIES
( name = 'BUTTON_URL_C_1' descr = 'Process Chain 1' action = /nly/cl_table_rest_v3=>co_action_button location = /nly/cl_table_rest_v3=>co_location_context sort_order = '0' parent = 'NO_ACTION_C' )
( name = 'BUTTON_URL_C_2' descr = 'Process Chain 2' action = /nly/cl_table_rest_v3=>co_action_button location = /nly/cl_table_rest_v3=>co_location_context sort_order = '1' parent = 'NO_ACTION_C' )
).

ENDMETHOD.

Submenu context

Localization

You can also localize your buttons and display a different description, based on the logon language selected by the user. Please refer to the code snippet below for orientation. If the user selected English as language, English description is shown. Otherwise the description is shown in German.

  METHOD /nly/if_editor~set_meta_exit.

DATA: lv_send_all TYPE string.

IF sy-langu = 'E'.
lv_send_all = 'Send all data'.
ELSE.
lv_send_all = 'Alle Daten senden'.
ENDIF.

ch_s_table_info-buttons = VALUE #(
"TOP MENU ENTRIES
( name = 'SEND_ALL_T' descr = lv_send_all action = /nly/cl_table_rest_v3=>co_action_send_all location = /nly/cl_table_rest_v3=>co_location_top )
).

ENDMETHOD.

Localized button

Same button in german

Code Snippet for all Buttons

Below you can use a code snippet contained all buttons, which you can use as reference for you own BAdIs.

  METHOD /nly/if_editor~set_meta_exit.
ch_s_table_info-buttons = VALUE #( BASE ch_s_table_info-buttons
"TOP MENU ENTRIES
( name = 'SEND_ALL_T' descr = 'Send all' action = /nly/cl_table_rest_v3=>co_action_send_all location = /nly/cl_table_rest_v3=>co_location_top )
( name = 'SEND_SEL_T' descr = 'Send selected' action = /nly/cl_table_rest_v3=>co_action_send_sel location = /nly/cl_table_rest_v3=>co_location_top )
( name = 'BUTTON_T' descr = 'Custom Function' action = /nly/cl_table_rest_v3=>co_action_button location = /nly/cl_table_rest_v3=>co_location_top )
( name = 'NO_ACTION_T' descr = 'Start Process Chain' action = /nly/cl_table_rest_v3=>co_action_no_action location = /nly/cl_table_rest_v3=>co_location_top )
"TOP MENU CHILD ENTRIES
( name = 'BUTTON_URL_T_1' descr = 'Process Chain 1' action = /nly/cl_table_rest_v3=>co_action_button location = /nly/cl_table_rest_v3=>co_location_top sort_order = '0' parent = 'NO_ACTION_T' )
( name = 'BUTTON_URL_T_2' descr = 'Process Chain 2' action = /nly/cl_table_rest_v3=>co_action_button location = /nly/cl_table_rest_v3=>co_location_top sort_order = '1' parent = 'NO_ACTION_T' )
"CONTEXT MENU ENTRIES
( name = 'SEND_ALL_C' descr = 'Send all' action = /nly/cl_table_rest_v3=>co_action_send_all location = /nly/cl_table_rest_v3=>co_location_context )
( name = 'SEND_SEL_C' descr = 'Send selected' action = /nly/cl_table_rest_v3=>co_action_send_sel location = /nly/cl_table_rest_v3=>co_location_context )
( name = 'BUTTON_C' descr = 'Custom Function' action = /nly/cl_table_rest_v3=>co_action_button location = /nly/cl_table_rest_v3=>co_location_context )
( name = 'NO_ACTION_C' descr = 'Start Process Chain' action = /nly/cl_table_rest_v3=>co_action_no_action location = /nly/cl_table_rest_v3=>co_location_context )
"CONTEXT MENU CHILD ENTRIES
( name = 'BUTTON_URL_C_1' descr = 'Process Chain 1' action = /nly/cl_table_rest_v3=>co_action_button location = /nly/cl_table_rest_v3=>co_location_context sort_order = '0' parent = 'NO_ACTION_C' )
( name = 'BUTTON_URL_C_2' descr = 'Process Chain 2' action = /nly/cl_table_rest_v3=>co_action_button location = /nly/cl_table_rest_v3=>co_location_context sort_order = '1' parent = 'NO_ACTION_C' )
).
ENDMETHOD.

Technical Tutorials

Do you have a question regarding NextTables?