on 11-24-2009 12:31 AM
We are in the process of developing an Excel file that can be used to update purchase requisitions. I have successfully created the VBA code required to open a connection, call the BAPI, and close the connection. However, I cannot figure out how to pass the table information to the BAPI. Below is a subset of my code:
Sub ChangeReq()
'******************************************
'Call BAPI_PR_CHANGE and change quantity
'******************************************
Set ReqChange = R3.Add("BAPI_PR_CHANGE")
Dim ReqNumber As Object
Dim Item As Object
Dim ItemChanges As Object
Dim Sht1 As Worksheet
Dim Sht2 As Worksheet
Dim Sht3 As Worksheet
Set Sht1 = Sheets("Requisitions")
Set Sht2 = Sheets("PRITEM")
Set Sht3 = Sheets("PRITEMX")
Set ReqNumber = ReqChange.exports("NUMBER")
Set Item = ReqChange.Tables("PRITEM")
Set ItemChanges = ReqChange.Tables("PRITEMX")
ReqNumber = Sht1.Range("A2").Value
Item = Sht2.Range("A2:CN2").Value >>>This is isn't correct
ItemChanges = Sht3.Range("A2:CO2").Value >>>This is isn't correct
Result = ReqChange.CALL
If Result = True Then
MsgBox (ReqNumber)
Else
End If
End Sub
For the life of me, I cannot figure out how to Pass the PRITEM and the PRITEMX data. Any suggestions? My PRITEM data is being stored in a worksheet in cells A2:CN2. PRITEMX is being stored in a separate worksheet in cells A2:CO2.
Michael,
My apologies for being in a hurry today and not posting any comments with the code snippet. The code sample you gave was extremely helpful. The code snippet I posted is the actual code I have created to solve the problem. While the code is not the final version, I will use it to complete the task.
Best regards and thanks again,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Item.Rows.Add
Item.Value(1, "PREQ_ITEM") = Sht1.Range("B2").Value
Item.Value(1, "QUANTITY") = Sht1.Range("E2").Value
Item.Value(1, "UNIT") = Sht1.Range("F2").Value
ItemChanges.Rows.Add
ItemChanges.Value(1, "PREQ_ITEM") = Sht1.Range("B2").Value
ItemChanges.Value(1, "QUANTITY") = "X"
ItemChanges.Value(1, "UNIT") = "X"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Mark,
here you have a couple of lines as an example, it's quite simple, but not obvious
For each row you want to add to PRITEM
Set auxRow = ReqChange.Tables("PRITEM").Rows.Add
auxRow.Value("PREQ_ITEM") = <pos number (*)>
auxRow.Value("CTRL_IND") = <control indicator (*)>
auxRow.Value("PUR_GROUP") = <purchase group (*)>
(and similar for the rest of PRITEM fields you want to set)
(*) Know how to retrieve this data from the mentioned sheets?
Regards
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.