‎2013 Aug 20 8:19 AM
I'm currently trying to figure out the basics of remote function calls via vb .NET. I feel pretty helpless however, because their just isn't any useful documentation for the most simple of tasks.
What I'm trying to do atm is starting the transaction CO13, write the confirmation number in the appropriate field and cancel the order. I'm still not sure how to access and modify the contents of a specific field. There are some examples with tables for excel in the net, but hat's about it. What I have so far is this (login is working and in another function):
Public Function stornieren() As Boolean
Dim ordernr As String
Dim confirmationnr
Dim confirmation As Object
Dim R3 As Object
Dim CO13 As Object
Dim result
R3 = CreateObject("SAP.Functions")
ordernr = TextBox3.Text
confirmationnr = TextBox4.Text
CO13 = R3.Add("RFC_CALL_TRANSACTION_USING")
CO13.exports("TCODE") = "CO13"
CO13.exports("MODE") = "S"
confirmation = CO13.exports("RUECK")
confirmation.value = confirmationnr
result = CO13.call
End Function
RUECK is the Field Name. I want to write the value of "confirmationnr" into the field RUECK. "confirmation.value = confirmationnr" throws the error message "the object variable could not be determined" and "NullReferenceException" was not handled. Sounds to me like "confirmation = CO13.exports("Rueck") did precisely nothing.
Alternatively I have tried doing it via BAPIs. I don't seem to get past the initialization though,. The code is mostly copied from other public sources as I have little idea of what I am doing at the moment. At the line "boBapiService = oBAPICtrl.GetSAPObject("BapiService")"
I get the error message "There is no connection to a SAP system." If I uncomment the line " If oBAPICtrl.Connection.Logon(frmStart.hWnd, False) = False Then" I get the "the object variable could not be determined" error message from above.
' define object for BAPI ActiveX control
Dim oBAPICtrl As Object
' define object for R/3 logon control
Dim oLogonCtrl As Object
' business object BapiService
Dim boBapiService As Object
' to open the file you need a file channel
Dim intChannel As Integer
Dim frmStart As Object
' create BAPI ActiveX control object
oBAPICtrl = CreateObject("SAP.BAPI.1")
' create R/3 logon control object
oLogonCtrl = CreateObject("SAP.Logoncontrol.1")
' connection object is part of the BAPI ActiveX Control object
oBAPICtrl.Connection = oLogonCtrl.NewConnection
' fill logon parameters for system to use
oBAPICtrl.Connection.System = "Q11"
oBAPICtrl.Connection.Client = "120"
oBAPICtrl.Connection.User = "Correct Username"
oBAPICtrl.Connection.Password = "Correct Password"
oBAPICtrl.Connection.Language = "DE"
oBAPICtrl.Connection.SystemNumber = "00"
' user logon to R/3
' If oBAPICtrl.Connection.Logon(frmStart.hWnd, False) = False Then
'MsgBox("R/3 connection failed")
' create BAPI service object
boBapiService = oBAPICtrl.GetSAPObject("BapiService")
Any help would be greatly appreciated as no one in my company has any knowledge about RFCs and BAPIs and I'm running out of ideas quickly.
‎2013 Aug 20 10:44 AM
Hi Mongan,
Could you please check the RFC connection "BapiService" is working or Not ?
if it's working fine then uncomment the line
" If oBAPICtrl.Connection.Logon(frmStart.hWnd, False) = False
Hope this will solve you problem . Thank you.
Regards,
Balaji P.
‎2013 Aug 20 11:19 AM
Hello Balaji,
I was just editing my post when I saw your answer. I have now managed to get the BAPI program working. I have since tried to complete my original task and execute the CO13 transaction with a specific confirmation number. Sadly I am still clueless about the syntax for BAPIs in vb. The following is what I have. It is pretty much the same idea as my first attempt and also throws the same error.
R3 = CreateObject("SAP.Functions")
ordernr = TextBox3.Text
confirmationnr = TextBox4.Text
CO13 = R3.add("BAPI_PRODORDCONF_CANCEL")
BAPI_Change = R3.add("BAPI_BUPA_CENTRAL_CHANGE")
BAPI_Change.exports("RUECK") = confirmationnr
‎2013 Aug 20 12:38 PM
‎2013 Aug 20 1:23 PM
Thank you, but it seems to be the same kind of examples I have found all over the internet: Getting stuff from SAP into EXCEL. What I need to do is start a transaction, enter a value in the field "confirmation" aka "RUECK" and then execute it. I can't find any RFC/BAPI to write in a specific field of a transaction and then execute it though. I have been told that this is definitely possible, else I would have given up already