[ABAP] Systemnamen ermitteln

* Variante 1 (SQL)
DATA(man) = cl_abap_syst=>get_client( ).

SELECT SINGLE logsys FROM t000 INTO @DATA(lv_logsys) WHERE mandt = @man.

IF sy-subrc = 0.
  WRITE: / lv_logsys.
ENDIF.

* Variante 2 (OWN_LOGICAL_SYSTEM_GET)
DATA: lv_logsys TYPE tbdls-logsys.

CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
  IMPORTING
    own_logical_system             = lv_logsys
  EXCEPTIONS
    own_logical_system_not_defined = 1
    OTHERS                         = 2.

IF sy-subrc = 0.
  WRITE: / lv_logsys.
ENDIF.

[ABAP] Wichtige Systemvariablen mit der ABAP Systemklasse auslesen

* Alias User
WRITE: / cl_abap_syst=>get_alias_user( ).
* Mandant
WRITE: / cl_abap_syst=>get_client( ).
* Programmname
WRITE: / cl_abap_syst=>get_current_program( ).
* Applikationsserver
WRITE: / cl_abap_syst=>get_host_name( ).
* Instanz
WRITE: / cl_abap_syst=>get_instance_name( ).
* akt. Sprachenschlüssel
WRITE: / cl_abap_syst=>get_language( ).
* Anmeldesprache
WRITE: / cl_abap_syst=>get_logon_language( ).
* Session Anmeldestatus
CASE cl_abap_syst=>get_session_authentication( ).
  WHEN cl_abap_syst=>session_authenticated_user.
    WRITE: / 'Session läuft unter Benutzerkennung (nach Anmeldung).'.
  WHEN cl_abap_syst=>session_configured_identity.
    WRITE: / 'Session läuft unter (technischer) Servicebenutzer-Kennung.'.
  WHEN cl_abap_syst=>session_system_account.
    WRITE: / 'Session läuft unter Systemkennung (keine Anmeldung erfolgt).'.
  WHEN OTHERS.
    WRITE: / 'Session läuft unter unbekanntem Kontext.'.
ENDCASE.
* Transaktionscode
WRITE: / cl_abap_syst=>get_transaction_code( ).
* User
WRITE: / cl_abap_syst=>get_user_name( ).

[ABAP] Wertebereich einer Domäne auslesen

Variante 1 (get_ddic_fixed_values)

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.
* liefert Typebeschreibung für DDIC-Typ
        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.
* liefert Typebeschreibung für DDIC-Typ
        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.

* Domäne über Variablen-Typ
  DATA(lv_cat) = VALUE cccategory( ).
  DATA(it_by_type) = lcl_domvalues=>get_by_type( lv_cat ).

* Domäne über 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( ).

Variante 2 (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.

Variante 3 (SQL)

* Name der Domäne
DATA(lv_domain) = 'CCCATEGORY'.
* Anmeldesprache
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 ).

Variante 4 (cl_reca_ddic_doma)

DATA(it_rsdomaval) = VALUE re_t_rsdomaval( ).

* DDIC-Objekt: Domäne
cl_reca_ddic_doma=>get_values( EXPORTING id_name   = 'CCCATEGORY'
                               IMPORTING et_values = it_rsdomaval ).

cl_demo_output=>display( it_rsdomaval ).

Variante 5 (cl_reca_ddic_doma)

DATA(lv_dd01v) = VALUE dd01v( ).
DATA(it_rsdomaval) = VALUE re_t_rsdomaval( ).

* DDIC-Objekt: Domäne
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( ).

Links

[ABAP] Rolle eines Mandanten bestimmen

* aktueller Mandant
DATA(man) = cl_abap_syst=>get_client( ).

* verfügbare Mandanten
SELECT SINGLE *
  INTO @DATA(lv_t000)
  FROM t000
  WHERE mandt = @man.

IF sy-subrc = 0.
  DATA(it_dd07v_tab) = VALUE dd07v_tab( ).
  DATA(lv_rc) = VALUE sy-subrc( ).

* DDextern: Externe Schnittstelle zum Lesen der Domänenfestwerte
  CALL FUNCTION 'DD_DOMVALUES_GET'
    EXPORTING
      domname        = 'CCCATEGORY' " Feld CCCATEGORY: Client Control: Rolle des Mandanten (Productive, Test,...)
      text           = abap_true    " Text holen
    IMPORTING
      rc             = lv_rc
    TABLES
      dd07v_tab      = it_dd07v_tab
    EXCEPTIONS
      wrong_textflag = 1
      OTHERS         = 2.
  IF sy-subrc = 0.
    IF lv_rc = 0.
      IF line_exists( it_dd07v_tab[ domvalue_l = lv_t000-cccategory ] ).
        DATA(lv_dd07v) = it_dd07v_tab[ domvalue_l = lv_t000-cccategory ].

* logisches System, Mandant und Kategorietext ausgeben
        WRITE: / lv_t000-logsys, lv_dd07v-ddtext.
      ENDIF.
    ENDIF.
  ENDIF.
ENDIF.