Tuesday, May 31, 2011

Using Assistance Class in web dynpro abap

Assistance Class in web dynpro Abap :- Assistance class is a way of writing a separate class and using the functionality or logic defined in its method within your web dynpro application.
It is useful where you have some piece of logic which is reusable at many places.
plus Assistance class is also used in internationalization of the WD application.
You can declare the text in the assistance class and then afterwards can use it in your WD application.
Concept is almost straight forward and easy.
You declare a class with some methods having the required functionality.
and can declare some text elements also if you want to use them.
and you have to make this class subclass of a class CL_WD_COMPONENT_ASSISTANCE.
However this is not a mandatory steps but declaring this class as superclass makes services available in web dynpro framework work.
WD_ASSIST attribute will be getting created automatically in each of the controllers in the web dynpro component.

Now lets have one step by step example of working with this feature of assistance class.

1. Go to txn se24 and create a class . give a relevant name and press on create.

Photobucket


Photobucket

and click on save.

Photobucket

2. Go to the methods tab and create methods. In the current case, I am creating a method name
'Get Name' and with one import and one export parameter.
functionality of the method is to give name of the dealer based on the ID.

Photobucket

Photobucket

Photobucket

Photobucket

Photobucket

3. Save and activate the class.


Photobucket

4. You can test the functionality of the method by using the TEST option as shown below.

Photobucket

Photobucket

Photobucket

5. ON the properties tab you can find one field called super class there give the name
CL_WD_COMPONENT_ASSISTANCE.
save and activate the class.

Photobucket

6. Go to SE80 and open the WD component where you want to use the assistance class.
give the name of the class in the assistance class field.

Photobucket

7. Automatically the attribute WD_ASSIST of type instance of class will be created in the component controller and view controller.

Photobucket

Photobucket

8. In the view we will use the assistance class method "GET_NAME". for that i have created some context attribute and then in the view layout, have designed two input fields and one button.
we will enter dealer id and then click on submit button. In the eventhandler of the button we will
call the method GET_NAME of the assistance class using the attribute WD_ASSIST and fetch the name form the database after passing ID.

Photobucket

Photobucket

Photobucket

9. Create an application and test it .

Photobucket

Photobucket




10. Now lets check out the other usage of assistance class. i.e. declaring the text elements in the class and then using it for translation according to the language chosen.
Here we will have one page with one simple text view translated according to the language chosen.

go to se24 and open the class and Goto-> Text elements.

11. declare the text elements here and after that save it and then Goto->Translation






12. Select the from and to language and then give the translated texts for each of the text elements. Save it and activate the class again.


13. Go to SE80 and open the web dynpro component and the view where you want the text.
I have used one text view which is bound to one context attribute of type string.


14. Then in wddoinit have used the
WD_ASSIST->IF_WD_COMPONENT_ASSISTANCE~GET_TEXT( KEY = ' ').
method of the interface for getting the data.
it will give the text according to the language selected in the application.


15. Test the application and we can see the text got automatically translated according to the
language selected.





Thanks :)

thanks
gill


Monday, May 30, 2011

Creating a Simple Web Dynpro App with ALV


Creating ALV in Web Dynpro ABAP.

This tutorial will give you step by step approach to create a simple ALV table in web dynpro abap.

1. Go to transaction SE80





2. Select object type as Web Dynpro Comp/Intf.





3. Give some name in the below box and press enter.



4. Pop up will come select Yes there.


5. Object as Local object.



6. It will create a new web dynpro component as shown.


7. Double click on the component name and there in the used web dynpro components list
Add SALV_WD_TABLE

component.

Go to the component controller and there create one node . give its name and cardinality

0..n
And in the dictionary structure give the name of some database table.
In the example here I have used Zdealer one

custom table that I have created.
After that click on the ‘ADD attribute from the structure ’. and the fields from the screen
Then press enter, attributes will be added to the node.
also















9. Then give one supply function in the node’s properties. FILL is the supply function created

here.



9. Go to that supply function and write the logic to fill the node.
Here I have written simple logic to fill it with all the entries of the table using the select *
Statement.
10. Now go to the

interfacecontroller usage created for the used web dynpro comp.
There go to context and click on controller usage.




11. There select the component controller from the popup and then map the node Dealer (which was

created earlier) to the DATA node




12. Go to the view controller of main view there add the UI element

ViewContainerUIElement.
And save everything.





13. Now go to the window and there right click on the viewcontianer added in the last step and

Select TABLE view of component SALV_WD_TABLE from there.






14. Save everything and activate.



15. Create one application for the component.




17. Right click on the application and test it. Browser will open and show you ALV filled with all the entries

of the table (in this case it is ZDEALER).







that is done....

we will discuss about more things related to ALV in webdynpro abap in next posts


thanks :)
Gill