Application Development 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: 

IDOC data split by dynamic structure

Former Member
0 Kudos

Hello,

In a specific program, I want to split a string (EDID4-SDATA)  with a dynamic structure.

The structure should not be defined with Data instruction. Because  the name of this structure (existing in dictionnary) is save in a table EDID4 field

SEGNAM. This structure can be any IDOC segment.

So my first solution is to declare (with data instruction)  all segments as structure that I use in this program.

And define the string EDID4-SDATA as a field symbol.

I am looking for another solution which avoid to create all segment as structure in data paragraph.

Best regards

Stéphane

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Are you aware of RTTI/RTTC classes that can be used to create structure dynamically?

Have a look at below snippet. Once field symbol has the data, you can access specific field using assign component ... of structure statement.


DATA: lo_segment_type       TYPE REF TO cl_abap_structdescr,

      lo_segment_data       TYPE REF TO data,

      ls_edid4              TYPE edid4.

FIELD-SYMBOLS <ls_segment_data> TYPE any.

SELECT SINGLE * FROM edid4 INTO ls_edid4.

IF sy-subrc EQ 0.

  lo_segment_type ?= cl_abap_structdescr=>describe_by_name( ls_edid4-segnam ).

  CREATE DATA lo_segment_data TYPE HANDLE lo_segment_type.

  ASSIGN lo_segment_data->* TO <ls_segment_data>.

  IF <ls_segment_data> IS ASSIGNED.

    <ls_segment_data> = ls_edid4-sdata.

  ENDIF.

  BREAK-POINT.

ENDIF.

/.

1 REPLY 1

Former Member
0 Kudos

Are you aware of RTTI/RTTC classes that can be used to create structure dynamically?

Have a look at below snippet. Once field symbol has the data, you can access specific field using assign component ... of structure statement.


DATA: lo_segment_type       TYPE REF TO cl_abap_structdescr,

      lo_segment_data       TYPE REF TO data,

      ls_edid4              TYPE edid4.

FIELD-SYMBOLS <ls_segment_data> TYPE any.

SELECT SINGLE * FROM edid4 INTO ls_edid4.

IF sy-subrc EQ 0.

  lo_segment_type ?= cl_abap_structdescr=>describe_by_name( ls_edid4-segnam ).

  CREATE DATA lo_segment_data TYPE HANDLE lo_segment_type.

  ASSIGN lo_segment_data->* TO <ls_segment_data>.

  IF <ls_segment_data> IS ASSIGNED.

    <ls_segment_data> = ls_edid4-sdata.

  ENDIF.

  BREAK-POINT.

ENDIF.

/.