ABAP – Get fixed values of a domain

There are several ways how to get the fixed values of a domain. In this post I present several way including an Object Oriented approach

Functional approach using DD_DOMVALUES_GET

DATA(it_dd07v_tab) = VALUE dd07v_tab( ).
DATA(lv_rc) = VALUE sy-subrc( ).
 
CALL FUNCTION 'DD_DOMVALUES_GET'
  EXPORTING
    domname        = 'CCCATEGORY'
    text           = abap_true
*   LANGU          = ' '
*   BYPASS_BUFFER  = ' '
  IMPORTING
    rc             = lv_rc
  TABLES
    dd07v_tab      = it_dd07v_tab
  EXCEPTIONS
    wrong_textflag = 1
    OTHERS         = 2.
 
IF sy-subrc = 0.
  IF lv_rc = 0.
    cl_demo_output=>display( it_dd07v_tab ).
  ENDIF.
ENDIF.

Direct SQL approach

* Name of the domain
DATA(lv_domain) = 'CCCATEGORY'.
* logon laguage
DATA(lv_lang) = cl_abap_syst=>get_logon_language( ).
 
SELECT l~domvalue_l, t~ddtext
  INTO TABLE @DATA(it_dom)
  FROM dd07l AS l
  INNER JOIN dd07t AS t ON l~domname = t~domname AND 
                           l~valpos = t~valpos AND 
                           l~domvalue_l = t~domvalue_l
  WHERE l~domname    = @lv_domain
    AND t~ddlanguage = @lv_lang.
 
cl_demo_output=>display( it_dom ).

OO Approach #1

DATA(it_rsdomaval) = VALUE re_t_rsdomaval( ).
 
* DDIC-Objekt: Domain
cl_reca_ddic_doma=>get_values( EXPORTING id_name   = 'CCCATEGORY'
                               IMPORTING et_values = it_rsdomaval ).
 
cl_demo_output=>display( it_rsdomaval ).

OO Approach #2

DATA(lv_dd01v) = VALUE dd01v( ).
DATA(it_rsdomaval) = VALUE re_t_rsdomaval( ).
 
* DDIC-Objekt: Domain
cl_reca_ddic_doma=>get_complete( EXPORTING id_name      = 'CCCATEGORY'
                                 IMPORTING es_header    = lv_dd01v
                                           et_rsdomaval = it_rsdomaval ).
 
cl_demo_output=>write_data( lv_dd01v ).
cl_demo_output=>write_data( it_rsdomaval ).
cl_demo_output=>display( ).

OO Approach #3

CLASS lcl_domvalues DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS: get_by_type
      IMPORTING
                iv_data               TYPE any
      RETURNING VALUE(rt_ddfixvalues) TYPE ddfixvalues.
    CLASS-METHODS: get_by_name
      IMPORTING
                iv_name               TYPE domname
      RETURNING VALUE(rt_ddfixvalues) TYPE ddfixvalues.
ENDCLASS.
 
CLASS lcl_domvalues IMPLEMENTATION.
 
  METHOD get_by_type.
    TRY.
        rt_ddfixvalues = CAST cl_abap_elemdescr( cl_abap_typedescr=>describe_by_data( iv_data ) )->get_ddic_fixed_values( ).
      CATCH cx_root.
    ENDTRY.
  ENDMETHOD.
 
  METHOD get_by_name.
    TRY.

        rt_ddfixvalues = CAST cl_abap_elemdescr( cl_abap_typedescr=>describe_by_name( iv_name ) )->get_ddic_fixed_values( ).
      CATCH cx_root.
    ENDTRY.
  ENDMETHOD.
 
ENDCLASS.
 
START-OF-SELECTION.
 
* Domain by type of a variable
  DATA(lv_cat) = VALUE cccategory( ).
  DATA(it_by_type) = lcl_domvalues=>get_by_type( lv_cat ).
 
* Domain by its name
  DATA(it_by_name) = lcl_domvalues=>get_by_name( 'CCCATEGORY' ).
 
  cl_demo_output=>write_data( it_by_type ).
  cl_demo_output=>write_data( it_by_name ).
 
  cl_demo_output=>display( ).

Leave a Reply