First of all, it is recommended to create an interface or an abstract superclass, and your various classes will implement this interface or subclass, that an abstract class will save you from unnecessary casting. So, let's say you have ZIF_FOO with implementations ZCL_BAR and ZCL_BAZ. Table may be
TYPES: BEGIN OF t_line type_name TYPE seoclass, instance TYPE REF TO zif_foo, END OF t_line. DATA: lt_instances TYPE STANDARD TABLE OF t_line, ls_instance TYPE t_line.
Then you can fill in the table as follows:
ls_instance-type_name = 'ZCL_BAR'. " or wherever you get this value from CREATE OBJECT ls_instance-instance TYPE (ls_instance-type_name).
If you want to use local classes, you can do the same - just use a longer type name (SEOCLASS with 30 characters will not be enough) and specify the type name as described in the RTTI online documentation:
ls_instance-typename = '\PROGRAM=ZMYREPORT\CLASS=LCL_MYCLASS'.
source share