Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI "document_change2" doesnu00B4t work

Former Member
0 Likes
735

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

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

2 REPLIES 2
Read only

frank_bueltge
Discoverer
0 Likes
552

Hello,

i have the same problem with this BAPI. Give it a chance of answer? Please.

best regards

Frank

Read only

Former Member
0 Likes
552

Hello,

sorry for pushing this topic back to the top of the forum, but I still didn´t found a solution or a good documentation of this BAPI and this topic is really important to me. So again the awnser, if anybody has a tip for me how to use the BAPI "DocumentChange2" in the right way?

Regards,

Robert Barnebeck