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.

Adding Custom Command Icons Programmatically 10.3

10.3 Adding Custom Command Icons Programmatically

One thing you almost always want when cr eating a report program is to have a

few of your own icons at the top of th e screen to perform application-specific

tasks. For example, you may have a report that shows a list of monsters, and you

want the user to be able to select a monster using a checkbox and then click the

Rampage icon at the top of the screen to send the selected monster into a blind

frenzy, destroying everything in its path and becoming so angry that you lose

control of it and it kills every single living thing on the planet, including you.

That’s a reasonably common user requirement.

What you do not want if at all possible is to have to paint icons on some sort of

screen. This is what you have to do when using the REUSE_ALV function modules;

if you want to add extra icons at the top of the screen to respond to applicationspecific

functions (like rampage), then you have to create a custom STATUS and

change it each time you have a new co mmand. (This isn’t the end of the world

and you can exclude any functions you don’t want at runtime, but it still isn’t very

elegant.)

CL_SALV_TABLE cannot say at runtime what icons you want programmatically.

With CL_GUI_ALV_GRID, there’s no need for a custom STATUS at all. If you want

extra commands in the SALV reporting fr amework, then you can send a list of

icons programmatically to the view in a pop-up box—but not in the default full

screen view, which is the one you usuall y want for a report. In the full screen

case, you have to have a custom STATUS, which is a quantum leap backwards and

contrary to the whole OO initiative SAP is pushing.

I don’t take this sort of thing lying down , so I thought to myself, “I need a container

in order to add commands to my SALV report, and I don’t want to have to

manually create that container for each report.” Accordingly, this section walks

you through the steps needed to change your custom ZCL_BC_VIEW_SALV_TABLE

class and calling program such that you can add custom icons programmatically.

The steps in this process are as follows:

1. Create a method to automatically create a container.

2. Add a method to fill the container ob ject needed by the SALV with the container

just created; this also involves adding an interface to your view class and

creating a function module.

441

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

Saved successfully!

Ooh no, something went wrong!