[ABAP] Angemeldete User eines Servers auslesen und IP-Adressen ermitteln

* lokale Server ermitteln
DATA: it_server_list_v4 TYPE STANDARD TABLE OF msxxlist WITH DEFAULT KEY.
DATA: it_server_list_v6 TYPE STANDARD TABLE OF msxxlist_v6 WITH DEFAULT KEY.

CALL FUNCTION 'TH_SERVER_LIST'
  TABLES
    list           = it_server_list_v4
    list_ipv6      = it_server_list_v6
  EXCEPTIONS
    no_server_list = 1
    OTHERS         = 2.

IF sy-subrc = 0.

  LOOP AT it_server_list_v6 ASSIGNING FIELD-SYMBOL(<s>).

    WRITE: / |{ <s>-host } ({ <s>-hostaddr_v4_str })|.

    DATA: it_users TYPE STANDARD TABLE OF uinfo WITH DEFAULT KEY.

* Angemeldete User einer SAP-Instanz holen
    CALL FUNCTION 'THUSRINFO' DESTINATION <s>-name
      TABLES
        usr_tabl              = it_users
      EXCEPTIONS
        system_failure        = 1
        communication_failure = 2
        OTHERS                = 3.

    IF sy-subrc = 0.
* Name, Terminal, IP-Adresse ausgeben
      LOOP AT it_users ASSIGNING FIELD-SYMBOL(<u>).

        DATA(lv_ip_user) = ||.

* IP besteht aus 4x HEX-Wert
        IF xstrlen( <u>-hostadr ) = 4.
* jeder Hex-Wert wird in Integer konvertiert
          lv_ip_user = |{ CONV i( <u>-hostadr+0(1) ) }.{ CONV i( <u>-hostadr+1(1) ) }.{ CONV i( <u>-hostadr+2(1) ) }.{ CONV i( <u>-hostadr+3(1) ) }|.
        ENDIF.

        WRITE: / '    ', <u>-bname, <u>-term, lv_ip_user.

      ENDLOOP.
    ENDIF.

  ENDLOOP.
ENDIF.