Author: Thomas Jung
Submitted: April 12, 2007
The same person who had asked me how to hook an event handler into the standard ALV APPEND/INSERT buttons came back a day later and had a good follow up question. He said that he had the eventing and everything working just great on his first ALV component, but now he had a new requirement: he needed to be able to use more than one ALV within the same view.
This is not difficult to do at all, so I set out to adjust the first example by adding in a tabstrip. In one tab I would display SFLIGHT in an ALV. In the second tab I would display the contents of a related sample table - SBOOK in another ALV component.
- We start off be declaring a second component usage for the same SALV_WD_TABLE component. This works fine because each usage gets its own unique name (you will see in moment how this effects access to the component via coding). This is like in OO when you have the same class, but you want to have two or more instances of the class. You just create two different object references.
- The same holds true for the Used Controllers/Components references at teh controller or view level. You just need to add the second component usage.
- Now we can adjust the initialization coding in the DOINIT method of the Component Controller. The component controller class is generated, so it has methods to reflect the names of each component usage. In the earlier example we accessed the component usage named ALV via the method WD_CPUSE_ALV. To access the second usage named 2ND_ALV, we use the method that was generated for this name - WD_CPUSE_2ND_ALV. Pretty Cool!
- Next we will change the design of our view to have the tabstrip. In side each tab, we will place a ViewUIElementContainer.
- From the window maintenance, each separate container is available. Inside each we can place the appropriate ALV Component Usage.
- It is even possible to go back to the view and have separate event handlers for each inner ALV component usage. That way we have a nice clear association between event handler methods and the objects they are listed for events from.
- Finally you can see that the example results in two completely independent instances of the ALV Component running within the same view. We used a tab strip to separate them in this example, but there is really no reason why they couldn't have even be side by side.
If you would like to import the entire Web Dynpro Component of this example; the following is a link to a SAPlink SLNK file that contains the project. You will need at least the 1.3 version of SAPlink and the Web Dynpro Component plug-in to import the SLNK.