dynamictype-conversionabapidoc

How to access a LCHR component of IDoc structure?


The below code gives a syntax error.

DATA: lt_vbeln TYPE TABLE OF vbeln.
SELECT * FROM EDID4 INTO TABLE @DATA(lt_edid4).
lt_vbeln = value #( for ls_edid4 in lt_edid4 ( conv E1NTHDR( ls_edid4-sdata )-vbeln ).

Table EDID4 contains field SDATA of type LCHR (char, length 1000). I want to convert it into structure E1NTHDR and immediately read its VBELN property.

How to do this inline ?

EDIT: The system has SAP_ABA 75G SP 0003.


Solution

  • You may use this code in all versions since ABAP 7.40 SP 5, by defining an auxiliary variable with LET ... IN:

    DATA: lt_vbeln TYPE TABLE OF vbeln.
    SELECT * FROM edid4 INTO TABLE @DATA(lt_edid4).
    lt_vbeln = VALUE #( FOR ls_edid4 IN lt_edid4
                        WHERE ( segnam = 'E1NTHDR' )
                        LET aux_e1nthdr = CONV e1nthdr( ls_edid4-sdata )
                        IN
                        ( aux_e1nthdr-vbeln ) ).
    

    EDIT: There are new ways of accessing components dynamically in more recent ABAP versions.

    In the latest ABAP version, 7.58, there is no better way. Reference in the ABAP documentation: