sap - Return a list of all atributes of a persistent class in abap -
i got persistent class on custom table. get_persistent_by_query can list of objects. how can objects of atributes printed user (e.g alv)?
can call instance function if click on somehow?
here dynamic solution, query_data result returned call get_persistent_by_query( ). in end data stored in structured table <table>, can use display in alv. note there little control on order of field. real use you'd have add error handling well.
data: pers_obj_desc type ref cl_abap_classdescr, pers_query_data type ref data, field_cat type lvc_t_fcat. field-symbols: <table> type standard table. loop @ query_data assigning field-symbol(<pers_data>). @ first. pers_obj_desc ?= cl_abap_typedescr=>describe_by_object_ref( p_object_ref = <pers_data> ). loop @ pers_obj_desc->attributes assigning field-symbol(<attr_desc>). append initial line field_cat assigning field-symbol(<field_cat>). <field_cat>-fieldname = <attr_desc>-name. <field_cat>-intlen = <attr_desc>-length. <field_cat>-datatype = <attr_desc>-type_kind. endloop. cl_alv_table_create=>create_dynamic_table( exporting it_fieldcatalog = field_cat importing ep_table = pers_query_data ). assign pers_query_data->* <table>. endat. " first append initial line <table> assigning field-symbol(<line>). loop @ pers_obj_desc->attributes assigning <attr_desc>. assign component <attr_desc>-name of structure <line> field-symbol(<field>). data(getter) = 'get_' && <attr_desc>-name. call method <pers_data>->(getter) receiving result = <field>. endloop. endloop.
Comments
Post a Comment