Sie sind auf Seite 1von 28

Assistance Class Use in WebDynpro ABAP

Prepared by:
Pallavi Gupta (Emp. Code 00662K)
Email ID Palgupt2@in.ibm.com

January 28, 2012

Contents
Use of Assistance Class:..............................................................................................
Advantages of Assistance Class:...................................................................................
Overview...................................................................................................................
Creation of DDIC Objects............................................................................................
Creation of Assistance Class........................................................................................
Add Inheritance.........................................................................................................
Create Methods in the Class.........................................................................................
Create Text Elements..................................................................................................
Create WebDynpro Component....................................................................................
Object for the Class....................................................................................................
Code.........................................................................................................................
Test..........................................................................................................................
Create Application...................................................................................................
Reference(s)..............................................................................................................

Use of Assistance Class:


A piece of code which is getting used again and again in a component can be added
to the method of an assistance class. Now this method can be called every time that
particular code has to be executed.
Advantages of Assistance Class:

Calling a method of an assistance class gives much improved performance


than calling a method of a controller.
Use of dynamic texts. Text can be saved as text symbols in an assistance
class and can be used at run time.

Overview
In this Document, Ill display the sales document details. The user will have to enter
the creation date; all the documents with that creation date will be displayed. When
user selects any particular sales document, the line items of that particular sales
document will be displayed
Steps:
Creation of DDIC Objects
Create 2 structures as show below in SE11.

Now create 2 Table Types using the structures created above.

Save and activate.

Creation of Assistance Class


Go to transaction SE24 to create a new assistance class.

Click on create.

Give the name of the class.

Add Inheritance
Note: All the assistance classes inherit from CL_WD_COMPONENT_ASSISTANCE.
To add the name of the superclass, click on the button next to class name field, a
new field for superclass will appear. Add the name of the superclass.

Click on Save.

The following screen will appear.


Two methods get automatically created. These are inherited from the superclass.
IF_WD_COMPONENT_ASSISTANCE~GET_TEXT method is used to get the dynamic
texts.

Create Methods in the Class


In the Methods tab, create 2 methods:
1) GET_SALES_DOCUMENTS
2) GET_SALES_DOCUMENT_DETAILS

Select the GET_SALES_DOCUMENTS method and click on parameters button.


Add 2 parameters as shown below.
Creation of Assistance Class
Go to transaction SE24 to create a new assistance class.

Click on create.

Give the name of the class.

Add Inheritance
Note: All the assistance classes inherit from CL_WD_COMPONENT_ASSISTANCE.
To add the name of the superclass, click on the button next to class name field, a
new field for superclass will appear. Add the name of the superclass.

Click on Save.

The following screen will appear.


Two methods get automatically created. These are inherited from the superclass.
IF_WD_COMPONENT_ASSISTANCE~GET_TEXT method is used to get the dynamic
texts.

Create Methods in the Class


In the Methods tab, create 2 methods:
3) GET_SALES_DOCUMENTS
4) GET_SALES_DOCUMENT_DETAILS

Select the GET_SALES_DOCUMENTS method and click on parameters button.


Add 2 parameters as shown below.

Similarly, add parameters for GET_SALES_DOCUMENT_DETAILS method.

Now, double click on the GET_SALES_DOCUMENTS method name. In the editor


screen, enter the following code.

select VBELN ERDAT ERZET ERNAM AUDAT


from VBAK
into table e_vbak
where ERDAT eq i_erdat.
Similarly, add the following code in the GET_SALES_DOCUMENT_DEATAILS method.

select VBELN POSNR MATNR MATWA ARKTX PSTYV MEINS


from VBAP
into table e_vbap
where VBELN eq i_vbeln.

Create Text Elements


Assistance class allows us to use the dynamic texts. In order to create them, click on
GOTO TEXT ELEMENTS.

Add text elements. Save and activate.

The assistance is ready to be used. We can test the working of our class by clicking
the execute button.

Create WebDynpro Component


Go to SE80 and create a new webdynpro component.

Double click on the component name. In the Assistance class field, add the name of
the class.

Go to the main view and go to the context tab.


Create the following nodes and attributes:

Click on Add Attribute from Structure button.

Click on Add Attribute from Structure button.

Create an attribute of DATS type.

Create 2 string attributes: TEXT1 and TEXT2. These will be used to display the
dynamic texts. Finally the nodes and attributes would look this:

Go to the layout tab and insert the UI elements.

Insert 2 Table UI elements. One to display the header lines of the sales documents
and other to display the line items of the selected sales document.

Right click on the table UI element, click on create binding.

Click on Context button.

Select the VBAK node.

Similarly create another table UI element and do the binding.

For the second table, select VBAP node.

Create a button UI element, and create an onAction event hander with the name
ONSEARCH.

Create an OnLeadSelect event handler for the first table. This event handler will be
called every time when a row in the first table is selected.

Bind the Caption of both the tables with attribute TEXT1 and TEXT2 respectively.

The final UI element will look like this:

Object for the Class


Go to the Attributes tab of the view, an object for the assistance class
WD_ASSIST will be automatically created.

