This method is based on Runtime Type Services (RTTS) classes. RTTS can find out domain just from variable and will return domain fix values, so you no longer have to specify domain name.
I will be using domain KOART for demo.
I use this domain to work out FI secondary index tables. For example, in domain D
is for customer therefore secondary index tables for customer are BSID
and BSAD. Similarly for vendor and GL accounts tables are BSIK, BSAK,
BSIS and BSAD respectively.
Coming back to topic. Here is the code in form of local class and
method which does the magic. From calling program you need to just pass
the variable to method GET_DOMAIN_DESCR and it will return you the
description of fixed values which is in variable itself.*----------------------------------------------------------------------* * CLASS cl_domain_desc DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cl_domain_desc DEFINITION . PUBLIC SECTION . METHODS : get_domain_descr IMPORTING i_field TYPE any i_langu TYPE syst-langu DEFAULT sy-langu RETURNING value(return) TYPE ddtext . ENDCLASS . "cl_domain_desc DEFINITION *----------------------------------------------------------------------* * CLASS cl_domain_desc IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cl_domain_desc IMPLEMENTATION . METHOD get_domain_descr. DATA : lo_element TYPE REF TO cl_abap_elemdescr , li_values TYPE ddfixvalues , ls_value TYPE ddfixvalue . lo_element ?= cl_abap_typedescr=>describe_by_data( i_field ) . li_values = lo_element->get_ddic_fixed_values( i_langu ) . READ TABLE li_values INTO ls_value WITH KEY low = i_field . IF sy-subrc = 0 . return = ls_value-ddtext . ENDIF . ENDMETHOD . "GET_DOMAIN_DESCR ENDCLASS . "cl_domain_desc IMPLEMENTATION |
DATA : lo_domain_text_test TYPE REF TO cl_domain_desc . DATA : lv_domain TYPE koart VALUE 'A' , "variable defined using domain lv_data_elem TYPE bkoart VALUE 'K' , "variable defined using data element lv_tab_field TYPE bseg-koart VALUE 'D' , "variable defined using table field lv_like LIKE lv_domain VALUE 'M' . "variable defined using LIKE DATA : lv_description TYPE ddtext . *--------------------------------------------------------------------* * Start of Selection *--------------------------------------------------------------------* START-OF-SELECTION . CREATE OBJECT lo_domain_text_test . CLEAR lv_description . lv_description = lo_domain_text_test->get_domain_descr( lv_domain ) . WRITE : / 'Domain variable : ' , lv_description . CLEAR lv_description . lv_description = lo_domain_text_test->get_domain_descr( lv_data_elem ) . WRITE : / 'Data element variable : ' , lv_description . CLEAR lv_description . lv_description = lo_domain_text_test->get_domain_descr( lv_tab_field ) . WRITE : / 'Table field variable : ' , lv_description . CLEAR lv_description . lv_description = lo_domain_text_test->get_domain_descr( lv_like ) . WRITE : / 'Variable using LIKE : ' , lv_description . |
Serkan AKKAVAK
Computer Engineer / ABAP Developer
serkurumsal@yandex.com
You can ask me all your questions about SAP and Abap .
Social Plugin