Skip to Content
0

How to find Assigned field name from field-symbol?

Dec 28, 2016 at 04:34 PM

339

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Fabian Lupa Dec 28, 2016 at 05:10 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

I try this solution and it works.

Thanks..

0
Sandra Rossi Dec 28, 2016 at 05:06 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded