zoukankan      html  css  js  c++  java
  • 使用Excel调用ABAP系统的函数

    效果:在excel里创建一个按钮,开发一些VB script,可以连接指定的ABAP系统并执行系统里的ABAP function module。

    在这里例子里执行ABAP系统的函数TH_USER_LIST, 把当前系统登录的用户取回来显示在excel里。

    该按钮的点击响应函数实现代码:

    Sub CommandButton1_Click()
        Set R3 = CreateObject("SAP.Functions")
        Set myConnction = R3.Connection
        myConnction.ApplicationServer = "ag3.xxx.sap.corp"
        myConnction.SystemNumber = 54
        myConnction.Client = "001"
        myConnction.user = "WANGJER"
        myConnction.Password = "your password"
        
        If myConnction.Logon(0, True) <> True Then
          MsgBox "Logon failed"
          Exit Sub
        End If
        
        Dim callFunctionModule As Object
            
        Set callFunctionModule = R3.Add("TH_USER_LIST")
        callFunctionModule.Call
    
        If callFunctionModule.Exception <> "" Then
            MsgBox callFunctionModule.Exception
        End If
    
        If callFunctionModule.Call = True Then
            Dim result As Object
            Set result = callFunctionModule.tables("USRLIST")
            Dim aSheet As Worksheet
            Dim sheetCol As New Collection
            sheetCol.Add ActiveWorkbook.Sheets(1)
            For Each aSheet In sheetCol
                Dim i As Integer
                i = 1
                For Each user In result.Rows
                    
                    Client = user(2)
                    UserName = user(3)
                    Terminal = user(5)
                    IP = user(16)
                    aSheet.Cells(i, 1) = Client
                    aSheet.Cells(i, 2) = UserName
                    aSheet.Cells(i, 3) = Terminal
                    aSheet.Cells(i, 4) = IP
                    
                    i = i + 1
                Next
            Next
        Else
            MsgBox " Call Failed! error: "
        End If
    'log off
        myConnction.logoff
    End Sub
    

    要获取更多Jerry的原创技术文章,请关注公众号"汪子熙"或者扫描下面二维码:

  • 相关阅读:
    第10组 Beta冲刺(4/4)
    第10组 Beta冲刺(3/4)
    第10组 Beta冲刺(2/4)
    第10组 Beta冲刺(1/4)
    第10组 Alpha冲刺(4/4)
    租房这件事
    idea中的maven工程,有的项目名称显示粗体,有的显示中括号
    win10电脑版微信数字输入的间隔变大解决办法
    在实体类中添加了@ApiModel不起作用
    为数字字符串加上千分位符号
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/8727530.html
Copyright © 2011-2022 走看看