‎2007 Sep 18 9:44 AM
Hi friends,
can anyone tells me how to access Structure component dynamicaly?
for ex.passing structure name in parameter field of selection screen.
than loop through all it's component.
Thanks in advance
‎2007 Sep 18 9:50 AM
Hi,
Check this
PARAMETERS: str(40) type c.
DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.
DATA: lt_comp TYPE cl_abap_structdescr=>component_table.
DATA: ls_comp LIKE LINE OF lt_comp.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_name( STR ).
lt_comp = lr_rtti_struc->get_components( ).
"lt_comp as all the components of the structure.
loop at lt_comp into ls_comp.
write: ls_comp-name.
endloop.
" execute this code by passing any structure
Regards,
Sesh
‎2007 Sep 18 9:48 AM
Here is some sample code:
FIELD-SYMBOLS: <fld> TYPE ANY.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE p_struc TO <fld>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
do something with your component
ENDDO.
‎2007 Sep 18 9:50 AM
Hi,
Check this
PARAMETERS: str(40) type c.
DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.
DATA: lt_comp TYPE cl_abap_structdescr=>component_table.
DATA: ls_comp LIKE LINE OF lt_comp.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_name( STR ).
lt_comp = lr_rtti_struc->get_components( ).
"lt_comp as all the components of the structure.
loop at lt_comp into ls_comp.
write: ls_comp-name.
endloop.
" execute this code by passing any structure
Regards,
Sesh