Using Select-Options in Web Dynpro for ABAP
Create a Web Dynpro Component called Z_SELECT_OPTIONS
The usage of WDR_SELECT_OPTIONS component is defined in the Used Components tab as SELECT_OPTIONS.
Now Create a View as MAIN_VIEW
Create a Context node called FLIGHTS
Click the button Add Attribute from Structure
Click OK.
Now Create a View Container UI Element as VIEW_CONTAINER
Now create a Button called SEARCH and create an action to it.
Now Create a Table called FLIGHTTABLE and the dataSource property of the Table view element is linked to the FLIGHTS context node.
In the Properties tab of the view controller, under the Used Controllers/Components
In the view controller, we need an attribute that holds the reference to the instance of the Select Options component. This is necessary because at runtime we access this reference to the search criteria that have been entered in the event-handler method.
Now in the WDDOINT method of the view controller write this code.
METHOD WDDOINIT . DATA: LT_RANGE_TABLE TYPE REF TO DATA, RT_RANGE_TABLE TYPE REF TO DATA, READ_ONLY TYPE ABAP_BOOL, TYPENAME TYPE STRING.
DATA: LR_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER, L_REF_CMP_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE.
* create the used component L_REF_CMP_USAGE = WD_THIS->WD_CPUSE_SELECT_OPTIONS( ). IF L_REF_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL. L_REF_CMP_USAGE->CREATE_COMPONENT( ). ENDIF. WD_THIS->M_WD_SELECT_OPTIONS = WD_THIS->WD_CPIFC_SELECT_OPTIONS( ). * init the select screen WD_THIS->M_HANDLER = WD_THIS->M_WD_SELECT_OPTIONS->INIT_SELECTION_SCREEN( ).
WD_THIS->M_HANDLER->SET_GLOBAL_OPTIONS( I_DISPLAY_BTN_CANCEL = ABAP_FALSE I_DISPLAY_BTN_CHECK = ABAP_FALSE I_DISPLAY_BTN_RESET = ABAP_FALSE I_DISPLAY_BTN_EXECUTE = ABAP_FALSE ).
* create a range table that consists of this new data element LT_RANGE_TABLE = WD_THIS->M_HANDLER->CREATE_RANGE_TABLE( I_TYPENAME = 'S_CARR_ID' ). * add a new field to the selection WD_THIS->M_HANDLER->ADD_SELECTION_FIELD( I_ID = 'S_CARR_ID' IT_RESULT = LT_RANGE_TABLE I_READ_ONLY = READ_ONLY ).
ENDMETHOD.
Now in the ONACTIONSEARCH method of the view controller write this code.
METHOD ONACTIONSEARCH .
DATA: NODE_FLIGHTS TYPE REF TO IF_WD_CONTEXT_NODE. DATA: RT_CARRID TYPE REF TO DATA. DATA: ISFLIGHT TYPE TABLE OF SFLIGHT. DATA: WSFLIGHT TYPE SFLIGHT. FIELD-SYMBOLS: <FS_CARRID> TYPE TABLE.
* Retrieve the data from the select option RT_CARRID = WD_THIS->M_HANDLER->GET_RANGE_TABLE_OF_SEL_FIELD( I_ID = 'S_CARR_ID' ).
* Assign it to a field symbol ASSIGN RT_CARRID->* TO <FS_CARRID>.
CLEAR ISFLIGHT. REFRESH ISFLIGHT. SELECT * INTO CORRESPONDING FIELDS OF TABLE ISFLIGHT FROM SFLIGHT WHERE CARRID IN <FS_CARRID>. NODE_FLIGHTS = WD_CONTEXT->GET_CHILD_NODE( NAME = `FLIGHTS` ). NODE_FLIGHTS->BIND_ELEMENTS( ISFLIGHT ). ENDMETHOD.
Now Drag and drop the MAIN_VIEW into the Window and create an Embed View in the VIEW_CONTAINER.
Now your window should look like this.
Now Create a Web Dynpro Application and save and activate all.
Output:
No comments:
Post a Comment