Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

Singleton

Solution

Chapter: Context at Runtime


Theme: Singleton

At the end of this Exercise, you will be able to:


• Create a supply method for a singleton context node

3 Developing

3-2 Build Context in the component controller

Locate the Component Controller node in


the project structure that is located
immediately under the component.
Double click on Component Controller to
open the Custom Controller editor.
• Add a new node to the Custom
Controller Context, having the
name BOOKINGTAB. Add the
new node directly under the node
FLIGHTTAB.
• On the popup Set the value for
Cardinality to 0..n, make sure that
Singleton has the valueYes, enter
SBOOK in the field Dictionary
structure and press Add Attribute
from structure.
• Choose fields bookid, customid,
custtype, luggweight, class and
passname and press Continue.

3-3 Create the supply function for the newly created context node
BOOKINGTAB
1
Singleton
Solution
Stay on the Context tab of the component controller and enter
BOOKINGS_READ as Supply Function for context node BOOKINGTAB.
Double-click on the supply function BOOKINGS_READ to navigate into the
editor.
Insert the source code for doing the following:
- Get the attributes of the parent element (= node FLIGHTTAB)
- Read the appropriate bookings from database table SBOOK into an
internal table.
Hint: Use carrid, connid and fldate in the where clause.
- Bind the internal table to the context node BOOKINGTAB.

method BOOKINGS_READ .

data:
Stru_flight type IF_COMPONENTCONTROLLER=>Element_Flightinfo,
Itab_Booking type IF_COMPONENTCONTROLLER=>Elements_Bookingtab.

* Get Parent Element


CALL METHOD parent_element->get_static_attributes
IMPORTING
STATIC_ATTRIBUTES = Stru_flight.

* read bookings
select * from sbook
into corresponding fields of table Itab_Booking
where carrid = Stru_flight-carrid
and connid = Stru_flight-connid
and fldate = Stru_flight-fldate.

* bind all the elements


Node->Bind_Table(
New_Items = Itab_Booking
Set_Initial_Elements = Abap_True ).

endmethod.

3-4 Map node BOOKINGTAB to context of OUTPUT_VIEW


Navigate to the OUTPUT_VIEW on the
Context tab. Update the mapping for
context node FLIGHTTAB in the view
context. (Node BOOKINGTAB will be
added to the view context)

2
Singleton
Solution
3
Singleton
Solution

You might also like