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.

Designing a Report Interface 10.2

The idea here is to perform each step you would manually perform when creating

a SALV object, provided that each such step would always be performed without

exception and always in the same way.

Setting Up the Basic Report

First, you always need to create the SA

going anywhere (Listing 10.3).

LV object itself; without it, you’re not

cl_salv_table=>factory(

IMPORTING

r_salv_table = mo_alv_grid

CHANGING

t_table = ct_data_table[] ).

Listing 10.3 Creating the SALV Object

In contrast to the older technologies, the factory method makes no presumptions

as to whether you want all the love ly buttons at the top of the screen for

sorting and changing the display variant and the like. This is the single responsibility

principle: it’s factory’s job to create the report object, but it’s not its place

to make any other decisions, like whethe r you want useful buttons at the top of

the screen. In fact, you always do want such buttons, so call the method shown in

Listing 10.4 directly after creating the SALV object.

display_basic_toolbar( ).

METHOD display_basic_toolbar.

mo_functions = mo_alv_grid->get_functions( ).

mo_functions->set_all( if_salv_c_bool_sap=>true ).

ENDMETHOD.

Listing 10.4 Making Sure a Toolbar Appears at the Top of the Report

In case you want to change some column attributes later, now is a good time to

create the object that looks after the columns:

mo_columns = mo_alv_grid->get_columns( ).

If you don’t do this early on (and construction is nice and early), then you’d have

to keep calling the GET COLUMNS method every time you wanted to change a column,

which is painful, boring, and repetitive.

419

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

Saved successfully!

Ooh no, something went wrong!