Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Access Structure component dynamicaly

Former Member
0 Likes
312

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

1 ACCEPTED SOLUTION
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
266

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

2 REPLIES 2
Read only

franois_henrotte
Active Contributor
0 Likes
266

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.

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
267

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