Monday, February 7, 2011

Working on Polymorphism

POLYMORPHISM:-

Polymorphism is a characteristic of being able to assign a different behavior or value in a subclass, to something that was declared in a parent class. For example, a method can be declared in a parent class, but each subclass can have a different implementation of that method. This allows each subclass to differ, without the parent class being explicitly aware that a difference exists.

CLAUSES REGARDING POLYMORPHISM:-

1.Allows one interface to be used for a general class of actions.
2.When objects from different classes react differently to the same procedural call.
3.User can work with different classes in a similar way, regardless of their implementation.
4.Allows improved code organization and readability as well as creation of “extensible” programs.
5.Although the form of address is always the same, the implementation of the method is specific to a particular class.

Go to SE24 T-code.

Press create button.

Press Save button.

Provide methods.

Select the first method then provide the parameters for this method.

Go back to the methods then double click on the method name.

Then provide the logic.

Select display_method then provide the parameters for this method.

Go back to method then provide the logic.

Save it , check it , and activate it .

Provide SUBCLASS:

Press CREATE button.

Click on SAVE .

Go to attribute provide the values that means provide super class name.

Go to methods we can see like this.



Select select _ method then press the REDEFINE button.

Then screen would like this.

Provide the logic.

Then save it .

Go to Attributes.

Then provide the Variables.

Go back to the methods.

Then provide another method.

Double click on the method then provide the logic

Click on SAVE , CHECK , and ACTIVATE .

Then provide the code in the T-Code SE38.

Provide the logic.

*Provide Object for Sub Class

DATA: OBJ1 TYPE REF TO ZCL_POLYMORPHISM_SUB.
*Provide Parameters
PARAMETERS: V_VBELN TYPE VBAP-VBELN.
*Provide Data Objects
DATA: WA_VBAP TYPE VBAP,
IT_VBAP TYPE Z_VBAP.
*Create the Object
CREATE OBJECT OBJ1.
*Call the Redefine Select Method
CALL METHOD OBJ1->SELECT_METHOD
EXPORTING
P_VBELN = V_VBELN
* IMPORTING
* WA_VBAK =.
*Provide the IT_VBAP Values
IT_VBAP = OBJ1->IT_VBAP.
LOOP AT IT_VBAP INTO WA_VBAP.
WRITE:/ WA_VBAP-VBELN,
WA_VBAP-POSNR,
WA_VBAP-MATNR.
ENDLOOP.

Click On SAVE , CHECK , ACTIVATE and EXECUTE it.

Output :-

The output data display in the list.


No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites