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

to make changes one by one. Using an interactive ALV grid is almost as easy as

(gasp) a spreadsheet!

Here, SAP is very clear: with CL_SALV_TABLE, you cannot have an editable grid. It

is impossible. It cannot be done. From a purely technical point of view, this

seems really strange, because at the heart of CL_SALV_TABLE there’s an embedded

instance of CL_GUI_ALV_GRID, which of course can be editable. The problem (for

us programmers) is that the business will come to you with a request for a readonly

report, you’ll program it using the SALV reporting framework (as SAP recommends),

and right at the end—just be fore you think the project is over—the

business will say, “Oh, and can we make a few columns editable?”

SAP’s official position is that you should always use CL_GUI_ALV_GRID, not the

SALV framework, for this purpose. But here’s a little secret: you can make the

SALV object editable.

In order to do so, you have to go through the following steps:

1. You need to create custom class ZCL_SALV_MODEL, inheriting from the standard

SAP class but able to export the underl ying grid object from a linked SALV

report object.

2. Next, the INITIALIZE method of ZCL_BC_VIEW_SALV_TABLE is changed to link

together the instance of the SALV report object and the custom ZCL_SALV_MODEL

class.

3. Then, you code a method in the ZCL_SALV_MODEL to extract the underlying grid

object from the linked SALV report object.

4. Next, you can change the calling program to invoke the report using a method

that automatically creates a container; you want to prog rammatically change

the user commands to add an edit_me command.

5. Finally, you bring all this together and code some user command handling such

that when a user clicks a Make This Editable button, he can in fact edit the

data.

10.4.1 Creating a Custom Class to Hold the Standard SALV Model

Class

In order to make a SALV object editable, you need to be able to access the underlying

CL_GUI_ALV_GRID instance. Where that grid object normally lives is in standard

448

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

Saved successfully!

Ooh no, something went wrong!