Google Search - Blog...........

ABAP - OOPS: Sample Program On Dynamic Method Calls In Method programming.

REPORT YSUBOOPS19 .

data : f(6) type c ,
g(10) type c .

Class c1 definition.
Public section.
Class-methods: statm.
methods : instm .
endclass.

class c1 implementation.
method : statm .
write:/5 'I am static method'.
endmethod.

method : instm.
write:/5 'I am instant method'.
endmethod.
endclass.


start-of-selection.
data : oref type ref to c1.
create object oref.
* Name of instance method can be dynamic
f = 'INSTM'. call method oref->(f).
* Name of static method can be dynamic
f = 'STATM'. call method oref->(f).
* Name of the class can be dynamic for static method call
f = 'C1'. call method (f)=>statm.
* Name of the method can be dynamic for static method call
f = 'STATM'. call method c1=>(f).
* Both can be dynamic for static method call
g = 'C1'. call method (g)=>(f).


Output

I am instant method
I am static method
I am static method
I am static method
I am static method

No comments:

Post a Comment