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.

10

ALV SALV Reporting Framework

Next, if the user has chosen a display variant, then you want to make sure the

report comes out with the chosen column order and sorting and what have you:

set_layout( id_variant ).

In Listing 10.5, you’re setting up the layout by calling a big bunch of SALV methods.

First, you have to access the layout object so that you can make changes to

it. Then, you pass in the ca lling program: without this information, the program

cannot determine which variant to retrieve from the database, because there

might be identically-named display variants for different programs. Pass this into

the layout object, tell this object that if there is no user variant, then it should use

the default variant, and finally pass in the variant the user selected. You’ll notice

that Listing 10.5 includes a custom authority object to say whether a user can

change global display varian ts; generally, only central people (like business analysts)

should be authorized to change global variants.

METHOD set_layout.

* Local Variables

DATA: ls_key TYPE salv_s_layout_key.

mo_layout = mo_alv_grid->get_layout( ).

* Set the Layout Key

ls_key-report = sy-cprog.

mo_layout->set_key( ls_key ).

* set usage of default Layouts

mo_layout->set_default( 'X' ).

* set initial Layout

IF id_variant IS NOT INITIAL.

mo_layout->set_initial_layout( id_variant ).

ENDIF.

* Set save restriction

* Check authority to change display variants.

AUTHORITY-CHECK OBJECT 'Z_VARIANT1' ID 'ACTVT' FIELD '*'.

IF sy-subrc = 0. " does he ride a white horse?

mo_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).

" yes, allow user and global display variants

ELSE.

mo_layout->set_save_restriction( if_salv_c_layout=>restrict_user_

dependant ).

ENDIF.

ENDMETHOD.”Set Layout

Listing 10.5 Setting up the Layout

420

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

Saved successfully!

Ooh no, something went wrong!