on 09-14-2009 6:26 AM
Hello,
I'm having some trouble with calling BAPI_DOCUMENT_CHECKOUTMODIFY2 from Excel VBA. When I call the BAPI with the following code, no file is checked out. Anyone knows why?
Dim oBAPICtrl As Object 'BAPI Control
Dim oConnection 'Connection object
Dim Logon 'Logon help variable
'Creating BAPI object
Set oBAPICtrl = CreateObject("SAP.BAPI.1")
'Creating Connection object
Set oConnection = oBAPICtrl.Connection
oConnection.Client = "XXX"
oConnection.User = "XXXXX"
oConnection.Language = "XX"
oConnection.ApplicationServer = "XXXXX"
oConnection.Password = "XXX"
oConnection.SystemNumber = "XX"
oConnection.System = "XXX"
'Performing a remote logon to the R/3 System
If oConnection.Logon(0, True) <> True Then 'Logon without dialog
Set oConnection = Nothing
Logon = False
MsgBox "No access to R/3 System", vbOKOnly, APPID
Else
Logon = True
End If
'If Logon Then
'MsgBox "Logged on successfullyu2026"
'End If
Dim DocObj As Object
Set DocObj = oBAPICtrl.GetSAPObject("J_8A3_DRAW", "PM2", "A5N00030059989", "D", "000")
Dim DocFile As Object
Dim OutFile As Object
Set DocuFile = oBAPICtrl.DimAs(DocObj, "CheckOutModify2", "DocumentFile")
Set OutFile = oBAPICtrl.DimAs(DocObj, "CheckOutModify2", "CheckedOutFile")
DocuFile.Value("FILE_ID") = "4AA80AA8D94F1B99E10080009EE28028"
OutFile.Value("DOCPATH") = "D:\"
'OutFile.Value("DOCFILE") = "Test.doc"
DocObj.CheckOutModify2 DocumentFile:=DocuFile, CheckedOutFile:=OutFile
On Error Resume Next
MsgBox "File: " & DocuFile("DOCFILE")
MsgBox "Out: " & OutFile("DOCFILE")
Set oConnection = Nothing
Set oBAPICtrl = Nothing
Thanks for your answers,
Thomander
Edited by: Thomander on Sep 14, 2009 8:27 AM
Hello Thomander,
I never did a checkout with this BAPI, but I did it with CheckOutView2 and with VB (see the below). The statement "RfcAllowStartProgram ByVal 0&" is needed to allow your program to start an other program, in this case saphttp.exe.
I was wondering about "J_8A3_DRAW", because I just use "Draw". Why do you use the file_id, usually you don't know the file_id, but you know the DIR-key and the ws-appl of the file you want to checkout.
regards Iring
Private Declare Sub RfcAllowStartProgram Lib "librfc32.dll" (value As Any)
Sub get_file2(ByVal dok_no As String, _
ByVal dok_typ As String, _
ByVal dok_td As String, _
ByVal dok_ver As String, _
ByVal ws_appl As String, _
ByVal get_structure As String, _
ByVal check_out_path As String, _
file_name As String, _
filestring As Variant)
Dim oDocument As Object
Dim oDocumentFiles As Object
Dim oService As Object
Dim oReturn As Object
Dim str1 As String
Dim str2 As String
Dim i As Integer
Dim fso As FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
Dim f As TextStream
RfcAllowStartProgram ByVal 0&
'Creating lokal instance of BO "Draw"
Set oDocument = oBAPICtrl.GetSAPObject("Draw", dok_typ, dok_no, dok_ver, dok_td)
If Err.Number <> 0 Then
MsgBox "No local BO 'Draw' created!"
Exit Sub
End If
Set oDocumentFile = oBAPICtrl.DimAs(oDocument, "CheckOutView2", "DocumentFile")
oDocumentFile("WSAPPLICATION") = ws_appl
oDocument.CheckOutView2 OriginalPath:=check_out_path + "\", _
GetStructure:=get_structure, _
DocumentFile:=oDocumentFile, _
DocumentFiles:=oDocumentFiles, _
DocumentStructure:=oDocumentStructure, Return:=oReturn
...........
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
thnaks a lot for your tip!
It seems your Code is not complete at all, because you declare some variables that are never used. Could you give me some more help? Why do you need the scripting object (fso)?
I'm totally confused about calling BAPIs with vba... I managed to get information from BAPI "USER" for example and tried successfully reading tables by RFC_READ_TABLE, but handling with files is something weird for me...
Could you give me an example of the whole procedure?
cu
Thomander
Hello,
make sure that the saphttp.exe and sapftp.exe are in the system32-folder.
Public Declare Sub RfcAllowStartProgram Lib "librfc32.dll" (value As Any)
Sub checkout_file()
Dim oDocument As Object
Dim oDocumentFile As Object
Dim oDocumentFiles As Object
Dim oReturn As Object
Dim oBAPICtrl As Object
'Creating BAPI object
Set oBAPICtrl = CreateObject("SAP.BAPI.1")
Set oConnection = oBAPICtrl.Connection
If oConnection.Logon(0, False) <> True Then
MsgBox "No access to R/3 System"
Exit Sub 'Programm beenden
End If
RfcAllowStartProgram ByVal 0&
'Creating lokal instance of BO "Draw"
Set oDocument = oBAPICtrl.GetSAPObject("Draw", "PD0", "0000000000000000000024287", "02", "000")
If Err.Number <> 0 Then
MsgBox "No local BO 'Draw' created!"
Exit Sub
End If
Set oDocumentFile = oBAPICtrl.DimAs(oDocument, "CheckOutView2", "DocumentFile")
oDocumentFile("WSAPPLICATION") = "PDF"
oDocument.CheckOutView2 OriginalPath:="D:\temp\", _
DocumentFile:=oDocumentFile, _
DOCUMENTFILES:=oDocumentFiles, _
DocumentStructure:=oDocumentStructure, Return:=oReturn
MsgBox oDocumentFiles.RowCount
MsgBox oReturn("MESSAGE")
End Sub
Hello,
sapftp.exe and saphttp.exe are in my system32 folder, I copied them from the SAPGUI dir...
I changed the Code to match my preferences, but I get the error that no local instance of BO 'DRAW' is created... Do I have to include any special dll?
Here's my Code:
Private Declare Sub RfcAllowStartProgram Lib "librfc32.dll" (value As Any)
Sub checkout_file()
Dim oDocument As Object
Dim oDocumentFile As Object
Dim oDocumentFiles As Object
Dim oReturn As Object
Dim oBAPICtrl As Object
'Creating BAPI object
Set oBAPICtrl = CreateObject("SAP.BAPI.1")
Set oConnection = oBAPICtrl.Connection
If oConnection.Logon(0, False) = False Then
MsgBox "No access to R/3 System"
Exit Sub 'Programm beenden
End If
RfcAllowStartProgram ByVal 0&
'Creating lokal instance of BO "Draw"
Set oDocument = oBAPICtrl.GetSAPObject("DRAW", "PM2", "A5N00030059989", "D", "000")
If Err.Number = 0 Then
MsgBox "No local BO 'Draw' created!"
Exit Sub
End If
Set oDocumentFile = oBAPICtrl.DimAs(oDocument, "CheckOutView2", "DocumentFile")
oDocumentFile("WSAPPLICATION") = "DOC"
oDocument.CheckOutView2 OriginalPath:="D:\test\", _
DocumentFile:=oDocumentFile, _
DOCUMENTFILES:=oDocumentFiles, _
DocumentStructure:=oDocumentStructure, Return:=oReturn
MsgBox oDocumentFiles.RowCount
MsgBox oReturn("MESSAGE")
End Sub
Edited by: Thomander on Sep 16, 2009 11:58 AM
I changed it to If Err.Number = 0#, but still get the MsgBox. The problem is, as far as I understand, that no BO is created... But I don't understand this, because it worked in ohter scenarios with different BAPI. The only possibility is, that the Set method is wrong or something.
Can you imagine why the object is not properly created? I'm sure a document exists with these parameters (I can view it in SAPGUI):
Type: PM2
Number: A5N00030059989
Version: D
Part: 000
The order of the parameters is correct, too...
I created a logfile, here is the result:
-
trc file: "d:\test\log.log", trc level: 5, release: "710"
-
Wed Sep 16 15:42:14 2009
SAP.BAPI up and running (version 710 )
loaded from c:\PROGRA~1\sap\frontend\sapgui\wdobapi.ocx
464: >>Invoke ID 1 (Document.PM2A5N00030059989 D 000)
464: >>Invoke: dispid 339 = VerbType M, Verb CHECKOUTVIEW2
464: >>Push structure(DOCUMENTFILE/DOCUMENTFILE)
464: >>Push parameter(ORIGINALPATH/ORIGINALPATH)
464: >>Push empty table(DOCUMENTSTRUCTURE)
464: >>Push empty table(DOCUMENTFILES)
464: >>Push empty table(COMPONENTS)
464: >>BAPI Call()
Then I executed the BAPI in SAPGUI and it worked perfectly. Now I'm helpless what to do.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.