Tuesday, April 14, 2009

Read the domain value ranges

Sometimes we need to display the description based on the key value of a field. And the description is not in a text table but defined as value range in the domain definition. For example the domain XUDATFM lists all the types of dates possible

image

Using the class CL_ABAP_ELEMDESCR, one can retrieve these values in an internal table of type DDFIXVALUES. Here is an example:

DATA o_rtti_attr TYPE REF TO cl_abap_elemdescr.
DATA t_fixed_values TYPE ddfixvalues.
TRY.
    rtti_attr ?= cl_abap_typedescr=>describe_by_name( 'XUDATFM' ).
  CATCH cx_root.                                            "#EC *
ENDTRY.
*       get the fixed values
CALL METHOD rtti_attr->get_ddic_fixed_values
  RECEIVING
    p_fixed_values = fixed_values
  EXCEPTIONS
    no_ddic_type   = 1
    OTHERS         = 2.

No comments: