‎2009 Nov 06 11:49 AM
Hello Gurus,
i have an internal table filled with class references and i need to acces the one field of a structure of every class.
I am now trying something like this:
loop ref_table assigning <l_wrk_ref_but0id>.
IF <l_wrk_ref_but0id>->m_str_but0id-type = /gkv/cd40_cl_const=>con_pkkv.
ENDIF.
endloop.
I need the field "type" in the structure "m_str_but0id" of every class (reference) in the table. The error that i'm getting is: "Field m_str_but0id unknown".
Please help.
Ioan Constantin.
‎2009 Nov 06 12:49 PM
Hello Ioan
You have to access the field dynamically as well:
DATA:
ld_structure TYPE <name of structure>,
ld_attribute TYPE tabname,
ld_field TYPE fieldname.
FIELD-SYMBOLS:
<ls_struct> TYPE any,
<ld_fld> TYPE any.
ld_attribute = 'M_STR_BUT0ID'.
ld_field = 'TYPE'.
loop ref_table assigning <l_wrk_ref_but0id>.
ASSIGN <l_wrk_ref>but0id>->(ld_attribute) TO <ls_struct>.
ASSIGN COMPONENT (ld_field) OF STRUCTURE <ls_struct> TO <ld_fld>.
" IF <l_wrk_ref_but0id>->m_str_but0id-type = /gkv/cd40_cl_const=>con_pkkv.
IF ( <ld_fld> = /gkv/cd40_cl_const=>con_pkkv ).
...
ENDIF.
endloop.
Even simpler might be the following approach:
LOOP AT ref_table assigning <l_wrk_ref_but0id>
WHERE ( table_line->m_str_but0id-type = /gkv/cd40_cl_const=>con_pkkv ).
...
ENDLOOP.
" Assumption: Itab has class reference type as line type.
Regards
Uwe
‎2009 Nov 06 12:49 PM
Hello Ioan
You have to access the field dynamically as well:
DATA:
ld_structure TYPE <name of structure>,
ld_attribute TYPE tabname,
ld_field TYPE fieldname.
FIELD-SYMBOLS:
<ls_struct> TYPE any,
<ld_fld> TYPE any.
ld_attribute = 'M_STR_BUT0ID'.
ld_field = 'TYPE'.
loop ref_table assigning <l_wrk_ref_but0id>.
ASSIGN <l_wrk_ref>but0id>->(ld_attribute) TO <ls_struct>.
ASSIGN COMPONENT (ld_field) OF STRUCTURE <ls_struct> TO <ld_fld>.
" IF <l_wrk_ref_but0id>->m_str_but0id-type = /gkv/cd40_cl_const=>con_pkkv.
IF ( <ld_fld> = /gkv/cd40_cl_const=>con_pkkv ).
...
ENDIF.
endloop.
Even simpler might be the following approach:
LOOP AT ref_table assigning <l_wrk_ref_but0id>
WHERE ( table_line->m_str_but0id-type = /gkv/cd40_cl_const=>con_pkkv ).
...
ENDLOOP.
" Assumption: Itab has class reference type as line type.
Regards
Uwe
‎2009 Nov 07 11:00 AM
Hello Uwe,
thank you for the response. What do you mean with "table_line" ? Yes the table line is of type class reference.
DATA: ref_table type tab_but0id_ref. " tab_but0id_ref ... table type with line type class reference ( ref to cl_99_dat_obj_but0id)
FIELD-SYMBOLS: <l_wrk_ref_but0id> type ref ro cl_99_dat_obj_but0id.
LOOP AT ref_table assigning <l_wrk_ref_but0id>
WHERE ( table_line->m_str_but0id-type = /gkv/cd40_cl_const=>con_pkkv ).
...
ENDLOOP.
Regards,
Ioan.
‎2009 Nov 07 7:26 PM
What Uwe 'means' is this (actually it is not really 'means'): table_line is used in generic programming. It is not really the name of an internal table line, but more a generic name for 'all' internal tables. So as you can see in the example from Uwe is the generic name 'table_line'.
‎2009 Nov 09 8:30 AM
As far as generic access (not specified type of object being access until runtime) is concerned, Guys are of course right, but as you know line type of table, which is fully typed (specifeid as ref to cl_99_dat_obj_but0id ) there can be a problem of attribute's visibility within class. Ensure that is it a public attribute, not protected or private, otherwise the acces from the outside will not be possible, hence you get the error.
Regards
Marcin