Skip to Content

How to find Assigned field name from field-symbol?

Hi,

Is it possible to find fieldname from field-symbol? For example :

    data : begin of ls_data,
            menge1 type menge_d,
            menge2 type menge_d,
           end of ls_data.

   ASSIGN COMPONENTS 'MENGE1' OF STRUCTURE ls_data 
                  TO FIELD-SYMBOL(<menge>).

I need to find which field ( menge1 or menge2 ) is assigned.

I try : CL_ABAP_ELEMDESCR, CL_ABAP_STRUCTDESCR etc. they dont return fieldname, they return field type.

Kind Regards

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Dec 28, 2016 at 05:10 PM

    Maybe something like this?

    DATA: BEGIN OF ls_data,
            menge1 TYPE menge_d,
            menge2 TYPE menge_d,
          END OF ls_data.
    
    
    ASSIGN COMPONENT 'MENGE1' OF STRUCTURE ls_data TO FIELD-SYMBOL(<menge>).
    
    
    DO.
      ASSIGN COMPONENT sy-index OF STRUCTURE ls_data TO FIELD-SYMBOL(<lg_comparison>).
      IF <lg_comparison> IS NOT ASSIGNED.
        EXIT.
      ENDIF.
      IF REF #( <lg_comparison> ) = REF #( <menge> ).
        DATA(lo_descr) = CAST cl_abap_structdescr(
                                cl_abap_typedescr=>describe_by_data( ls_data )
                              ).
        WRITE lo_descr->components[ sy-index ]-name.
      ENDIF.
      UNASSIGN <lg_comparison>.
    ENDDO.
    

    http://help.sap.com/abapdocu_751/en/abenlogexp_rules_operands_ref.htm

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 28, 2016 at 05:06 PM

    It's impossible directly, but it's usually possible to find workarounds.

    Add comment
    10|10000 characters needed characters exceeded