Application using Tab strip tool and assistance class in Web Dynpro
Introduction: THE DOCUMENT ELABORATES THE STEP BY STEP PROCESS TO USE TABSTRIP TOOLS AND ASSISTANCE CLASS.
1. Technical Design
1.1. Developing Application:
- Create a Webdynpro Application from Transaction Code: Se80.
1.2. View Designing:
- Go to the Main View and create a Group element in the Route Element Container.
- Take two Tray elements in the Group and take two Captions and Input Fields in the trays simultaneously.
- Create two Labels and input fields in the respective trays.
- Create another group to display the outputs in the Tab Strip.
- Create a Tab Strip inside the second Group.
- Right Click on the Tab Strip and click on Insert tab. Create two tabs and change the captions of the tabs as: “Material Details” and “Plant Details”.
- Now, go to the two tabs of the tab strip simultaneously, and add the table element to each of them for displaying the details tables and bind them with the respective nodes for display.
1.3. Component Controller Designing and Context Mapping:
- Now, go to the Component Controller of the application and create the node and take the attributes from the structure for the input fields as well as the table for the output screen.
- Now create the nodes for the result data for the material and plant details and fill up nodes with the attributes, those are to be displayed.
- Finally the context node will look like:
- Now go to the main view and navigate to the context tab and make the context mapping.
1.4. Value Mapping to the Input Fields and Tables from the View Controller:
- Now go to the Layout tab and select the input fields and map them with the context attributes using the value property.
1.5. Creation of Push Button and Action of the button:
Once the user will provide the input to the respective input fields and press the Search Button, it will call the Assistance class and fetch the data from the Database table and display the output to the tables of the respective tab strips.
- Take a button and for searching the material details:
- Now, create an action for the “OnAction” event of the button and write the code inside the same.
1.6. Code for the Action Button:
method ONACTIONSEARCH_DETAILS .
*************************************************************************
***************** Material Number *******************
*************************************************************************
DATA lo_nd_material_number TYPE REF TO if_wd_context_node.
DATA lo_el_material_number TYPE REF TO if_wd_context_element.
DATA ls_material_number TYPE wd_this->element_material_number.
DATA lo_nd_plants TYPE REF TO if_wd_context_node.
DATA lo_el_plants TYPE REF TO if_wd_context_element.
DATA ls_plants TYPE wd_this->element_plants.
DATA: it_material TYPE zgt_material,
it_plant TYPE zgt_plant,
node_material TYPE REF TO if_wd_context_node,
node_plant TYPE REF TO if_wd_context_node.
* navigate from
lo_nd_material_number = wd_context->get_child_node( name = wd_this->wdctx_material_number ).
* get element via lead selection
lo_el_material_number = lo_nd_material_number->get_element( ).
* @TODO handle not set lead selection
IF lo_el_material_number IS INITIAL.
ENDIF.
* get all declared attributes
lo_el_material_number->get_static_attributes(
IMPORTING
static_attributes = ls_material_number ).
*************************************************************************
***************** Plant Input *******************
*************************************************************************
* navigate from
lo_nd_plants = wd_context->get_child_node( name = wd_this->wdctx_plants ).
* get element via lead selection
lo_el_plants = lo_nd_plants->get_element( ).
* @TODO handle not set lead selection
IF lo_el_plants IS INITIAL.
ENDIF.
* get all declared attributes
lo_el_plants->get_static_attributes(
IMPORTING
static_attributes = ls_plants ).
* NAVIGATE FROM
node_material = wd_context->get_child_node(‘MATERIAL_DETAILS’) .
* NAVIGATE FROM
node_plant = wd_context->get_child_node(‘PLANT_DETAILS’).
IF ls_material_number IS NOT INITIAL OR ls_plants IS NOT INITIAL.
CALL METHOD wd_assist->get_material_plant
EXPORTING
im_matnr = ls_material_number–matnr
im_werks = ls_plants–werks
IMPORTING
et_material = it_material
et_plant = it_plant.
ENDIF.
*** Binding
node_material->bind_table( it_material ).
node_plant->bind_table( it_plant ).
endmethod.
1.7. Webdynpro Application Creation:
- Now, Create a Webdynpro Application, by right clicking on the component name and providing a suitable description to the same and activate the entire component.
2. Data Dictionary:
The structures and table types, those are declared globally through transaction SE11 and used by the Webdynpro Component.
The Line type used for Material Details:
The Table type used for Material Details:
The line type used for the Plant Details:
The table type used for Plant Details:
3. Assistance Class Design:
As this code uses the Assistance Class to fetch the data from the Database table, we need to develop a global class.
The Assistance Class details to fetch the details of the material as well as the respective plants:
The Method: GET_MATERIAL_PLANT in the class.
Code to Fetch data in Assistance Class
METHOD get_material_plant.
**** Type Declaration
TYPES: BEGIN OF ty_mara,
matnr TYPE matnr,
mtart TYPE mtart,
matkl TYPE matkl,
meins TYPE meins,
END OF ty_mara.
TYPES: BEGIN OF ty_makt,
matnr TYPE matnr,
spras TYPE spras,
maktx TYPE maktx,
END OF ty_makt.
TYPES: BEGIN OF ty_marc,
matnr TYPE matnr,
werks TYPE werks_d,
END OF ty_marc.
TYPES: BEGIN OF ty_t001w,
werks TYPE werks_d,
name1 TYPE name1,
bwkey TYPE bwkey,
kunnr TYPE kunnr_wk,
lifnr TYPE lifnr_wk,
END OF ty_t001w.
**** Data Declaration
DATA: wa_mara TYPE ty_mara,
it_mara TYPE TABLE OF ty_mara,
wa_makt TYPE ty_makt,
it_makt TYPE TABLE OF ty_makt,
wa_marc TYPE ty_marc,
it_marc TYPE TABLE OF ty_marc,
wa_t001w TYPE ty_t001w,
it_t001w TYPE TABLE OF ty_t001w,
es_material TYPE zty_material,
es_plant TYPE zty_plant.
**** Constant Declaration
CONSTANTS: co_spras TYPE spras VALUE ‘E’.
**** Selecting data from MARA Table
SELECT matnr
mtart
matkl
meins
FROM mara
INTO TABLE it_mara
WHERE matnr EQ im_matnr.
IF sy–subrc = 0.
SELECT matnr
spras
maktx
FROM makt
INTO TABLE it_makt
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara–matnr
AND spras = co_spras.
IF sy–subrc = 0.
LOOP AT it_mara INTO wa_mara.
es_material–matnr = wa_mara–matnr.
es_material–mtart = wa_mara–mtart.
es_material–matkl = wa_mara–matkl.
es_material–meins = wa_mara–meins.
READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mara–matnr.
IF sy–subrc = 0.
es_material–maktx = wa_makt–maktx.
APPEND es_material TO et_material.
CLEAR: wa_mara,
wa_makt,
es_material.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
IF im_werks IS NOT INITIAL.
SELECT matnr
werks
FROM marc
INTO TABLE it_marc
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara–matnr
AND werks = im_werks.
IF sy–subrc = 0.
SELECT werks
name1
bwkey
kunnr
lifnr
FROM t001w
INTO TABLE it_t001w
FOR ALL ENTRIES IN it_marc
WHERE werks = it_marc–werks
AND werks = im_werks.
IF sy–subrc = 0.
LOOP AT it_t001w INTO wa_t001w.
es_plant–werks = wa_t001w