‎2008 Jun 10 10:51 AM
Hi there,
I want to code something for "looping" through a structure, I mean that I get every field of a structure and its value.
Now I have it like this:
DO.
ADD 1 TO lv_comp_count.
ASSIGN COMPONENT lv_comp_count OF STRUCTURE is_data TO <fs_comp>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
* ....
ENDDO.
But here I have the problem that I don't know the name of the field in this coding. How can I code this similar so that I get both: value and name of the field??
Thanks!
Regards,
Markus
‎2008 Jun 10 11:18 AM
Hi,
perhaps the following funtion module will help you :
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = <name_of_you_struture>
TABLES
components = lt_components.
Regards.
David
‎2008 Jun 10 11:32 AM
And one hard-code for example
DATA: COMP LIKE RSTRUCINFO OCCURS 0 WITH HEADER LINE.
CALL 'AB_STRUC_INFO'
ID 'PROGRAM' FIELD SY-REPID
ID 'STRUCNAME' FIELD 'structure name'
ID 'STRUCINFO' FIELD COMP-*SYS*.
LOOP AT COMP.
...
ENDLOOP.
.
Return table with fields of internal structure in program.
Good luck.
‎2020 Sep 25 9:26 PM
Hana dynamic implementation:
FIELD-SYMBOLS: <lv_field> type any.
data: lr_descr_struc TYPE REF TO data.
data: lo_structdescr TYPE REF TO cl_abap_structdescr.
CLEAR: lr_descr_struc, lo_structdescr.
CREATE DATA lr_descr_struc like ch_service_datax. " <- any type
lo_structdescr ?= cl_abap_structdescr=>describe_by_data_ref( p_data_ref = lr_descr_struc ).
LOOP AT lo_structdescr->components ASSIGNING FIELD-SYMBOL(<lv_component>).
if <lv_component>-name(1) eq 'Z'.
ASSIGN COMPONENT <lv_component>-name of STRUCTURE ch_service_datax to <lv_field>.
if <lv_field> is ASSIGNED.
<lv_field> = abap_true.
endif.
endif.
ENDLOOP.