Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Check interface method is implemented

Former Member
0 Likes
6,973

hi!

is there a way to check an interface method is implemented? RTTS provide a table of all methods in CL_ABAP_OBJECTDESCR->METHODS, which has attributes like IS_INTERFACE or IS_REDEFINED. But nothing specific for interface methods like "IS_IMPLEMENTED" (what I would need).

Any suggestions welcome

Thanks,

Roland

6 REPLIES 6
Read only

0 Likes
3,822

Hi Roland,

Wouldn't it be sufficient to find out whether the class in question implements the interface containing this method in general? If such interface is listed in cl_aba_objectdescr->interfaces it should be guaranteed that it also implements the method because a class which binds itself to implement an interface cannot be activated unless it actually does implement all methods from that interface.

Best regards

Michal

Read only

0 Likes
3,822

Thanks Michal for your reply. In earlier versions your statement was true; but at least in the system I'm currently developing (7.40), not all interface-methods of an interface need to be implemented. In the interface definition, there is a way to tell the system what to do in case an implementation is missing but the method gets executed ("default fail" will throw an exception, the other option is to simulate empty method behavior).

Read only

0 Likes
3,822

I think you are referring to PARTIALLY IMPLEMENTED , but this is only valid for ABAP Unit Test class. It can't be used anywhere else.

See this discussion on Blog - ABAP News for Release 7.40 - ABAP Objects | SCN

Regards,
Naimesh Patel

Read only

0 Likes
3,822

I see Roland, I had no clue this was possible. Due to that this task becomes pretty tricky! I'd let you know if something came on my mind. Unfortunately for the time being I am out of ideas

Read only

larshp
Active Contributor
0 Likes
3,822

If you know the methods from the interface and assuming it is a global class, try calling cl_oo_classname_service=>get_all_method_includes it will return the implemented methods

Read only

MattDion
Participant
0 Likes
3,244

I know this question is quite old, but I had to find a way to do this in ABAP for Cloud Development

cl_oo_classname_service is not released for use, so another approach was needed (calling the method with fake parameters is not an option).

The solution comes complements of the XCO classes. With these classes, you can read the source code of the method implementation into a string table. If the method is not implemented, an exception is raised. Here is an example:

 

TRY.
    xco_cp_abap_repository=>object->clas->for( '<name of class>' )->implementation->method('<name of interface>~<name of method')->content( )->get_source( ).

    " method is implemented

  CATCH cx_xco_runtime_exception.
    " method is not implemented
ENDTRY.