Skip to Content
0
Former Member
Dec 19, 2007 at 12:26 PM

Active X bapi commit

113 Views

I have created to short vb.net program to test the goods movement bapi. The code returns a material document and a year but this does not exist in SAP.

Do I need a commit or have I made a different error?

John.

my code:

Imports SAPBAPIControlLib

Imports SAPTableFactoryCtrl

Module Module1

Dim oGoodsmvtHeader As Object

Dim oGoodsmvt As Object

Dim oGoodsmvtCode As Object

Dim oGoodsmvtItem As Object

Dim oGoodsmvtSerialnumber As Object

Dim oTestrun As Object

Dim oGoodsmvtHeadret As Object

Dim oReturn As Object

Dim oBAPICtrl As Object

Dim boMove As Object

Sub Main()

Call axm()

End Sub

Sub axm()

Dim oBAPICtrl As Object

Dim oLogonCtrl As Object

Dim strTID As String

Console.WriteLine("Create Objects")

oBAPICtrl = CreateObject("SAP.BAPI.1")

oLogonCtrl = CreateObject("SAP.Logoncontrol.1")

oBAPICtrl.Connection = oLogonCtrl.NewConnection

Console.WriteLine("open logon screen")

If oBAPICtrl.Connection.Logon() = False Then

MsgBox("R/3 Connection failed")

End

End If

Console.WriteLine("connected")

oGoodsmvt = oBAPICtrl.GetSAPObject("GoodsMovement")

oGoodsmvtHeader = oBAPICtrl.DimAs(oGoodsmvt, "CreateFromData", "GoodsmvtHeader")

oGoodsmvtCode = oBAPICtrl.DimAs(oGoodsmvt, "CreateFromData", "GoodsmvtCode")

oGoodsmvtItem = oBAPICtrl.DimAs(oGoodsmvt, "CreateFromData", "GoodsmvtItem")

oGoodsmvtSerialnumber = oBAPICtrl.DimAs(oGoodsmvt, "CreateFromData", "GoodsmvtSerialnumber")

oReturn = oBAPICtrl.DimAs(oGoodsmvt, "CreateFromData", "Return")

oGoodsmvtHeadret = oBAPICtrl.DimAs(oGoodsmvt, "CreateFromData", "GoodsmvtHeadret")

oReturn = oBAPICtrl.DimAs(oGoodsmvt, "CreateFromData", "Return")

Console.WriteLine("Objects defined")

oGoodsmvtHeader.Value("PSTNG_DATE") = "20071218"

oGoodsmvtHeader.Value("DOC_DATE") = "20071218"

oGoodsmvtHeader.Value("PR_UNAME") = "FNGJ"

oGoodsmvtHeader.Value("HEADER_TXT") = "BAPI test"

oGoodsmvtCode.Value("GM_CODE") = "04"

oGoodsmvtItem.Rows.Add()

oGoodsmvtItem.Value(1, "MATERIAL") = "ZE0512-550"

oGoodsmvtItem.Value(1, "PLANT") = "1111"

oGoodsmvtItem.Value(1, "STGE_LOC") = "0000"

oGoodsmvtItem.Value(1, "MOVE_TYPE") = "301"

oGoodsmvtItem.Value(1, "ENTRY_QNT") = 1

oGoodsmvtItem.Value(1, "QUANTITY") = 1

oGoodsmvtItem.Value(1, "MOVE_PLANT") = "1111"

oGoodsmvtItem.Value(1, "MOVE_STLOC") = "0001"

'oGoodsmvtItem.value(1, "MOVE_REAS") = "Test"

Console.WriteLine("Values Assigned")

oGoodsmvt.CreateFromData(GoodsmvtHeader:=oGoodsmvtHeader, _

GoodsmvtCode:=oGoodsmvtCode, _

goodsmvtItem:=oGoodsmvtItem, _

GoodsmvtSerialnumber:=oGoodsmvtSerialnumber, _

Testrun:="", _

GoodsmvtHeadret:=oGoodsmvtHeadret, _

Return:=oReturn)

Console.WriteLine("Doc id: " + oGoodsmvtHeadret.value("MAT_DOC"))

Console.WriteLine("Doc yr: " + oGoodsmvtHeadret.value("DOC_YEAR"))

'For Each boReturn In oReturn

' Console.WriteLine("Return Type:" + boReturn.value("TYPE"))

' Console.WriteLine(boReturn.value("MESSAGE_V1"))

' Console.WriteLine(boReturn.value("MESSAGE_V2"))

' Console.WriteLine(boReturn.value("MESSAGE_V3"))

' Console.WriteLine(boReturn.value("MESSAGE_V4"))

' Console.WriteLine(boReturn.value("PARAMETER"))

' Console.WriteLine(boReturn.value("FIELD"))

' Console.WriteLine(boReturn.value("ROW"))

'Next

strTID = oBAPICtrl.CreateTransactionID

Console.WriteLine(strTID)

Console.ReadLine()

oBAPICtrl.Connection.Logoff()

End Sub

End Module