‎2008 Apr 23 1:50 PM
Hi all,
i'm in 4.6C version.
i would like create a FORM with a structure as a parameter and i would like to analyse the components of the structure and finally serialize all fields of the structure in a string.
My problem is that in my FORM i don't have the type of the structure, i can get it, but i can not access to the field of the structure, compiler tell me 'no type for the structure'.
For example:
data: l_data type p0045,
l_str type string.
PERFORM FILL_data changing l_data.
PERFORM serialize_struc using l_data changing l_str.
Can you help me please ?
Thanks
‎2008 Apr 23 2:07 PM
Good chance you need to pass it in a single line table.
DATA: l_data TYPE p0045,
l_str TYPE string,
it_data LIKE STANDARD TABLE OF l_data.
*
*
*
REFRESH it_data.
APPEND l_data TO it_data.
PERFORM fill_data TABLES it_data.
PERFORM serialize_struc TABLES it_data CHANGING l_str.
*&---------------------------------------------------------------------*
*& Form FILL_data
*&---------------------------------------------------------------------*
* -->P_IT_DATA text
*----------------------------------------------------------------------*
FORM fill_data TABLES p_it_data STRUCTURE l_data.
READ TABLE p_it_data INTO l_data INDEX 1.
* Do you code here
ENDFORM. " FILL_data
*&---------------------------------------------------------------------*
*& Form serialize_struc
*&---------------------------------------------------------------------*
* -->P_IT_DATA text
* <--P_L_STR text
*----------------------------------------------------------------------*
FORM serialize_struc TABLES p_it_data STRUCTURE l_data
CHANGING p_l_str.
READ TABLE p_it_data INTO l_data INDEX 1.
* Do you code here
ENDFORM. " serialize_struc
‎2008 Apr 23 3:11 PM
I don't think that, in ECC6 i succeeded my need, but in 4.6 it lacks instructions
‎2008 Apr 23 3:42 PM
Hi,
try this and on break have a look in l_fields_table:
REPORT test.
DATA:
struc TYPE mara,
l_oref_structure TYPE REF TO cl_abap_structdescr,
l_fields_table TYPE TABLE OF rfc_fields.
PERFORM form_with_unknown_struc USING struc.
&----
*& Form FORM_WITH_UNKNOWN_STRUC
&----
FORM form_with_unknown_struc USING struc.
DATA:
l_oref_structure TYPE REF TO cl_abap_structdescr,
l_fields_table TYPE TABLE OF rfc_fields.
l_oref_structure ?= cl_abap_typedescr=>describe_by_data( struc ).
PERFORM build_field_table TABLES l_fields_table
USING l_oref_structure.
BREAK-POINT.
ENDFORM. " FORM_WITH_UNKNOWN_STRUC
&----
*& Form build_field_table
&----
FORM build_field_table TABLES pc_tab_fields STRUCTURE rfc_fields
USING value(pi_oref_structure)
TYPE REF TO cl_abap_structdescr.
DATA l_tabname TYPE dd02l-tabname.
DATA l_component TYPE abap_compdescr.
DATA l_field TYPE rfc_fields.
DATA l_offset TYPE i.
SEARCH pi_oref_structure->absolute_name FOR '\TYPE='.
IF sy-subrc = 0.
sy-fdpos = sy-fdpos + STRLEN( '\TYPE=' ) .
l_tabname = pi_oref_structure->absolute_name+sy-fdpos.
ELSE.
l_tabname = 'UNKNOWN'.
ENDIF.
CLEAR l_offset.
l_field-tabname = l_tabname.
LOOP AT pi_oref_structure->components INTO l_component.
MOVE-CORRESPONDING l_component TO l_field.
l_field-fieldname = l_component-name.
l_field-exid = l_component-type_kind.
l_field-intlength = l_component-length.
l_field-position = sy-tabix.
l_field-offset = l_offset.
l_offset = l_offset + l_field-intlength.
APPEND l_field TO pc_tab_fields.
ENDLOOP.
ENDFORM. " BUILD_FIELD_TABLE
With kind regards
Walter Habich