Skip to Content
0
Former Member
Oct 19, 2005 at 05:08 AM

Error Creating an Order via VB by calling a BAPI

52 Views

Hi Friends,

I am trying to create an Order in SAP in the PM Module. I am using the following code.

Private Sub Form_Load()

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

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

Set oBAPICtrl.Connection = oLogonCtrl.NewConnection

With oBAPICtrl.Connection

.Client = "xxx"

.ApplicationServer = "xxx.xxx.xxx.xxx"

.SystemNumber = "01"

.Language = "en"

.User = "xxxxxx"

.Password = "xxxxxx"

.System = "01"

End With

If oBAPICtrl.Connection.Logon(0, False) = False Then

MsgBox "R/3 connection failed"

End

Else

MsgBox "R/3 Connected"

End If

Set oMaintenanceOrder = oBAPICtrl.GetSAPObject("MaintenanceOrderBAPI")

Set oItMethods = oBAPICtrl.DimAs(oMaintenanceOrder, "OrderMaintain", "ItMethods")

oItMethods.Rows.Add

oItMethods.Value(1, "REFNUMBER") = "1"

oItMethods.Value(1, "OBJECTTYPE") = "HEADER"

oItMethods.Value(1, "METHOD") = "CREATE"

oItMethods.Value(1, "OBJECTKEY") = "%00000000001"

oItMethods.Rows.Add

oItMethods.Value(2, "REFNUMBER") = "1"

oItMethods.Value(2, "OBJECTTYPE") = "OPERATION"

oItMethods.Value(2, "METHOD") = "CREATE"

oItMethods.Value(2, "OBJECTKEY") = "%000000000010010"

oItMethods.Rows.Add

oItMethods.Value(3, "OBJECTTYPE") = "OPERATION"

oItMethods.Value(3, "METHOD") = "DELETE"

oItMethods.Value(3, "OBJECTKEY") = "%000000000010020"

oItMethods.Rows.Add

oItMethods.Value(4, "OBJECTTYPE") = ""

oItMethods.Value(4, "METHOD") = "SAVE"

oItMethods.Value(4, "OBJECTKEY") = "%00000000001"

Set oItHeader = oBAPICtrl.DimAs(oMaintenanceOrder, "OrderMaintain", "ItHeader")

oItHeader.Rows.Add

oItHeader.Value(1, "ORDERID") = "%00000000001"

oItHeader.Value(1, "ORDER_TYPE") = "PM01"

oItHeader.Value(1, "PLANT") = "0001"

oItHeader.Value(1, "PLANPLANT") = "0001"

oItHeader.Value(1, "BUS_AREA") = "0001"

oItHeader.Value(1, "MN_WK_CTR") = "EXEC.BOA"

oItHeader.Value(1, "EQUIPMENT") = "000000000010007253"

oItHeader.Value(1, "SHORT_TEXT") = "Test"

Set oItHeaderUp = oBAPICtrl.DimAs(oMaintenanceOrder, "OrderMaintain", "ItHeaderUp")

oItHeaderUp.Rows.Add

oItHeaderUp.Value(1, "ORDERID") = "%00000000001"

'oItHeaderUp.Value(1, "ORDER_TYPE") = "X"

oItHeaderUp.Value(1, "PLANT") = "X"

oItHeaderUp.Value(1, "BUS_AREA") = "X"

oItHeaderUp.Value(1, "MN_WK_CTR") = "X"

oItHeaderUp.Value(1, "EQUIPMENT") = "X"

oItHeaderUp.Value(1, "SHORT_TEXT") = "X"

Set oItOperation = oBAPICtrl.DimAs(oMaintenanceOrder, "OrderMaintain", "ItOperation")

oItOperation.Rows.Add

oItOperation.Value(1, "ACTIVITY") = "10"

oItOperation.Value(1, "WORK_CNTR") = "EXEC.BOA"

oItOperation.Value(1, "PLANT") = "0001"

oItOperation.Value(1, "CONTROL_KEY") = "PM01"

oItOperation.Value(1, "DESCRIPTION") = "TEST"

oItOperation.Rows.Add

oItOperation.Value(2, "ACTIVITY") = "20"

oItOperation.Value(2, "WORK_CNTR") = "EXEC.BOA"

oItOperation.Value(2, "PLANT") = "0001"

oItOperation.Value(2, "CONTROL_KEY") = "PM01"

oItOperation.Value(2, "DESCRIPTION") = "TEST 1"

Set oItOperationUp = oBAPICtrl.DimAs(oMaintenanceOrder, "OrderMaintain", "ItOperationUp")

oItOperationUp.Rows.Add

oItOperationUp.Value(1, "ACTIVITY") = "X"

oItOperationUp.Value(1, "WORK_CNTR") = "X"

oItOperationUp.Value(1, "PLANT") = "X"

oItOperationUp.Value(1, "CONTROL_KEY") = "X"

oItOperationUp.Value(1, "DESCRIPTION") = "X"

oMaintenanceOrder.OrderMaintain ItMethods:=oItMethods, _

ItHeader:=oItHeader, _

ItHeaderUp:=oItHeaderUp, _

ItOperation:=oItOperation, _

ItOperationUp:=oItOperationUp, _

Return:=oReturn, _

EtNumbers:=oEtNumbers

MsgBox oReturn.Value(1, "MESSAGE")

MsgBox oReturn.Value(1, "NUMBER")

MsgBox oReturn.Value(1, "ROW")

MsgBox oReturn.Value(1, "FIELD")

MsgBox oReturn.Value(1, "SYSTEM")

MsgBox oReturn.Value(1, "LOG_MSG_NO")

End Sub

The code is executing without any errors. But the Order is not getting generated. The value of oReturn.Value(1, "MESSAGE") is

<b> Error reading the standard sequence from the document tables</b>

When i consulted a person he is saying that "this isnt an error but this is purely on functional error because of some customizing sequence or some logic is there for some of the objects to be read hierarchicaly"

I am relly stuck up with this. Could any one of you suggest how to proceed.

Regards,

Kranthi