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.

Editing Data 10.4

SAP class CL_SALV_MODEL_LIST, but the problem is that the grid instance is private

and thus cannot be read.

To get around this, create a new class: ZCL_SALV_MODEL, inheriting from CL_SALV_

MODEL_LIST. Then give this new class a private attribute, MO_MODEL, which is typed

as an instance of CL_SALV_MODEL. This attribute is populated during construction,

as shown in Listing 10.28. The actual value coming in will be a model object that

knows all about the SALV report object.

METHOD constructor.

super->constructor( ).

mo_model = io_model.

ENDMETHOD.

Listing 10.28 Adding the Standard SALV Model to a Custom Class

10.4.2 Changing the Initialization Method of

ZCL_BC_VIEW_SALV_TABLE

Section 10.4.1 explained the process of adding an attribute, MO_SALV_MODEL, to the

custom SALV view class. Now change the end of the INITIALIZE method in order

to link the CL_SALV_TABLE instance with the CL_SALV_MODEL instance object (Listing

10.29).

set_handlers( ).

DATA: lo_salv_model TYPE REF TO cl_salv_model.

"Narrow casting

"CL_SALV_MODEL is a superclass of CL_SALV_TABLE

"Target = LO_SALV_MODEL = CL_SALV_MODEL

"Source = MO_ALV_GRID = CL_SALV_TABLE

lo_salv_model ?= mo_alv_grid.

"Object to access underlying CL_GUI_ALV_GRID

CREATE OBJECT mo_salv_model

EXPORTING io_model = lo_salv_model.

Listing 10.29 Changing the INITIALIZE Method to Store an ALV Grid Object

10.4.3 Adding a Method to Retrieve the Underlying Grid Object

In the class ZCL_SALV_MODEL, add a method called GET_ALV_GRID, which returns an

instance of CL_GUI_ALV_GRID. In Listing 10.30, the instance MO_MODEL is linked to

the SALV report object. You now have a lovely MVC construct. The view in this

449

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

Saved successfully!

Ooh no, something went wrong!