How to immediately access a component of an anonymous structure created with CONV?

The below code gives a syntax error.

DATA: lt_vbeln TYPE TABLE OF vbeln.
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.


  • 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 )
                        ( 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:

    • Constructor Operators for Constructor Expressions: « Unlike method chainings or table expressions, constructor expressions cannot be placed on the left side of a structure component selector, since constructing a structure only to access a single component is pointless. »
      • i.e. the structure component selector being - (e.g. in struct-comp), it's not possible to use something like CONV e1nthdr( xx )-component.
      • It wouldn't be so pointless for CONV, but the documentation doesn't add any precision.
    • Extra information in the same chapter about Constructor Operators:
      • What is possible after a constructor operator, seems limited to NEW and CAST (nothing allowed for other constructor operators): « Expressions with the operators NEW and CAST can be positioned directly in front of the object component selector -> and can occur in chainings. »
      • Remark about LET: « LET expressions can be used to define local helper fields in all suitable constructor expressions. »