2010 Apr 20 7:05 PM
Hi Experts,
it is possible get all attributes from a structure in a loop or so on?
e.g.
<structure>-<attribute> = Loop at <structure>.
Thanks in advance
2010 Apr 20 7:36 PM
Thanks, thats work if define my own structure.
But if I use the structure CRMT_BUPA_IL_HEADER_SEARCH I only get I subset of sttributes?
data: ls_struct type CRMT_BUPA_IL_HEADER_SEARCH.
DATA:
lr_structdescr TYPE REF TO cl_abap_structdescr,
lr_datadescr TYPE REF TO cl_abap_datadescr,
lt_components TYPE abap_component_tab,
ls_components TYPE LINE OF abap_component_tab.
now decribe the LS_STRUCT structure
lr_structdescr ?= cl_abap_structdescr=>DESCRIBE_BY_DATA( ls_struct ).
lt_components = lr_structdescr->GET_COMPONENTS( ).
loop at lt_components into ls_components.
lr_datadescr = ls_components-type.
write:/ ls_components-name, lr_datadescr->TYPE_KIND, lr_datadescr->length.
endloop.
2010 Apr 20 7:19 PM
You can do something like this to describe the fields of a structure.
TYPE-POOLS: abap.
Types: begin of t_struct,
var1 type i,
var2 type string,
var3 type c,
end of t_Struct.
data: ls_struct type t_struct.
DATA:
lr_structdescr TYPE REF TO cl_abap_structdescr,
lr_datadescr TYPE REF TO cl_abap_datadescr,
lt_components TYPE abap_component_tab,
ls_components TYPE LINE OF abap_component_tab.
* now decribe the LS_STRUCT structure
lr_structdescr ?= cl_abap_structdescr=>DESCRIBE_BY_DATA( ls_struct ).
lt_components = lr_structdescr->GET_COMPONENTS( ).
loop at lt_components into ls_components.
lr_datadescr = ls_components-type.
write:/ ls_components-name, lr_datadescr->TYPE_KIND, lr_datadescr->length.
endloop.
Regards,
Rich Heilman
2010 Apr 20 7:36 PM
Thanks, thats work if define my own structure.
But if I use the structure CRMT_BUPA_IL_HEADER_SEARCH I only get I subset of sttributes?
data: ls_struct type CRMT_BUPA_IL_HEADER_SEARCH.
DATA:
lr_structdescr TYPE REF TO cl_abap_structdescr,
lr_datadescr TYPE REF TO cl_abap_datadescr,
lt_components TYPE abap_component_tab,
ls_components TYPE LINE OF abap_component_tab.
now decribe the LS_STRUCT structure
lr_structdescr ?= cl_abap_structdescr=>DESCRIBE_BY_DATA( ls_struct ).
lt_components = lr_structdescr->GET_COMPONENTS( ).
loop at lt_components into ls_components.
lr_datadescr = ls_components-type.
write:/ ls_components-name, lr_datadescr->TYPE_KIND, lr_datadescr->length.
endloop.
2010 Apr 20 8:01 PM
I suppose you must be referring to fields that are parts of an INCLUDE or APPEND structure. Yes, in that case, they will be missing the the example code. You have to do some recursive type calling of the methods to retrieve the structure of the include structures. Some similar to this. rsbasidoc contains both an INCLUDE structure as well as an APPEND structure, and the fields of these structures are now outputted as well. If your structure has a deeper structure you would have to code for the next level as well. You will probabaly want to come up with some kind of recursive calling here so that you reuse a lot of the example coding.
DATA: ls_struct TYPE rsbasidoc .
DATA:
lr_structdescr TYPE REF TO cl_abap_structdescr,
lr_datadescr TYPE REF TO cl_abap_datadescr,
lr_datadescr_incl TYPE REF TO cl_abap_datadescr,
lt_components TYPE abap_component_tab,
ls_components TYPE LINE OF abap_component_tab,
lt_components_incl TYPE abap_component_tab,
ls_components_incl TYPE LINE OF abap_component_tab.
* now decribe the LS_STRUCT structure
lr_structdescr ?= cl_abap_structdescr=>describe_by_data( ls_struct ).
lt_components = lr_structdescr->get_components( ).
LOOP AT lt_components INTO ls_components.
lr_datadescr = ls_components-type.
IF ls_components-as_include = space.
WRITE:/ ls_components-name, lr_datadescr->type_kind, lr_datadescr->length.
ELSE. " IF include or append structure, you need to get that structures components now.
lr_structdescr ?= ls_components-type.
lt_components_incl = lr_structdescr->get_components( ).
LOOP AT lt_components_incl INTO ls_components_incl.
lr_datadescr_incl = ls_components_incl-type.
WRITE:/ ls_components_incl-name, lr_datadescr_incl->type_kind, lr_datadescr_incl->length.
ENDLOOP.
ENDIF.
ENDLOOP.
Regards,
Rich Heilman
2010 Apr 21 1:11 PM
Thanks that wokrs fine. But my next problem is that now I know the attributes from the structure but no her value?
How can I reach the value of every attribute?
2010 Apr 22 7:38 AM
Is there no way to read the attribute name and value from a structure in a loop o so on without hardcoded <structureName>-<attributeName> ?
Pls help...
2010 Apr 22 9:22 PM