CL_ABAP_TYPEDESCR,"Reflection" in the ABAP

"Reflection" is a term commonly used in Java programming,but there is one class in ABAP that has similar behaviors,it is "CL_ABAP_TYPEDESCR"

The Structure of CL_ABAP_TYPEDESCR.

CL_ABAP_TYPEDESCR

  • CL_ABAP_DATADESCR
    • CL_ABAP_ELEMDESCR
    • CL_ABAP_REFDESCR
    • CL_ABAP_COMPLEXDESCR
      • CL_ABAP_STRUCTDESCR
      • CL_ABAP_TABLEDESCR
  • CL_ABAP_OBJECTDESCR
    • CL_ABAP_CLASSDESCR
    • CL_ABAP_INTFDESCR

Example of CL_ABAP_TYPEDESCR usage.

Below tips are very helpful in implicit enhancements

"Supposed that <F1> is "MARA-MATNR"
DATA:LO_TYPEDESCR    TYPE REF TO CL_ABAP_TYPEDESCR,
          LV_TYPE   TYPE STRING.

LO_TYPEDESCR = CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <F1> )."data type
LV_TYPE = LO_TYPEDESCR->GET_RELATIVE_NAME( )."This would be "CHAR10"

LO_TYPEDESCR = CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( <F1> )."data lable
LV_TYPE = LO_TYPEDESCR->GET_RELATIVE_NAME( )."This would be "MATNR"
posted @ 2019-06-23 11:07  auroracj  阅读(262)  评论(0编辑  收藏  举报