In ABAP, if you want to write a method that reads domain texts (i.e., the text descriptions of domain values like those found in table TDDD or via function module DD_DOMVALUES_GET), you can use either direct table access or more appropriately, the standard function module provided by SAP.
Below is an example of how to write a method in a class that retrieves domain texts using the function module DD_DOMVALUES_GET.
✅ Example: Method to Read Domain Texts
CLASS zcl_domain_reader DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF ty_dom_value,
value TYPE string,
meaning TYPE string,
END OF ty_dom_value.
TYPES: tt_dom_values TYPE STANDARD TABLE OF ty_dom_value WITH KEY value.
METHODS read_domain_texts
IMPORTING
iv_domain_name TYPE domname
EXPORTING
et_values TYPE tt_dom_values
RAISING
cx_sy_dyn_call_error.
ENDCLASS.
CLASS zcl_domain_reader IMPLEMENTATION.
METHOD read_domain_texts.
DATA: lt_ddtext TYPE ddtext_t,
ls_ddtext TYPE ddtext.
DATA: lv_selected_value TYPE domvalue_l,
lv_add_sel_text TYPE c LENGTH 1 VALUE 'X'.
CALL FUNCTION 'DD_DOMVALUES_GET'
EXPORTING
domname = iv_domain_name
langu = sy-langu
add_seltexts_to_key = lv_add_sel_text
IMPORTING
selected_value = lv_selected_value
TABLES
ddtext = lt_ddtext
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE cx_sy_dyn_call_error.
ENDIF.
LOOP AT lt_ddtext INTO ls_ddtext.
APPEND VALUE #( value = ls_ddtext-key
meaning = ls_ddtext-text )
TO et_values.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
📌 Usage Example:
DATA: lo_reader TYPE REF TO zcl_domain_reader,
lt_values TYPE zcl_domain_reader=>tt_dom_values.
CREATE OBJECT lo_reader.
CALL METHOD lo_reader->read_domain_texts
EXPORTING
iv_domain_name = 'WAERS' " Currency code domain
IMPORTING
et_values = lt_values.
LOOP AT lt_values ASSIGNING FIELD-SYMBOL(<fs_value>).
WRITE: / <fs_value>-value, <fs_value>-meaning.
ENDLOOP.
💡 Notes:
- This method uses the standard function module
DD_DOMVALUES_GET, which handles all domain types, including fixed values and foreign key domains.
- The result is returned as an internal table with two fields:
value and meaning.
- You can extend this method to handle additional parameters like filtering for specific values or handling inactive entries.
Let me know if you need to include inactive values, translations, or filter by language.