Skip to Content
0
Former Member
Feb 14, 2008 at 10:06 AM

Problem calling BAPI GoodsMovement from VB6.0

30 Views

Hi all,

could anyone give me some advise? The BAPI returns the message cost centre does not exists, but if I look up in our SAP-System the cost centre exists.

-


VB-Code----


Dim oGoodsmvt As Object

'Importparameter BAPI

Dim oGoodsmvt_Header As Object

Dim oGoodsmvt_Code

Dim oTestrun As String

'Exportparameter BAPI

Dim oGoodsmvt_Headret As Object

'Unterparameter von Headret

Dim oMaterialdocument As Object

Dim oMatdocumentyear As Object

‘Tables BAPI

Dim oGoodsmvt_Item As Object

Dim oGoodsmvt_Serialnumber As Object

Dim oGoodsmvt_Return As Object

Dim ReturnMessage as String

Dim MATERIAL As String

Dim PLANT As String

Dim STGE_LOC As String

Dim MOVE_TYPE As String

Dim BATCH As String

Dim ENTRY_QNT As Integer

Dim ENTRY_UOM As String

Dim COSTCENTER As String

Dim GR_RCPT As String

Dim j As Integer

'Fill variables

COSTCENTER = ...

.

.

.

Set oGoodsmvt = SAPBAPIControl1.GetSAPObject("GoodsMovement")

'Importparameter

Set oGoodsmvt_Header = SAPBAPIControl1.DimAs(oGoodsmvt, "CreateFromData", "GoodsmvtHeader")

Set oGoodsmvt_Code = SAPBAPIControl1.DimAs(oGoodsmvt, "CreateFromData", "GoodsmvtCode")

oTestrun = "X"

'Exportparameter

Set oGoodsmvt_Headret = SAPBAPIControl1.DimAs(oGoodsmvt, "CreateFromData", "GoodsmvtHeadret")

'Tables

Set oGoodsmvt_Item = SAPBAPIControl1.DimAs(oGoodsmvt, "CreateFromData", "GoodsmvtItem")

Set oGoodsmvt_Serialnumber = SAPBAPIControl1.DimAs(oGoodsmvt, "CreateFromData", "GoodsmvtSerialnumber")

Set oGoodsmvt_Return = SAPBAPIControl1.DimAs(oGoodsmvt, "CreateFromData", "Return")

oGoodsmvt_Return.Refresh

oGoodsmvt_Header.value("PSTNG_DATE") = Format(Now, "DD.MM.YYYY")

oGoodsmvt_Header.value("DOC_DATE") = Format(Now, "DD.MM.YYYY")

oGoodsmvt_Code.value("gm_code") = "03"

oGoodsmvt_Item.Rows.Add

oGoodsmvt_Item.value(j, "MATERIAL") = MATERIAL

oGoodsmvt_Item.value(j, "PLANT") = PLANT

oGoodsmvt_Item.value(j, "MOVE_TYPE") = MOVE_TYPE

oGoodsmvt_Item.value(j, "MVT_IND") = MVT_IND

oGoodsmvt_Item.value(j, "STGE_LOC") = STGE_LOC

oGoodsmvt_Item.value(j, "ENTRY_QNT") = ENTRY_QNT

oGoodsmvt_Item.value(j, "ENTRY_UOM") = ENTRY_UOM

oGoodsmvt_Item.value(j, "COSTCENTER") = COSTCENTER

oGoodsmvt_Item.value(j, "GR_RCPT") = GR_RCPT

If Err.Number <> 0 Then

MsgBox "Create Data Error"

Exit Function

End If

'*****-- call BAPI --*****

Call oGoodsmvt.CreateFromData(GoodsmvtHeader:=oGoodsmvt_Header, GoodsmvtCode:=oGoodsmvt_Code, Testrun:=oTestrun, _

GoodsmvtItem:=oGoodsmvt_Item, GoodsmvtSerialnumber:=oGoodsmvt_Serialnumber, Return:=oGoodsmvt_Return)

If Not IsEmpty(oGoodsmvt_Return) Then

ReturnMessage = "Typ: " & oGoodsmvt_Return(1, "Type") & vbCrLf

ReturnMessage = ReturnMessage & "ID: " & oGoodsmvt_Return(1, "ID") & vbCrLf

ReturnMessage = ReturnMessage & "No: " & oGoodsmvt_Return(1, "Number") & vbCrLf

ReturnMessage = ReturnMessage & "Message: " & oGoodsmvt_Return(1, "Message") & vbCrLf

ReturnMessage = ReturnMessage & "Log_No: " & oGoodsmvt_Return(1, "LOG_NO") & vbCrLf

ReturnMessage = ReturnMessage & "No: " & oGoodsmvt_Return(1, "LOG_MSG_NO") & vbCrLf

ReturnMessage = ReturnMessage & ": " & oGoodsmvt_Return(1, "PARAMETER") & vbCrLf

ReturnMessage = ReturnMessage & ": " & oGoodsmvt_Return(1, "ROW") & vbCrLf

ReturnMessage = ReturnMessage & ": " & oGoodsmvt_Return(1, "FIELD") & vbCrLf

ReturnMessage = ReturnMessage & ": " & oGoodsmvt_Return(1, "SYSTEM")

MsgBox (ReturnMessage)

End If

-


VB-Code----


Regards Oliver