cancel
Showing results for 
Search instead for 
Did you mean: 

Checkout via BAPI_DOCUMENT_CHECKOUTMODIFY2

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

...........

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

change

If Err.Number = 0

to

If Err.Number <> 0#

Err.Number should not be equal to 0, but uneqal, unfortunatly the letter are not shown in here

Edited by: Iring Maeurer on Sep 16, 2009 2:03 PM

Former Member
0 Kudos

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...

Former Member
0 Kudos

between Err.Number and 0

must be the characters < and >, this means Err.Number is unequal to 0

Former Member
0 Kudos

Ok, so I missunderstood. I thought Err.Number has to be unequal to 0 to avoid the If clause...

I changed it, but now Excel hangs up when executing the BAPI Call. No Response...

Former Member
0 Kudos

try to execute the FM directly in SAP, so you see whether it works at all.

You can also turn in a trace like this

oBAPICtrl.LogFileName = "d:\temp\xx.log"

oBAPICtrl.LogLevel = 5

sometimes you can see an error in the log file (try with differen loglevels)

Former Member
0 Kudos

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.

Former Member
0 Kudos

sorry I am helpless too.

It seems that there is a problem calling the sapftp.exe / saphttp.exe on yout local machine. Maybe try on an other coumputer

Former Member
0 Kudos

OK, problem solved. RFC Calls from my PC were blocked by the Application Server. Now everything works fine. Thanks a lot for you help!

Answers (0)