当前位置:网站首页>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
边栏推荐
- 常用Markdown语法学习
- 自己封装unity的Debug函数
- 将单行文字自动适应到目标矩形框内
- Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments
- 'NPM' is not an internal or external command, nor is it a runnable program or batch file
- 事件管理之一
- The page displays the current time in real time
- 向量到一个平面的投影向量
- promise all的实现
- Unable to process jar entry [module info. Class]
猜你喜欢

FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning

基于NLP的软件安全研究(二)

Houdini流体>>粒子流体导出到unity笔记

Configure NPM

How does Apache Hudi accelerate traditional batch mode?

Protobuf 使用

Houdini>流体,刚体导出学习过程笔记

Django uses MySQL database to solve error reporting

常用Markdown语法学习

使用flask时代码无报错自动结束,无法保持连接,访问不了url。
随机推荐
Apache Hudi 如何加速传统的批处理模式?
C reads the registry
Nodejs (II) read files synchronously and asynchronously
【NLP笔记】CRF原理初探
Weblux file upload and download
Unityshader Foundation
将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小)
Shapley Explanation Networks
js案例之求最大值,反转数组,冒泡排序
面经总结2
使用flask时代码无报错自动结束,无法保持连接,访问不了url。
Idea shortcut
如何展示您的数字作品集:来自创意招聘人员的建议
C# 多个矩形围成的多边形标注位置的问题
根据某一指定的表名、列名及列值来向前或向后N条查相关列值的SQL自定义标量值函数
对复杂字典Dictionary<T1,T2>排序问题
Robust and Efficient Quadrotor Trajectory Generation for Fast Autonomous Flight
Unable to process jar entry [module info. Class]
The projection vector of a vector to a plane
Dropping Pixels for Adversarial Robustness