14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Adding Custom Command Icons Programmatically 10.3

Finally, the program calls a method to add the table of your custom commands to

the toolbar.

*---------------------------------------------------------------*

* If we have a container, then we can add our own user-defined

* commands programmatically, but we cannot edit the data

*---------------------------------------------------------------*

IF io_container IS SUPPLIED AND

io_container IS BOUND.

cl_salv_table=>factory(

EXPORTING

r_container = io_container

IMPORTING

r_salv_table = mo_alv_grid

CHANGING

t_table = ct_data_table[] ).

display_basic_toolbar( ).

IF it_user_commands[] IS NOT INITIAL.

add_commands_to_toolbar( it_user_commands ).

ENDIF.

Listing 10.25 Revised INITIALIZE Method

10.3.4 Adding the Custom Commands to the Toolbar

Listing 10.26 shows how you actually pass the list of user commands into the MO_

FUNCTIONS object of SALV, which is in chargeof keeping track of any user-defined

functions that have been added. For each command, you pass in what the icon

should look like, a text description, and a tooltip (if you so desire).

METHOD add_commands_to_toolbar.

* Local Variables

DATA: ls_commands LIKE LINE OF it_commands,

ld_icon TYPE string,

ld_tooltip TYPE string,

ld_text TYPE string.

TRY.

LOOP AT it_commands INTO ls_commands.

CHECK ls_commands-function <> '&IC1'.

ld_icon = ls_commands-icon.

ld_text = ls_commands-text.

ld_tooltip = ls_commands-quickinfo.

mo_functions->add_function(

name = ls_commands-function

icon = ld_icon

text = ld_text

445

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!