cancel
Showing results for 
Search instead for 
Did you mean: 

Reading stock for material - VB or VBA

0 Kudos

Hi all,

Can anyone help with one simple thing?

I need to read a stock of material with VB or VBA like in LS26 or SQ01-MM_SPAREPARTS.

I reach "login succesfull" and program stops when "BdcTab.Rows.Add"

Can you help please and fix my code?

Below code and table from sheet

Type BDCTYPE
    programName As String
    dynPro As String
    iD As String
    fieldName As String
    fieldValue As String
End Type

Dim BdcTab As Object
Dim Functions As Object
Dim RfcCallTransaction As Object
Dim bdcWork(300) As BDCTYPE

Sub Button1_Click()

Set Functions = CreateObject("SAP.Functions")
Functions.Connection.System = "my system name"

Functions.Connection.client = "010"
Functions.Connection.user = "mylogin"
Functions.Connection.Password = "mypassword"
Functions.Connection.Language = "PL"

If Functions.Connection.Logon(0, False) <> True Then
Exit Sub
End If
MsgBox "Success"

   Set rfcFunc = Functions.Add("RFC_CALL_TRANSACTION_USING")
   Set BdcTab = rfcFunc.tables("BDCTABLE")

   For idx1 = 2 To 9
    bdcWork(idx1).programName = Cells(idx1, 2)
    bdcWork(idx1).dynPro = Cells(idx1, 3)
    bdcWork(idx1).iD = Cells(idx1, 4)
    bdcWork(idx1).fieldName = Cells(idx1, 5)
    bdcWork(idx1).fieldValue = Cells(idx1, 6)
   Call AppendBDC(bdcWork(idx1).programName, bdcWork(idx1).dynPro, bdcWork(idx1).iD, bdcWork(idx1).fieldName, "", "", "RFC")
Next

If rfcFunc.Call = True Then
MsgBox ("It works")
Else
MsgBox " Call Failed! error: "
Functions.Connection.Logoff
End If
End Sub

Sub AppendBDC(pgm, dyn, beg, nam, val, flNum, processOpt)
   BdcTab.Rows.Add
   BdcTab.Value(BdcTab.RowCount, "PROGRAM") = pgm
   BdcTab.Value(BdcTab.RowCount, "DYNPRO") = dyn
   BdcTab.Value(BdcTab.RowCount, "DYNBEGIN") = beg
   BdcTab.Value(BdcTab.RowCount, "FNAM") = nam
   BdcTab.Value(BdcTab.RowCount, "FVAL") = val
End Sub

<br>
anne-petteroe
Community Manager
Community Manager
0 Kudos

Hello Jan,

Welcome to the SAP Community. Thank you for visiting us to get answers to your questions.

Since you're asking a question here for the first time, I'd like to offer some friendly advice on how to get the most out of your community membership and experience.

First, please see https://community.sap.com/resources/questions-and-answers, as this resource page provides tips for preparing questions that draw responses from our members. Second, feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html, as that will help you when submitting questions to the community.

I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.

I hope you find this advice useful, and we're happy to have you as part of SAP Community!

All the best,
Anne

Accepted Solutions (0)

Answers (0)