‎2007 Feb 01 5:06 AM
Hi,
I want to invoke a method dynamically. I have the class name and method name in a variable and the list of import and export parameter for this method in an internal table. Now I need to invoke this method dynamically i.e. without having it to call in code like this classname->methodname(.....). I want something like reflection in java, where we can call the method using invoke method of method class ex:
try {
Method method = cls.getMethod( "setColor",
new Class[] {Color.class} );
method.invoke( obj, new Object[] );
}
It would be helpful if you can provide a simple example on how it can be implemented in ABAP.
Thanks,
Raghavendra
‎2007 Feb 01 5:18 AM
Hi,
You can perform calls in that way as follows.
You need to pass the parameters usingthe following table of type ABAP_PARAMBIND_TAB.
DATA: ptab type ABAP_PARAMBIND_TAB,
ptab_line like line of ptab.
DATA: clas_name type stirng VALUE 'CLASS_NAME',
method_name type string VALUE 'METHOD_NAME'.
DATA: obj type ref to OBJECT.
create object obj type class_name.
ptab_line-name = 'PARAM_NAME'.
ptab_line-kind = CL_ABAP_OBJECTDESCR=>EXPORTING.
Then you can use
CALL METHOD obj->(method_name) PARAMETER-TABLE ptab.
Regards,
Sesh
‎2007 Feb 01 5:18 AM
Hi,
You can perform calls in that way as follows.
You need to pass the parameters usingthe following table of type ABAP_PARAMBIND_TAB.
DATA: ptab type ABAP_PARAMBIND_TAB,
ptab_line like line of ptab.
DATA: clas_name type stirng VALUE 'CLASS_NAME',
method_name type string VALUE 'METHOD_NAME'.
DATA: obj type ref to OBJECT.
create object obj type class_name.
ptab_line-name = 'PARAM_NAME'.
ptab_line-kind = CL_ABAP_OBJECTDESCR=>EXPORTING.
Then you can use
CALL METHOD obj->(method_name) PARAMETER-TABLE ptab.
Regards,
Sesh
‎2008 Feb 15 5:32 PM
Hi Sesh,
I'm on SAP 4.7 and there isn't any type ABAP_PARAMBIND_TAB. Can you please describe how it is declare in order to recreate it here.
thanks in advanced,
Eric