14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Designing a Report Interface 10.2

Setting Up Event Handling

Listing 10.6 sets the handlers, which me ans that it defines how user commands

are handled in the program.

set_handlers( ).

METHOD set_handlers.

mo_events = mo_alv_grid->get_event( ).

SET HANDLER handle_link_click

FOR mo_events.

SET HANDLER handle_user_command FOR mo_events.

ENDMETHOD.

Listing 10.6 Custom ALV Object: SET_HANDLERS Method

Forging the link between the events that are raised by the SALV objects is quite

complicated. The main SALV class contains an attribute within it (CL_SALV_EVENTS_

TABLE) that raises an event ( RAISE_LINK_CLICK) when a user clicks on a hotspot.

You need the code in Listing 10.6 to tell your newly created SALV object that the

HANDLE_LINK_CLICK method in your custom SALV class is going to respond to that

event. That declaration does half the job; the other step you need to do is to make

sure that the definition of the even t handler method links the event from CL_

SALV_EVENTS_TABLE to your custom event handling method. In SE24, select the

method HANDLE_LINK_CLICK of your custom cl ass and click on the Detail View

icon at the top of the list of methods. The result can be seen in Figure 10.5.

Setting up such a definition in the class gives the method the potential to be used

as an event handler, but it’s not actually used until a SET_HANDLER command is

used at runtime to subscribe to an event; that is, you activate the linkage between

a specific instance of the class that rais es the event and a specific instance of the

class that is to handle the event.

Now you’ve handled the case in which the user has clicked a hotspot, such as

clicking a monster number to display the monster master record. The other case

you have to deal with is one in which you’ve added your own buttons to the top

of the screen (the steps for doing this are explained in Section 10.3) and the user

has clicked one of them. Naturally, if the user clicks one of the standard buttons,

then the SALV class deals with that situation itself.

421

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

Saved successfully!

Ooh no, something went wrong!