Você está na página 1de 8

Web Dynpro for ABAP: Fix for Tutorial 6 Component Usage

By Bruno Esperana

04.05.2012

Context
Web dynpro is becoming increasingly popular, and demand for experts in this area is on the rise. Due to this, many developers are training themselves around web dynpros, both for abap and java. One very well known group of tutorials is the one in SCN provided by Antje Boehm-Peters and Razi Mateen of SAP NetWeaver Product Management. To get there you can follow the link http://scn.sap.com/docs/DOC-8863 and you will be presented with Web Dynpro for ABAP: Tutorials for Beginners. In this group of tutorials you are presented with six different tutorials. Following and completing them is pretty straightforward, however I did come across a small glitch in tutorial 6 component usage. It seems that my system did not have the reusable component necessary to complete this tutorial, component TECHED_05S_CUSTOMER_DATA. I googled around the internet and it seemed others were facing the same problem and were having a hard time working around this problem, so I took the initiative to investigate how to solve this problem and write this fix for it. I hope you will find it valuable.

Web Dynpro for ABAP: Fix for Tutorial 6 Component Usage

04.05.2012

Procedure
1. 2. 3. 4. 5. 6. Creating a new component ......................................................................................... 4 Creating the attributes in the component controllers context ................................... 4 Map the components context to the views context .................................................. 4 Creating the layout ..................................................................................................... 5 Creating the method ................................................................................................... 6 Save it and activate everything! ................................................................................. 8

Web Dynpro for ABAP: Fix for Tutorial 6 Component Usage

04.05.2012

1. Creating a new component


Start by creating a new component and name it whatever you like. I named it ZZ_00_CUSTDISPLAY. I entered the same name for the window and left the default name for the view.

2. Creating the attributes in the component controllers context


Switch to the context tab of the components controller. Create a node and use structure BAPICUSTOMER_04. For simplicity I added four attributes from the structure: Customer, Name, City and Street. In the end it should look something like this:

3. Map the components context to the views context


Now you need to map the components context to the views context. Switch to the context tab of the component view to be able to do this. Drag the components context node to the views context node. If done properly, it should look like this:

Web Dynpro for ABAP: Fix for Tutorial 6 Component Usage

04.05.2012

4. Creating the layout


Now you have to change to the layout tab and draw it out, mapping the fields to the respective attributes in the views context. I used read-only input fields and labels. This is how it looks like in the end:

Web Dynpro for ABAP: Fix for Tutorial 6 Component Usage

04.05.2012

5. Creating the method


Now we need to implement the method that will get the information for the customer and display it on the screen. Switch to the method tab of the component controller and create method SHOWCUSTOMER. Dont forget to check the interface checkbox or it wont be available for the component usage controller. Method list:

Double click it. Now you have to implement the method. We need an importing parameter, CUSTOMER_ID, of type S_CUSTOMER, like this:

Web Dynpro for ABAP: Fix for Tutorial 6 Component Usage

04.05.2012

Heres the code for the method:


METHOD showcustomer . DATA: lv_kunnr ls_cust TYPE kunnr, TYPE bapicustomer_04.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = customer_id IMPORTING output = lv_kunnr. CALL FUNCTION 'BAPI_CUSTOMER_GETDETAIL2' EXPORTING customerno = lv_kunnr IMPORTING customeraddress = ls_cust. DATA lo_nd_cust_data TYPE REF TO if_wd_context_node. DATA lo_el_cust_data TYPE REF TO if_wd_context_element. DATA ls_cust_data TYPE wd_this->element_cust_data. * navigate from <CONTEXT> to <CUST_DATA> via lead selection lo_nd_cust_data = wd_context->get_child_node( name = wd_this>wdctx_cust_data ). * * * * @TODO handle non existant child IF lo_nd_cust_data IS INITIAL. ENDIF. get element via lead selection lo_el_cust_data = lo_nd_cust_data->get_element( ).

Web Dynpro for ABAP: Fix for Tutorial 6 Component Usage

04.05.2012

@TODO handle not set lead selection IF lo_el_cust_data IS INITIAL. ENDIF. @TODO fill static attributes ls_cust_data = ls_cust. set all declared attributes lo_el_cust_data->set_static_attributes( static_attributes = ls_cust_data ).

* *

ENDMETHOD.

6. Save it and activate everything!


Save and activate everything, you should now be able to proceed with tutorial 6 component usage. Hope this was helpful for you.

Web Dynpro for ABAP: Fix for Tutorial 6 Component Usage

Você também pode gostar