[MS Excel] Nutzerliste per RFC-Zugriff (TH_USER_LIST) aus einem SAP-System importieren

Sub GetUserList()
  ' https://www.linkedin.com/pulse/connect-sap-r3-call-custom-fm-from-ms-excel-erkan-kopuz
  ' https://saplsmw.com/Import_tables_directly_into_Access_from_SAP_using_RFCs
  ' http://sapass.metro.client.jp/Sap_Active_X/UseFunctionControl.htm

  ' SAP-Objekt erzeugen
  Set oSAP = CreateObject("SAP.Functions")
  oSAP.Connection.ApplicationServer = "1.1.1.1"     ' IP des Appl-Servers (SM51->Details)
  oSAP.Connection.SystemNumber = "01"               ' Systemnummer, meißt im Namen des Appl-Servers enthalten
  oSAP.Connection.System = "DV1"                    ' Entwicklungs-, Test-, Produktivsystem
  oSAP.Connection.Client = "100"                    ' Mandant
  oSAP.Connection.Language = "DE"                   ' Sprache "EN", "DE" ...
  oSAP.Connection.User = "USER1"                    ' SAP-User
  'oSAP.Connection.Password = "xyz"                  ' SAP-Passwort
  oSAP.Connection.UseSAPLogonIni = False
    
  ' RFC-Login, wobei
  ' Logon(0, False): Logon-Fenster anzeigen
  ' Logon(0, True): Silent logon, Passwort muss gesetzt sein
  If oSAP.Connection.Logon(0, False) = True Then
    Dim oFuBa As Object
        
    ' FuBa TH_USER_LIST abfragen
    Set oFuBa = oSAP.Add("TH_USER_LIST")

    If oFuBa.Call = True Then
        
      ' Schnittstellenparameter "TABLES-USRLIST"
      Dim oUsrList As Object
      Set oUsrList = oFuBa.Tables("USRLIST")
             
      ' Userliste in Excel-Sheet einfügen         
      Dim i As Integer
      i = 1
            
      For Each User In oUsrList.Rows
               
        ActiveWorkbook.Sheets(1).Cells(i, 1) = User(2)  ' Client
        ActiveWorkbook.Sheets(1).Cells(i, 2) = User(3)  ' UserName
        ActiveWorkbook.Sheets(1).Cells(i, 3) = User(5)  ' Terminal
        ActiveWorkbook.Sheets(1).Cells(i, 4) = User(16) ' IP
               
        i = i + 1
      Next
    Else
      ' Exception?
      MsgBox oFuBa.Exception
    End If

    ' Logoff
    oSAP.Connection.Logoff
    
  Else
    ' Kein Login möglich
    MsgBox "Login fehlgeschlagen."
  End If

End Sub

[ABAP] Angemeldete Benutzer eines Application-Servers auflisten

DATA: it_uinfo TYPE TABLE OF uinfo.
DATA: it_usrinfo TYPE TABLE OF usrinfo.

CALL FUNCTION 'TH_USER_LIST'
  TABLES
    list = it_uinfo       " wenn auskommentiert, dann wird usrlist zurückgegeben, sonst nur list
    usrlist = it_usrinfo.

LOOP AT it_uinfo INTO DATA(wa_uinfo).
  WRITE: / wa_uinfo-tid,
          wa_uinfo-mandt,
          wa_uinfo-bname,
          wa_uinfo-tcode,
          wa_uinfo-term,
          wa_uinfo-zeit,
          wa_uinfo-master,
          wa_uinfo-hostadr,
          wa_uinfo-trace,
          wa_uinfo-extmodi,
          wa_uinfo-intmodi,
          wa_uinfo-type,
          wa_uinfo-stat,
          wa_uinfo-protocol,
          wa_uinfo-guiversion,
          wa_uinfo-rfc_type.
ENDLOOP.

LOOP AT it_usrinfo INTO DATA(wa_usrinfo).
  WRITE: / wa_usrinfo-tid,
          wa_usrinfo-mandt,
          wa_usrinfo-bname,
          wa_usrinfo-tcode,
          wa_usrinfo-term,
          wa_usrinfo-zeit,
          wa_usrinfo-master,
          wa_usrinfo-trace,
          wa_usrinfo-extmodi,
          wa_usrinfo-intmodi,
          wa_usrinfo-type,
          wa_usrinfo-stat,
          wa_usrinfo-protocol,
          wa_usrinfo-guiversion,
          wa_usrinfo-rfc_type,
          wa_usrinfo-hostaddr.
ENDLOOP.