当前位置:网站首页>VBA calls SAP RFC to read & write data
VBA calls SAP RFC to read & write data
2022-04-23 07:52:00 【Willie Y】
1、RFC structure
RFC Attribute configuration :

RFC Input parameters :

ZSCE_MAT× Table structure :

RFC Output parameters :

2、VBA Code
Public Const StartRow% = 2 ' Data start line
Public Const EndRow% = 3 ' End of data line
Public Const DataSheetName$ = "Data"
Public SAP As Object
'******************************************************************************
'* Function Desc:VBA call SAP RFC
'* Author:
'* Param:
'* Returns:
'******************************************************************************
Sub InputData()
Dim WrtDataResult As String
Dim IMATNR$, ZYIELD$
If ContectSAP = False Then
MsgBox " Connect SAP Failure "
Exit Sub
End If
If MsgBox(" Connect SAP success ! Add table " & DataSheetName & " Data import in SAP?", vbYesNo, " Warning ") = vbNo Then
Exit Sub
End If
Call OperationPrompts(" Write data to SAP, Please wait a moment ……")
Application.DisplayAlerts = False
Application.ScreenUpdating = False
With ThisWorkbook.Sheets(DataSheetName)
For i = StartRow To EndRow
IMATNR = .Cells(i, 1).Value
ZYIELD = .Cells(i, 2).Value
WrtDataResult = CallRFC(IMATNR, ZYIELD)
.Cells(i, 3).Value = WrtDataResult
Next i
' Sign out
SAP.Connection.LOGOFF
Call OperationPrompts(" Disconnected SAP……")
UF_Prompt.Label1.Caption = "【 End of program running 】"
ThisWorkbook.Save
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
call RFC Core code :
'******************************************************************************
'* Function Desc:VBA call SAP RFC
'* Author:
'* Param:
'* MATNR_No:
'* ZYIELD_value:
'* Returns:
'******************************************************************************
Public Function CallRFC(MATNR_No$, ZYIELD_Value$) As String
Dim LogFlag As Boolean
Dim Result As String
Dim InputTable As Object
Dim Result1 As Object
Dim Result2 As Object
Set RFC = SAP.Add("RFC_Z_SCE_CHANGEMATERIAL")
Set InputTable = RFC.Tables("ZSCE_MAT_GDPW")
'rfc Parameter table assignment
With InputTable
.Rows.Add
.Value(.RowCount, "MATNR") = MATNR_No
'.Value(.ROWCOUNT, "VOLUM") = VOLUM_Value
.Value(.RowCount, "ZYIELD") = ZYIELD_Value
End With
'call RFC
LogFlag = RFC.Call
If LogFlag = True Then
' Set the return parameters
Set Result1 = RFC.Imports("ZMSGNO")
Set Result2 = RFC.Imports("ZMESSG")
CallRFC = MATNR_No & "," & Result1.Value & "," & Result2.Value
Else
CallRFC = "RFC Call failed !"
End If
InputTable.FreeTable
Set InputTable = Nothing
Set Result1 = Nothing
Set Result2 = Nothing
Set RFC = Nothing
End Function
In the code RFC Table structure assignment requires row by row assignment .Exports Parameters are passed to participate in Imports The parameters are similar to .
RFC In call to ,Exports Indicates input RFC Parameters of ,Imports Express RFC Returned call result .
summary :
On a daily basis ,VBA Read SAP surface , Or call RFC It's more convenient , Don't need to SAP Use ABAP Develop and transmit matching production system , Basically, just change the above code .
For more information, please refer to :ExcelVBA And SAPRFC Interface call instance - Douding net
版权声明
本文为[Willie Y]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230628041296.html
边栏推荐
猜你喜欢
![MySQL8. 0 installation / uninstallation tutorial [window10 version]](/img/9c/1acf153b410f0d2eb6a23dcdbabb88.png)
MySQL8. 0 installation / uninstallation tutorial [window10 version]

Install and configure Taobao image NPM (cnpm)

【Unity VFX】VFX特效入门笔记-火花制作

Django uses MySQL database to solve error reporting

Understanding the Role of Individual Units in a Deep Neural Networks(了解各个卷积核在神经网络中的作用)

Apache Hudi 如何加速传统的批处理模式?

向量到一个平面的投影向量

Understanding the role of individual units in a deep neural networks

Scrapy modifies the time in the statistics at the end of the crawler as the current system time

Simple random roll call lottery (written under JS)
随机推荐
Nodejs (four) character reading
Samplecamerafilter
关于unity获取真实地理地图转3D化的相关链接
将单行文字自动适应到目标矩形框内
The problem of exporting excel form with wireframe and internal spacing of form by using web form
【Unity VFX】VFX特效入门笔记-火花制作
Mongodb 启动警告信息处理
js之函数的两种声明方式
事件管理之一
Electronic builder package error: proxyconnect TCP: Dial TCP: 0: connectex
C# 多个矩形围成的多边形标注位置的问题
SQL user-defined scalar value function that looks up relevant column values n times forward or backward according to a specified table name, column name and column value
State synchronization and frame synchronization
设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
Nodejs (VI) sub process operation
Unity获取真实地理地图应用Terrain笔记
关于U盘数据提示RAW,需要格式化,数据恢复笔记
MySQL8. 0 installation / uninstallation tutorial [window10 version]
js之什么是事件?事件三要素以及操作元素
系统与软件安全研究(二)