2014 Aug 12 10:30 AM
Hi experts. Problem is following:
I have an export parameter es_data in my method with type 'any'. Is there a possibility to check whether this structure contains some field. For example I do need to know whether es_data contains field 'userName' . If it contains I want to fill it. Guess that it could be done with field-symbols, but dunno how.
Thanks in advance!
2014 Aug 12 10:58 AM
Using field-symbols,
FIELD-SYMBOLS: <comp> TYPE any.
DATA name TYPE string,
name = 'userName'.
ASSIGN COMPONENT name OF STRUCTURE es_data TO <comp>.
IF sy-subrc EQ 0.
"Field exists.
ENDIF.
Use RTTS classes & methods,
DATA: tab TYPE REF TO cl_abap_structdescr,
comp_tab TYPE cl_abap_structdescr=>component_table.
tab?= cl_abap_typedescr=>describe_by_name( es_data ).
comp_tab = tab->get_components( ).
READ TABLE comp_tab WITH KEY name = 'userName' TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
"Field exists.
ENDIF.
2014 Aug 12 10:52 AM
DATA: info TYPE dd_x031l_table,
descr_ref TYPE REF TO cl_abap_typedescr.
descr_ref = cl_abap_typedescr=>describe_by_data( es_data ).
info = descr_ref->get_ddic_object( ).
Table info will contain all fields.
Regards,
Ulrich
2014 Aug 12 10:58 AM
Using field-symbols,
FIELD-SYMBOLS: <comp> TYPE any.
DATA name TYPE string,
name = 'userName'.
ASSIGN COMPONENT name OF STRUCTURE es_data TO <comp>.
IF sy-subrc EQ 0.
"Field exists.
ENDIF.
Use RTTS classes & methods,
DATA: tab TYPE REF TO cl_abap_structdescr,
comp_tab TYPE cl_abap_structdescr=>component_table.
tab?= cl_abap_typedescr=>describe_by_name( es_data ).
comp_tab = tab->get_components( ).
READ TABLE comp_tab WITH KEY name = 'userName' TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
"Field exists.
ENDIF.
2014 Aug 12 11:05 AM
DATA: lr_structdescr TYPE REF TO cl_abap_structdescr.
DATA: lt_components TYPE abap_compdescr,
ls_component like line of lt_components.
*
FIELD-SYMBOLS: <fs_line> TYPE any.
*
ASSIGN es_data TO <fs_line>.
IF sy-subrc EQ 0
lr_structdescr ?= cl_abap_typedescr=>describe_by_data( <fs_line> ).
lt_components = lr_strucdescr->get_components( ). "get field names
READ TABLE lt_components INTO ls_component WITH KEY name = 'userName'.
IF sy-subrc EQ 0.
* Do your assignment here
ENDIF.
ENDIF.
2014 Aug 12 1:02 PM