Web Dynpro for ABAP – Fix for Tutorial 6 – Component Usage (How to create a reusable component)
Hi all,
My interest in Web Dynpro for ABAP has been piling up so I finally took the time to try it out and run through some tutorials.
Like many others, I started here http://scn.sap.com/docs/DOC-8863 , an excelent set of tutorials by Antje Boehm-Peters and Razi Mateen. However, in Tutorial 6, which teaches you how to reuse other components, the component used (TECHED_05S_CUSTOMER_DATA) did not exist in my system. I googled around and it seemed that there were others in my situation. So, to help out others, and also for educational purposes, I took the time to learn how to create a reusable component that could be used to complete this tutorial.
So let’s start!
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 controller’s context
Switch to the context tab of the component’s controller. Create a node and use structure BAPICUSTOMER_04. For simplicity I added 4 attributes from the structure: Customer, Name, City and Street.
In the end it should look something like this:
3 – Map the component’s context to the view’s context
Now you need to map the component’s context to the view’s context. Switch to the context tab of the component view to be able to do this. Drag the component’s context node to the view’s context node.
If done properly, it should look like this:
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 view’s context.. I used read-only input fields and labels.
This is how it looks like in the end:
5 – Creating the method
Now we need to implement the method that will get the information from the customer and display it on the screen. Switch to the method tab of the component controller and create method SHOWCUSTOMER. Don’t forget to check the interface checkbox or it won’t 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:
Here’s the code for the method (sorry for the poor formatting):
METHOD showcustomer .
DATA:
lv_kunnr TYPE kunnr,
ls_cust 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( ).
* @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 is helpful.
Best,
Bruno Esperança
well done Bruno! 🙂
Thanks 🙂
ths,it is very useful for me!
You're welcome!
u r gr8
Thx, glad I could help 🙂
good work.
Thanks Hans!
Thanks Bruno!
It's been really helpful.
Happy to hear that 🙂
Thanks for the 5 star rating!
Cheers,
Bruno
Hi Bruno,
The link seem to be broken. I couldn't download the file from the link you provided. Can you send a fresh link.
Thanks in advance.
Regards,
Satyavrit
Hi Satyavrit, I'll do better than that, as soon as I have some time (hopefully this week) I will re-write this document post so that you don't need to download a file.
Unfortunately at the time I wrote this post it was not easy to include pictures, but now it is, so it makes sense for me to re-write this post. I will let you know.
Kind regards,
Bruno
Hi again,
I updated the blog post. You should now be able to follow it without any trouble. Let me know if you still have any questions! (Even though it's been a LONG time since I've done anything with web dynpro 🙂 )
Best,
Bruno
Hi Bruno,
This is really helpful. Appreciate your effort.
Regards,
Aayush
Hi Aayush,
That's good to know 🙂
Best regards,
Bruno
Thanks,it's very useful for me to done the tutorial 6!
I'm happy to know that 🙂
Cheers,
Bruno
Thanks Bruno. This was very helpful. I didn't have BAPI_CUSTOMER_GETDETAIL2 in my system so I needed to use BAPI_FLCUST_GETLIST instead. I replaced the first part of your code with the following to fill the customer data. "wa_customer" was used instead of "ls_cust".
TYPES typ_cust_range TYPE STANDARD TABLE OF bapiscucra.
TYPES typ_customer TYPE STANDARD TABLE OF bapiscudat.
DATA tab_cust_range TYPE typ_cust_range.
DATA wa_cust_range TYPE bapiscucra.
DATA tab_customer TYPE typ_customer.
DATA wa_customer TYPE bapiscudat.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = customer_id
IMPORTING
output = wa_cust_range-low.
wa_cust_range-sign = 'I'.
wa_cust_range-option = 'EQ'.
APPEND wa_cust_range TO tab_cust_range.
CALL FUNCTION 'BAPI_FLCUST_GETLIST'
TABLES
customer_range = tab_cust_range
customer_list = tab_customer.
READ TABLE tab_customer WITH KEY customerid = customer_id INTO wa_customer.
Hi Peter,
You are very welcome, I'm glad it was useful 🙂
Very strange that you didn't have that BAPI on your system!! But I'm glad you found a way around it.
Best regards,
Bruno
Excelente, obrigado Bruno!
Com prazer (with pleasure).
Cumprimentos!
Hi, I have encountered this where I couldnt mark the "Interface Checkbox" as theres no interface checkbox column in method list, i tried to search online couldnt find the result, only only has got tutorial on how to create checkbox on layout.
Is there somewhere to enable it?
Appreciate your help, thanks