0% found this document useful (0 votes)
93 views9 pages

Working On Polymorphism: by Vikram Chellappa, Mouri Tech Solutions

Polymorphism allows objects from different classes to react differently to the same method call. It provides a common interface that subclasses can implement differently, without the parent class being aware of the differences. The document discusses how polymorphism allows one interface to be used for general classes of actions, and subclasses can have different implementations of methods declared in the parent class, allowing for improved code organization, readability, and extensibility. It provides an example of redefining a select method in a subclass to retrieve data differently than the parent class implementation.

Uploaded by

rajeevbaghel2000
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views9 pages

Working On Polymorphism: by Vikram Chellappa, Mouri Tech Solutions

Polymorphism allows objects from different classes to react differently to the same method call. It provides a common interface that subclasses can implement differently, without the parent class being aware of the differences. The document discusses how polymorphism allows one interface to be used for general classes of actions, and subclasses can have different implementations of methods declared in the parent class, allowing for improved code organization, readability, and extensibility. It provides an example of redefining a select method in a subclass to retrieve data differently than the parent class implementation.

Uploaded by

rajeevbaghel2000
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Working on Polymorphism

By Vikram Chellappa, Mouri Tech Solutions

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.

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.

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.

You might also like