Code
Go the WDDOINIT method of the view and use the following code:
The following code calls the IF_WD_COMPONENT_ASSISTANCE~GET_TEXT method
of the assistance class. This method takes the message number as input and
returns the text element corresponding to it. These texts are then set to TEXT1
and TEXT2 attribute and will appear on the caption of the table.
method WDDOINIT .
data: header1
header2
Elem_Context
Stru_Context
Item_TEXT1
*

type string,
type string,
type ref to If_Wd_Context_Element,
type If_Main_View=>Element_Context,
like Stru_Context-TEXT1.

get element via lead selection


Elem_Context = wd_Context->get_Element( ).

header1 = WD_ASSIST->IF_WD_COMPONENT_ASSISTANCE~GET_TEXT( KEY =


'001' ).
header2 = WD_ASSIST->IF_WD_COMPONENT_ASSISTANCE~GET_TEXT( KEY =
'002' ).
*

set single attribute


Elem_Context->set_Attribute(
exporting
Name = `TEXT1`
Value = header1 ).

set single attribute


Elem_Context->set_Attribute(
exporting
Name = `TEXT2`
Value = header2 ).

endmethod.

Now go to ONACTIONONSEARCH method and use the following code:


The following code gets the creation date entered by the user on the selection and
then calls the GET_SALES_DOCUMENTS method of the assistance class with
creation date as input parameters and returns an internal table.
method ONACTIONONSEARCH .
* Read the user entered date
data:
Elem_Context
type ref to If_Wd_Context_Element,
Stru_Context
type If_Main_View=>Element_Context ,
Item_CREATION_DATE
like Stru_Context-CREATION_DATE,
Node_Vbak
type ref to If_Wd_Context_Node,
Elem_Vbak
type ref to If_Wd_Context_Element,
Stru_Vbak
type If_Main_View=>Element_Vbak ,
it_vbak
type zvbak_tt.
* get element via lead selection
Elem_Context = wd_Context->get_Element( ).
*

navigate from <CONTEXT> to <VBAK> via lead selection


Node_Vbak = wd_Context->get_Child_Node( Name = IF_MAIN_VIEW=>wdctx_V
bak ).
*

get element via lead selection


Elem_Vbak = Node_Vbak->get_Element( ).

get single attribute


Elem_Context->get_Attribute(
exporting
Name = `CREATION_DATE`
importing
Value = Item_Creation_Date ).
CALL METHOD WD_ASSIST->GET_SALES_DOCUMENTS
EXPORTING
I_ERDAT = Item_Creation_Date
IMPORTING
E_VBAK = it_vbak.
IF not it_vbak[] IS initial.
Node_Vbak->bind_table( it_vbak ).
ENDIF.

endmethod.

The method of the class can called using Pattern

button.

Give the instance name (object name) of the class, which is WD_ASSIST in our
case. Provide the class name and method to be called. Code will be generated by
the system.

Use the following code on the OnLeadSelect method of the first table.
The following code will get the selected sales document number (VBELN) and will
pass it to the GET_SALES_DOCUMENT_DETAILS method of the class to get the line
items corresponding to that sales document number.
method ONACTIONONSELECT .
data:
Node_Vbak
type ref to If_Wd_Context_Node,
Elem_Vbak
type ref to If_Wd_Context_Element,
Stru_Vbak
type If_Main_View=>Element_Vbak ,
Node_Vbap
type ref to If_Wd_Context_Node,
Elem_Vbap
type ref to If_Wd_Context_Element,
Stru_Vbap
type If_Main_View=>Element_Vbap ,
it_vbap
type zvbap_tt.
* navigate from <CONTEXT> to <VBAK> via lead selection
Node_Vbak = wd_Context->get_Child_Node( Name = IF_MAIN_VIEW=>wdctx_V

bak ).
*

get element via lead selection


Elem_Vbak = Node_Vbak->get_Element( ).

* navigate from <CONTEXT> to <VBAP> via lead selection


Node_Vbap = wd_Context->get_Child_Node( Name = IF_MAIN_VIEW=>wdctx_V
bap ).
* get element via lead selection
Elem_Vbap = Node_Vbap->get_Element( ).
*

get all declared attributes


Elem_Vbak->get_Static_Attributes(
importing
Static_Attributes = Stru_Vbak ).
CALL METHOD WD_ASSIST->GET_SALES_DOCUMENT_DETAILS
EXPORTING
I_VBELN = stru_Vbak-vbeln
IMPORTING
E_VBAP = it_vbap.
IF it_vbap[] is not initial.
Node_Vbap->bind_table( it_vbap ).
ENDIF.

endmethod.

Test
Create Application
Right click on the component name. Create WebDynpro application.

Save it.
Right click on application Test.

Initial Screen

Enter the
creation

date and click on Search button. Sales documents created on that date gets
displayed.

Select any sales document, line items corresponding to that sales document gets
displayed.

Reference(s)
1. Project Experience
2. http://www.sdn.sap.com/
3. http://help.sap.com

Das könnte Ihnen auch gefallen