Application Development 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: 

Find Abstract class ABAP

omar_saber
Explorer
755

Hello everyone,

I have 3 classes which using the same interface, to find them I used method ' get_implementing_classes ' to find the classes which using this interface and I put it them in a table ' lt_classes ' and made a loop over this table.

my problem is that I have 1 class from those 3 classes is Abstract Class so I want to avoid it from the implementing so I tried to use method ' is_abstract ' to find this class and store it in ' class_abstract ' so I called this method in my code as you can see but I want to know how can I check and remove this class to avoide the error, please find my code below. Thank you in advance.

DATA: lo_interf TYPE REF TO cl_oo_interface.
lo_interf ?= cl_oo_interface=>get_instance( 'ZMAR_IF_HANDSON' ).
DATA(lt_classes) = lo_interf->get_implementing_classes( ).

DATA: lo_abstract_cl TYPE REF TO cl_oo_class.
lo_abstract_cl ?= cl_oo_class=>get_instance( 'ZMAR_HANDSON2' ).

DATA: ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE STANDARD TABLE OF slis_fieldcat_alv.


DATA: lt_output TYPE TABLE OF zmar_st_get_daemon,
ls_output TYPE  zmar_st_get_daemon.

LOOP AT lt_classes ASSIGNING FIELD-SYMBOL(<print_cl>).

DATA: get TYPE REF TO zmar_if_handson .
CREATE OBJECT get TYPE (<print_cl>-clsname). 
DATA(class_abstract) = lo_abstract_cl->is_abstract( ).

IF sy-subrc = 0 AND class_abstract = abap_true.
CONTINUE.

ELSE.
ls_output-daemon_name = get->naming( ).
ls_output-priority = get->priority( ).
ls_output-damon_config = get->get_daemon_start_config( ).
APPEND ls_output TO lt_output.

ENDIF.
ENDLOOP.
5 REPLIES 5

Sandra_Rossi
Active Contributor
692

You are providing some code which seems to do what you are asking. Could you explain what exact issue you have with your code, then?

omar_saber
Explorer
0 Kudos
692

sandra.rossi My problem is in this section, I think my if statement is wrong and I still have the error and I want to exclude this class from my implementation.

DATA: get TYPE REF TO zmar_if_handson .
CREATE OBJECT get TYPE (<print_cl>-clsname).
DATA(class_abstract) = lo_abstract_cl->is_abstract( ).

IF sy-subrc = 0 AND class_abstract = abap_true.
CONTINUE.

ELSE.
ls_output-daemon_name = get->naming( ).
ls_output-priority = get->priority( ).
ls_output-damon_config = get->get_daemon_start_config( ).
APPEND ls_output TO lt_output.

ENDIF.
ENDLOOP.

Sandra_Rossi
Active Contributor
692

My question was to understand what error you have, you still don't explain.

If you mean that you do "create object" BEFORE testing whether it's abstract, it's an obvious error in your code, you must do it AFTER !

omar_saber
Explorer
692

yes this was my error and now this is the correct code if someone can get usefull from it, thank you sandra.rossi

START-OF-SELECTION.
DATA: lo_interf TYPE REF TO cl_oo_interface.

lo_interf ?= cl_oo_interface=>get_instance( 'ZMAR_IF_HANDSON' ).
DATA(lt_classes) = lo_interf->get_implementing_classes( ).



DATA: ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE STANDARD TABLE OF slis_fieldcat_alv.


DATA: lt_output TYPE TABLE OF zmar_st_get_daemon,
ls_output TYPE zmar_st_get_daemon.

"-----------------------------------------------------------------------------------------------------------


LOOP AT lt_classes ASSIGNING FIELD-SYMBOL(<print_cl>).



DATA: get TYPE REF TO zmar_if_handson .

DATA: lo_abstract_cl TYPE REF TO cl_oo_class.
lo_abstract_cl ?= cl_oo_class=>get_instance( <print_cl>-clsname ).


DATA(class_abstract) = lo_abstract_cl->is_abstract( ).

IF sy-subrc = 0 AND class_abstract = abap_true.
CONTINUE.
ELSE.

CREATE OBJECT get TYPE (<print_cl>-clsname).

ls_output-daemon_name = get->naming( ).
ls_output-priority = get->priority( ).
ls_output-damon_config = get->get_daemon_start_config( ).
APPEND ls_output TO lt_output.
ENDIF.




ENDLOOP.

Sandra_Rossi
Active Contributor
0 Kudos
692

Thanks for the feedback!

PS: to know if one class is abstract, CL_OO_CLASS is not supported (not API), better use RTTS (attribute CLASS_KIND of CL_ABAP_CLASSDESCR, constant CLASSKIND_ABSTRACT).

NB: RTTS cannot be used to find class pools which implement an interface pool, so you can go for unsupported CL_OO_INTERFACE (or any equivalent solution, like e.g., reading the table SEOMETAREL, RELTYPE='1')