‎2008 Nov 05 6:40 PM
I need to write a little program: when a user enters a classname:
I need to collect all the subclasses of this class and subclasses of this subclasses and so on...
example:
CLASS->S_CLASS_1
->S_CLASS_2
->S_CLASS_3->S_CLASS4
->S_CLASS5
->S_CLASS6->.....
CLASS has 3 subclasses en S_CLASS_3 also has 3 subclasses ...
I need to collect all these classes in one itab. how do i do this?
‎2008 Nov 05 7:01 PM
Hi
U can create an internal table where the first field is the level and the second the subclass:
DATA: BEGIN OF ITAB OCCURS 0,
LIVEL(4) TYPE N,
SUBCLASS(20) TYPE C,
END OF ITAB.
DATA: N_CLASS(4) TYPE N.
DATA: POS TYPE I.
DATA: COUNT TYPE I.
MOVE 0 TO ITAB-LIVEL.
MOVE 'CLASS' TO ITAB-SUBCLASS.
APPEND ITAB.
DO 10 TIMES.
MOVE SY-INDEX TO ITAB-LIVEL.
DO 3 TIMES.
N_CLASS = N_CLASS + 1.
ITAB-SUBCLASS = 'S_CALLS_X'.
REPLACE 'X' WITH N_CLASS INTO ITAB-SUBCLASS.
APPEND ITAB.
ENDDO.
ENDDO.
LOOP AT ITAB.
IF SY-TABIX <> 1.
COUNT = COUNT + 1.
ELSE.
COUNT = 3.
ENDIF.
WRITE: AT /POS ITAB-LIVEL, ITAB-SUBCLASS.
CHECK COUNT = 3.
CLEAR COUNT.
POS = POS + 4.
ENDLOOP.
‎2008 Nov 05 7:01 PM
Hi
U can create an internal table where the first field is the level and the second the subclass:
DATA: BEGIN OF ITAB OCCURS 0,
LIVEL(4) TYPE N,
SUBCLASS(20) TYPE C,
END OF ITAB.
DATA: N_CLASS(4) TYPE N.
DATA: POS TYPE I.
DATA: COUNT TYPE I.
MOVE 0 TO ITAB-LIVEL.
MOVE 'CLASS' TO ITAB-SUBCLASS.
APPEND ITAB.
DO 10 TIMES.
MOVE SY-INDEX TO ITAB-LIVEL.
DO 3 TIMES.
N_CLASS = N_CLASS + 1.
ITAB-SUBCLASS = 'S_CALLS_X'.
REPLACE 'X' WITH N_CLASS INTO ITAB-SUBCLASS.
APPEND ITAB.
ENDDO.
ENDDO.
LOOP AT ITAB.
IF SY-TABIX <> 1.
COUNT = COUNT + 1.
ELSE.
COUNT = 3.
ENDIF.
WRITE: AT /POS ITAB-LIVEL, ITAB-SUBCLASS.
CHECK COUNT = 3.
CLEAR COUNT.
POS = POS + 4.
ENDLOOP.
‎2008 Nov 05 7:10 PM
okey but it is more difficult then that. there is a parameter where the user can enter a class: example class ZCAR. then i need to check if ZCAR has subclasses(table SEOMETAREL). then for each subclass of the class ZCAR i need to collect there subclasses to and so on.....
‎2008 Nov 05 7:39 PM
Hi
U can try to do something like this:
parameters: p_class type SEOMETAREL-CLSNAME.
data: _class type SEOMETAREL-CLSNAME.
DATA: BEGIN OF ITAB OCCURS 0,
LIVEL(4) TYPE N,
SUBCLASS type SEOMETAREL-CLSNAME,
END OF ITAB.
data: _level type i.
data: itab_temp like table of itab WITH HEADER LINE.
data: itab_temp2 like table of itab WITH HEADER LINE.
start-of-selection.
move p_class to itab-subclass.
append itab.
MOVE 1 TO itab_temp-livel.
SELECT * FROM SEOMETAREL WHERE CLSNAME = p_class.
move SEOMETAREL-REFCLSNAME to itab_temp-subclass.
append itab_temp.
append itab_temp to itab.
ENDSELECT.
_level = 1.
loop at itab_temp.
_level = _level + 1.
move _level to itab_temp2-livel.
SELECT * FROM SEOMETAREL WHERE CLSNAME = itab_temp-subclass.
MOVE SEOMETAREL-REFCLSNAME TO itab_temp2-subclass.
APPEND itab_temp2.
ENDSELECT.
delete itab_temp.
append lines of: itab_temp2 to itab,
itab_temp2 to itab_temp.
refresh itab_temp2.
endloop.P.s.: I can't try to run this code now.
Max
‎2008 Nov 05 8:09 PM
Hi,
See if this program gives you the basis for what you are looking for. The internal table it_all will contain all the subclasses, and subclasses of all subclasses, etc. starting with the class entered in the parameter. Of course, you don't need it_all since the lcl_relations->subclasses internal table attribute also has the info. I just included it_all as an example of how to get a separate itab (in case you need a different structure for example).
REPORT ztemp.
PARAMETERS: p_class TYPE seoclsname DEFAULT 'CL_SALV_MODEL'.
TYPE-POOLS: seor.
TYPES: BEGIN OF ty_all,
clsname TYPE seoclsname,
END OF ty_all.
DATA: lcl_relations TYPE REF TO cl_oo_class_relations,
it_all TYPE TABLE OF ty_all.
FIELD-SYMBOLS: <fs_subclass> TYPE seor_inheritance_r,
<fs_all> TYPE ty_all.
CREATE OBJECT lcl_relations
EXPORTING
clsname = p_class.
LOOP AT lcl_relations->subclasses ASSIGNING <fs_subclass>.
APPEND INITIAL LINE TO it_all ASSIGNING <fs_all>.
<fs_all>-clsname = <fs_subclass>-clsname.
WRITE: /1 <fs_all>-clsname.
ENDLOOP.
Regards,
Jamie