Home > Software engineering >  VBA call SAP RFC error
VBA call SAP RFC error

Time:11-19

Sub sapMARC ()
Dim iData As Integer
Dim nField As Integer
Dim nData As Integer
Dim the Result As a Boolean
Dim vRow As the Variant
MsgBox "the Program Start!"
The Set R3=CreateObject (" SAP Functions provides ")
R3. Connection. The System="KP1"
R3. The Connection. The application server=SapApplicationServer
R3. Connection. The Client=SapCient
R3. Connection. SystemNumber=SapSystemNumer
R3. Connection. The User=sapuser
R3. Connection. The Password=sappass
R3. Connection. Language=SapLanguage

If R3. Connection. Logon (0, False) & lt;> True Then
The Exit Sub
End the If
'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
With ThisWorkbook. Sheets (" Program ")
A65536 Lrow=. Range (" "). The End (xlUp). Row
BRR=Application. The Transpose (. Range (A7: "A" & amp; Range (" A65536 "). The End (xlUp). Row))
If IsArray (BRR) Then
For the s=1 To UBound (BRR)
BRR (s)="" "& amp; BRR (s) & amp; "'
"Next s
Optin=Join (BRR, ", ")
The Else
Optin="'" & amp; BRR & amp; "'
"End the If
Cells (10, 11)=optin
End With
'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Set the RFC=R3. The Add (" RFC_READ_TABLE ")
Print '
The Set it_fields=RFC. Tables (" FIELDS ")
The Set it_options=RFC. Tables (" OPTIONS ")
The Set it_data=https://bbs.csdn.net/topics/RFC.Tables (" DATA ")

RFC. Exports (" QUERY_TABLE "). The Value="https://bbs.csdn.net/topics/MARC" 'my table in SAP

Parts With ThisWorkbook. Sheets (" info ")
It_fields. Rows. The Add
It_fields. Value (1, "FIELDNAME")="MATNR"
It_fields. Rows. The Add
It_fields. Value (2, "FIELDNAME")="WERKS
"It_fields. Rows. The Add
It_fields. Value (3, "FIELDNAME")="MMSTA
"It_fields. Rows. The Add
It_fields. Value (4, "FIELDNAME")="EKGRP
"It_fields. Rows. The Add
It_fields. Value (5, "FIELDNAME")="DISMM
"It_fields. Rows. The Add
It_fields. Value (6, "FIELDNAME")="DISPO
"It_fields. Rows. The Add
It_fields. Value (7, "FIELDNAME")="PLIFZ
"It_fields. Rows. The Add
It_fields. Value (8, "FIELDNAME")="DISLS
"It_fields. Rows. The Add
It_fields. Value (9, "FIELDNAME")="BESKZ
"It_fields. Rows. The Add
It_fields. Value (10, "FIELDNAME")="SOBSL
"It_fields. Rows. The Add
It_fields. Value (11, "FIELDNAME")="MINBE
"It_fields. Rows. The Add
It_fields. Value (12, "FIELDNAME")="BSTMI
"It_fields. Rows. The Add
It_fields. Value (13, "FIELDNAME")="BSTRF
"It_fields. Rows. The Add
It_fields. Value (14, "FIELDNAME")="MTVFP
"It_fields. Rows. The Add
It_fields. Value (15, "FIELDNAME")="STRGR
"'it_fields. Rows. The Add
'it_fields. Value (3, "FIELDNAME")="MAKTX
"The Set it_options=RFC. Tables (" OPTIONS ")
It_options. Rows. The Add
It_options. Value (1, "TEXT")="MATNR in (" & amp; Optin & amp;
")"It_options. Rows. The Add
It_options. Value (2, "TEXT")="AND WERKS='8701'"
RFC. Exports (" DELIMITER "). The Value="https://bbs.csdn.net/topics/,"
Result=RFC. Call
. UsedRange. Clear
NFields=it_fields. RowCount
NData=https://bbs.csdn.net/topics/it_data.RowCount
For iField=1 To nFields
Cells (1, iField)=it_fields. Rows (iField). The Value (" FIELDTEXT ")
Next
Columns (a: a) NumberFormatLocal="@"
For To nData iData=https://bbs.csdn.net/topics/1
For j=1 To 15
N=j - 1
VRow=Split (it_data (iData, 1), ", ")
Cells (iData + 1, j)=vRow (n)
Next
Next
. Activate
End With
R3. Connection. LOGOFF
MsgBox "the Program End!"
End Sub

Part of the code excerpt from small lazy _lan blogger code, I put the MATNR (material) Settings for makings [it_options. Value (1, "TEXT")="MATNR in (" & amp; optin & amp;") "], once the problem is now more than 4, the result is returned False, have a great god know the cause of the problem, help to see how to modify the 0.0 #!
  •  Tags:  
  • VBA
  • Related