Skip to Content
0
Former Member
Nov 18, 2012 at 10:28 PM

Call Method of interface at runtime

899 Views

Hello

I'm trying to call a method of a class that implements a custom interface. I receive the class name as a parameter in my method so i have to create the object at runtime.

This is currently my code:

try.

" Call the Interface Method to Get Additional

create object generic_class type (gs_class_name).

if_xxx_gs_mapping ?= generic_class.

call method if_xxx_gs_mapping->map_gs_fields

exporting

it_form_values = it_form_values

importing

it_keys = it_keys

changing

it_fields = it_fields

exceptions

error_mapping_fields = 1

others = 2.

if sy-subrc <> 0.

raise error_mapping_gs_fields.

endif.

" Catch - Possible Errors

catch cx_sy_create_object_error .

raise error_calling_interface.

catch cx_sy_dyn_call_param_missing .

raise error_calling_interface.

catch cx_sy_dyn_call_illegal_method.

" Class doesnt implement the method

return.

endtry.

The problem is this code always enter's in the cx_sy_dyn_call_illegal_method.

I have checked the gs_class_name implements the interface and both the class and the method are active.

i have also tried to do this:

create object if_xxx_gs_mappingtype (gs_class_name).

In the method call the exception is the same

What could be the problem?

Thanks