Skip to Content
0
Former Member
Nov 13, 2006 at 03:37 PM

BAPI "document_change2" doesnu00B4t work

183 Views

Hello,

I´m trying to change the description of a document by using the BAPI "DOCUMENT_CHANGE2" in VBA. Logon to SAP and creating a local instance of the "DRAW" object work. But whem I´m trying to initially set the objects for the import parameter "documentdata" and "documentdatax", these objects get the Value "Error 0". I`m still able to set Values to these Objects (e.g. description). And the BAPI method "change2" is executed without an Error, but the description field hasn´t change. And i think that results of the "Error 0" message. For a better understanding here my VBA-Code:

Public Sub DocumentChange()

dim oBapiCtrl As Object
Dim oLogonCtrl As Object
Dim oDocument As Object
Dim oDocumentData As Object
Dim oDocumentDatax As Object
Dim oReturn As Object

'-----------------------------------------------------------------------------
' Logon SAP
'-----------------------------------------------------------------------------

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

oBapiCtrl.Connection.client = txtClient.Value
oBapiCtrl.Connection.user = txtUser.Value
oBapiCtrl.Connection.Password = txtPassWord.Value
oBapiCtrl.Connection.Language = txtLang.Value
oBapiCtrl.Connection.hostname = txtServer.Value
oBapiCtrl.Connection.systemnumber = txtSysNumber.Value

If Not oBapiCtrl.Connection.Logon(0, True) Then
	MsgBox "Logon error."
End If

'-----------------------------------------------------------------------------
' creating a local instance of the "DRAW" object
'-----------------------------------------------------------------------------

Set oDocument = oBapiCtrl.GetSAPObject("DRAW", strDocType, strDocNumber, strDocVersion, strDocPart)

'-----------------------------------------------------------------------------
' set the objects for the import parameter
'-----------------------------------------------------------------------------

Set oDocumentData = oBapiCtrl.DimAs(oDocument, "Change2", "DOCUMENTDATA")
Set oDocumentDatax = oBapiCtrl.DimAs(oDocument, "Change2", "DOCUMENTDATAX")

'-----------------------------------------------------------------------------
' set values to parameter
'-----------------------------------------------------------------------------

oDocumentData.Value("DOCUMENTNUMBER") = strDocNumber
oDocumentDatax.Value("DOCUMENTNUMBER") = "X"
oDocumentData.Value("DOCUMENTTYPE") = strDocType
oDocumentDatax.Value("DOCUMENTTYPE") = "X"
oDocumentData.Value("DOCUMENTPART") = strDocPart
oDocumentDatax.Value("DOCUMENTPART") = "X"
oDocumentData.Value("DOCUMENTVERSION") = strDocVersion
oDocumentDatax.Value("DOCUMENTVERSION") = "X"
oDocumentData.Value("DESCRIPTION") = strDocDescriptionChange
oDocumentDatax.Value("DESCRIPTION") = "X"

'-----------------------------------------------------------------------------
' execute change2 method
'-----------------------------------------------------------------------------

oDocument.Change2 _
    DOCUMENTDATA:=oDocumentData, _
    DOCUMENTDATAX:=oDocumentDatax, _
    RETURN:=oReturn
	
If oReturn("TYPE") = "" Then
    MsgBox "successful"
ElseIf oReturn("TYPE") = "W" Then
    MsgBox "successful with warning:" & vbCrLf & vbCrLf & oReturn("Message")
Else
    MsgBox "not successful:" & vbCrLf & vbCrLf & oReturn("Message")
End If

End Sub

Has anybody an idea what this error message will tell me? 😊

Thanks

Robert Barnebeck