cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

DMS - BAPI - BAPI_DOCUMENT_CHECKIN2 - No upload to server

Former Member
0 Likes
3,994

Hi,

I am having a problem with BAPI_DOCUMENT_CHECKIN2. I use it to checkin a document into an existing Document info record.

Example of how I am using the BAPI:

REPORT ztestdms .

DATA: it_files  LIKE TABLE OF bapi_doc_files2 WITH HEADER LINE.
DATA: ln_return LIKE bapiret2.

it_files-docfile       = 'C:tempDMS_Test.txt'.
it_files-wsapplication = 'TXT'.
APPEND it_files.

CALL FUNCTION 'BAPI_DOCUMENT_SETCOMMITMODE'
     EXPORTING
          auto_commit = 'X'.

CALL FUNCTION 'BAPI_DOCUMENT_CHECKIN2'
  EXPORTING
    documenttype            = 'TEK'
    documentnumber          = '0000000000000010000000046'
    documentpart            = '000'
    documentversion         = '00'
*   HOSTNAME                = ' '
*   STATUSINTERN            = ' '
*   STATUSEXTERN            = ' '
    statuslog               = 'test mb'
*   REVLEVEL                = ' '
*   AENNR                   = ' '
*   PF_FTP_DEST             = ' '
*   PF_HTTP_DEST            = ' '
  IMPORTING
    return                  = ln_return
  TABLES
    documentfiles           = it_files
*   COMPONENTS              =
*   DOCUMENTSTRUCTURE       =
          .

WRITE ln_return.

The BAPI links the file to the DIR but does not upload it, the lock symbol in transaction CV02N is still open and the file is still available at the client. A manual checkin completes the process but this is not wanted.

What I would like to happen is the file to be uploaded (actually checked in) and removed from the client.

Any help is welcome and thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

Thanks Maurice,

Infact I am using CVAPI_DOC_CHECKIN.

CALL FUNCTION 'CVAPI_DOC_CHECKIN'

EXPORTING

PF_DOKAR = LV_DOKAR

PF_DOKNR = LV_DOC_NUMBER

PF_DOKVR = LV_DOC_VERSION

PF_DOKTL = LV_DOC_PART

PS_API_CONTROL = LIT_API_CONTROL

PF_FTP_DEST = 'SAPFTP'

PF_HTTP_DEST = 'SAPHTTP'

IMPORTING

PSX_MESSAGE = LIT_PSX_MESSAGE_1

TABLES

PT_FILES_X = LIT_PT_FILES.

I am also calling the

ReturnCode = RfcAllowStartProgram("sapftp;saphttp") in my VB code.

Now I have one question, If you see in the function module I am passing 2 parameters "SAPFTP" and "SAPHTTP".

Are we suppossed to do any configuration in SAP for this, I think these 2 are the Default RFC destination maintained in SM59 and When I do a test connection they connect successfully. But what will be the user id and password with which FTP will be accessed.

Answers (9)

Answers (9)

Former Member
0 Likes

Sunil,

I finally found the reason of my problem:

Since the SAPFTP and SAPHTTP RFC starts a program called SAPFTP.exe and SAPHTTP.exe on the client (in this case my desktop), windows has to be able to run these programs. I tested this in the command prompt and windows could not find these programs. So I copied these two files into the Windows home dir and tried again. Now everything is running smoothly!

I also enclosed a working example of the code I am going to use and which will run under the following conditions:

- You are able to start SAPFTP.exe and SPAHTTP.exe from the command prompt.

- You have references in your VBA application to WDTFUNCS.ocx and WDTLOG.ocx


Option Explicit
Function SAPCheckinExample()

Dim R3 As Object
Dim conn As Connection
Dim rfcFunc As SAPFunctionsOCX.Function

Dim PF_DOKAR As Object, PF_DOKNR As Object
Dim PF_DOKTL As Object, PF_DOKVR As Object
Dim PSX_MESSAGE As Object, PT_FILES_X As Object

Dim blnResult As Boolean
Dim strMsg As String, strTtl As String
Dim intStl As Integer, strTyp As String

'**** Change these constants as desired ****************
Const strApplicationServer = "ur_server"
Const strSystemNumber = "xx"
Const strClient = "xxx"
Const strLanguage = "EN"
Const strDocTyp As String = "TEK"
Const strDocNum As String = "0000000000000010000000091"
Const strDocPrt As String = "000"
Const strDocVer As String = "00"
Const strFile As String = "C:temperror.txt"
Const strApplication As String = "TXT"
Const strStorage As String = "DMS_C1_ST"
'*******************************************************

'**** Program extract **********************************
' Create a new connection object
  Set R3 = CreateObject("SAP.Functions")
  Set conn = R3.Connection

' Set the logon parameters
  conn.ApplicationServer = strApplicationServer
  conn.SystemNumber = strSystemNumber
  conn.Client = strClient
  conn.Language = strLanguage
  conn.AutoLogon = True
  
  ' Logon
  If conn.Logon(0, False) <> True Then
      strMsg = "Logon failure!"
      strTtl = "Logon"
      intStl = vbOKOnly & vbExclamation
      MsgBox strMsg, intStl, strTtl
      Exit Function
  End If

  ' Create the checkin rfc in the connection object
  Set rfcFunc = R3.Add("CVAPI_DOC_CHECKIN")
  
  ' Link the parameters from the rfc to the objects
  ' called in this function
  With rfcFunc
      Set PF_DOKAR = .Exports("PF_DOKAR")
      Set PF_DOKNR = .Exports("PF_DOKNR")
      Set PF_DOKTL = .Exports("PF_DOKTL")
      Set PF_DOKVR = .Exports("PF_DOKVR")
      Set PSX_MESSAGE = .Imports("PSX_MESSAGE")
      Set PT_FILES_X = .Tables("PT_FILES_X")
  End With
  
  ' Set the parameters for the rfc
  PF_DOKAR.Value = strDocTyp     ' Document Type
  PF_DOKNR.Value = strDocNum     ' Document number
  PF_DOKTL.Value = strDocPrt     ' Document Part
  PF_DOKVR.Value = strDocVer     ' Document Version
  
  With PT_FILES_X
    .Rows.Add
    .Value(1, "PATHNAME") = strFile
    .Value(1, "DAPPL") = strApplication
    .Value(1, "STORAGE_CAT") = strStorage
  End With

  ' Call the rfc
  blnResult = rfcFunc.Call
  Debug.Print blnResult ' True if the function is
                        ' called succesfully

  'Check if the rfc is executed correctly
  Set PSX_MESSAGE = rfcFunc.Imports("PSX_MESSAGE")
  Debug.Print PSX_MESSAGE("MSG_TYPE"); _
              PSX_MESSAGE("MSG_ID"); _
              PSX_MESSAGE("MSG_NO"); _
              PSX_MESSAGE("MSG_TXT")
  strTyp = PSX_MESSAGE("MSG_TYPE")
  strMsg = PSX_MESSAGE("MSG_TXT")
  Select Case strTyp
    Case "S"
      intStl = vbOKOnly + vbInformation
      strTtl = "Info"
    Case "I"
      intStl = vbOKOnly + vbInformation
      strTtl = "Info"
    Case "E"
      intStl = vbOKOnly + vbExclamation
      strTtl = "Error!"
    Case "W"
      intStl = vbOKOnly + vbExclamation
      strTtl = "Error!"
    Case "A"
      intStl = vbOKOnly + vbCritical
      strTtl = "Critical error!"
  End Select

  conn.Logoff

  If strMsg = "" Then
    strMsg = "File checked in!"
    strTtl = "Info"
    intStl = vbOKOnly + vbInformation
    MsgBox strMsg, intStl, strTtl
  Else
    MsgBox strMsg, intStl, strTtl
  End If
  
End Function

Former Member
0 Likes

Hello Maurice,

i have the same problem as you and would like to try your vb code.

If i try this i get a lot of syntax errors.

Wich workbench do you use or is it necessary to load adl. libraries.

Reinhold.

Former Member
0 Likes

Hi Maurice,

I got my BAPI working and now I am able to attach and archive a document from my VB code. I did everything correct only issue was the call to LIBRFC32 DLL to get the hold of program RfcAllowStartProgram.

The VB code to call this function before the CHECKIN bapi is

Private Const RAccess As String = " "

Private Declare Function RfcAllowStartProgram Lib "librfc32" (ByVal RAccess As String) As Integer

ReturnCode = RfcAllowStartProgram("sapftp;saphttp")

Now call the CHECK IN BAPI from Vb code, In ABAP the CHECKIN BAPI is something liek this

CALL FUNCTION 'CVAPI_DOC_CHECKIN'

EXPORTING

PF_DOKAR = LV_DOKAR

PF_DOKNR = LV_DOC_NUMBER

PF_DOKVR = LV_DOC_VERSION

PF_DOKTL = LV_DOC_PART

PS_API_CONTROL = LIT_API_CONTROL

IMPORTING

PSX_MESSAGE = LIT_PSX_MESSAGE_1

TABLES

PT_FILES_X = LIT_PT_FILES.

Hope this resolves your issue too.

Former Member
0 Likes

Sorry the error Code I am getting now is

"RFC Partner does not allow to start the Required P", I assume the "P" is an incomplete word and it is actally "Program".

I don't know which Program it is looking for when this Vb Code is invoking CVAPI_DOC_CHECKIN function module.

Former Member
0 Likes

Hi Maurice,

I don't know, something strange is happenning. As I mentioned I have this VB Code in Place to checkin a Document to one of our IXOS Server.

CALL FUNCTION 'CVAPI_DOC_CHECKIN'

EXPORTING

PF_DOKAR = LV_DOKAR

PF_DOKNR = LV_DOC_NUMBER

PF_DOKVR = LV_DOC_VERSION

PF_DOKTL = LV_DOC_PART

PS_API_CONTROL = LIT_API_CONTROL

PF_FTP_DEST = 'SAPFTPA'

PF_HTTP_DEST = 'SAPHTTPA'

IMPORTING

PSX_MESSAGE = LIT_PSX_MESSAGE_1

TABLES

PT_FILES_X = LIT_PT_FILES.

I also have the

ReturnCode = RfcAllowStartProgram("sapftpa;saphttpa") in VB Code to allow RFC to start any program.

When I debug my VB Code, i.e Debug my 'CVAPI_DOC_CHECKIN' from my VB Code (This can be achived by putting RFC_DEBUG = 1 in the Environment Variable) This Function module does checkin the document correctly and it works fine without any error.

But when I put the Debug option off, I get this error message "RFC partner does not allow to start any program".

I don't know whats happenning. In both cases the User ID used to access SAP is same i.e my ID.

Please let me know if anyone can answer this.

Former Member
0 Likes

It appears that it has nothing to do with the filelength. I tried to check in a file using the RFC SAPFTPA and a test file on the application server. It was successfully check in!

So it appears that the file you want to check in, has to be on a location that the application server can reach.

Sunil could you also test this on your system and inform me if this is working for you as well.

If you (or someone else) are able to find a solution for loading a file from the client I also would like to know that.

Former Member
0 Likes

Sunil,

I added these FTP and HTTP parameters to the program and checked via transaction SM59 if these RFC exists. They donot exist but there are these two: SAPFTPA and SAPHTTPA. I turned on the trace for these RFC's. The FTP RFC shows in the trace something like this:

(..............46

C ......FTP_CLIE

NT_TO_R3........

..........ERROR.

.....LENGTH.....

.FNAME......C:\C

AD\DEV_RFC.TXT

As you can see it looks like there is some problem with the filelength...(?)

I hope this help you a little bit further if it does please let me know i am still investigating this problem.

[edit]

Program RSFTP005 creates the SAPFTP and SAPFTPA RFC's. Where SAPFTP runs on the client and SAPFTPA on the application server.

[/edit]

Message was edited by: Maurice Brouwers

Former Member
0 Likes

Hi,

I have developed a BAPI which uses BAPI_DOCUMENT_CREATE2 to create a BAPI and BAPI_DOCUMENT_CHECKIN2 to check in the same document.

These 2 BAPIS works fine and they do Checkin the concerned document when called from SE37. But When I call these BAPIs from a VB Program, it does not checks in the document. Kindly suggest what could be the issue.

Former Member
0 Likes

Sunil,

I am having the same problem and have already created an OSS note for SAP in which they reply:

<i>However, as you use Visual Basic, your query represents

a consulting issue rather than a problem based on a

software error in R/3 (as you said, the BAPI works in TA

se37). Therefore, I would ask you to contact our Remote

Consulting and to open a new call under component XX-RC.

Our consultants will assist you.

Nevertheless, you could also try to use CVAPI_DOC_CHECKIN

instead of BAPI_DOCUMENT_CHECKIN2, API-s are much more

flexible than BAPI-s.

Thank you for your understanding.!

</i>

I have just finished testing this other function but it has the same result. Below you will find an example program with this other function.


Function SAPCheckinExample()

Dim R3 As Object
Dim conn As Connection
Dim rfcFunc As SAPFunctionsOCX.Function

Dim PF_DOKAR As Object, PF_DOKNR As Object, PF_DOKTL As Object
Dim PF_DOKVR As Object, PSX_MESSAGE As Object, PT_FILES_X As Object
Dim PS_DOC_STATUS As Object

Dim blnResult As Boolean
Dim strMsg As String, strTtl As String, intStl As Integer, strTyp As String

'**** Change these constants as desired *************************************
Const strApplicationServer = "ur_server"
Const strSystemNumber = "XX"
Const strClient = "XXX"
Const strLanguage = "EN"
Const strDocTyp As String = "TEK"
Const strDocNum As String = "0000000000000010000000045"
Const strDocPrt As String = "000"
Const strDocVer As String = "06"
Const strFile As String = "C:CADDEV_RFC.TXT"
Const strApplication As String = "TXT"
Const strStorage As String = "DMS_C1_ST"
'****************************************************************************

'**** Program extract *******************************************************
' Create a new connection object
Set R3 = CreateObject("SAP.Functions")
Set conn = R3.Connection

' Set the logon parameters
'R3.LogFileName = "C:WINDOWSDESKTOPSAPLOG.TXT"
  conn.ApplicationServer = strApplicationServer
  conn.SystemNumber = strSystemNumber
  conn.Client = strClient
  conn.Language = strLanguage
  conn.AutoLogon = True
  
  ' Logon
  If conn.Logon(0, False) <> True Then
      strMsg = "Logon failure!"
      strTtl = "Logon"
      intStl = vbOKOnly & vbExclamation
      MsgBox strMsg, intStl, strTtl
      Exit Function
  End If
  
  ' Create the checkin rfc in the connection object
  Set rfcFunc = R3.Add("CVAPI_DOC_CHECKIN")
  
  ' Link the parameters from the rfc to the objects called in this function
  With rfcFunc
      Set PF_DOKAR = .Exports("PF_DOKAR")
      Set PF_DOKNR = .Exports("PF_DOKNR")
      Set PF_DOKTL = .Exports("PF_DOKTL")
      Set PF_DOKVR = .Exports("PF_DOKVR")
      Set PS_DOC_STATUS = .Exports("PS_DOC_STATUS")
      Set PSX_MESSAGE = .Imports("PSX_MESSAGE")
      Set PT_FILES_X = .Tables("PT_FILES_X")
  End With
  
  ' Set the parameters for the rfc
  PF_DOKAR.Value = strDocTyp     ' Document Type
  PF_DOKNR.Value = strDocNum     ' Document number
  PF_DOKTL.Value = strDocPrt     ' Document Part
  PF_DOKVR.Value = strDocVer     ' Document Version
  
  With PT_FILES_X
    .Rows.Add
    .Value(1, "PATHNAME") = strFile
    .Value(1, "DAPPL") = strApplication
    .Value(1, "STORAGE_CAT") = strStorage
  End With
  
  ' Call the rfc
  blnResult = rfcFunc.Call
  Debug.Print blnResult ' True if the function is called succesfully

  'Check if the rfc is executed correctly
  Set PSX_MESSAGE = rfcFunc.Imports("PSX_MESSAGE")
  Debug.Print PSX_MESSAGE("MSG_TYPE"); PSX_MESSAGE("MSG_ID"); PSX_MESSAGE("MSG_NO"); PSX_MESSAGE("MSG_TXT")
  strTyp = PSX_MESSAGE("MSG_TYPE")
  strMsg = PSX_MESSAGE("MSG_TXT")
  Select Case strTyp
    Case "S"
      intStl = vbOKOnly + vbInformation
      strTtl = "Info"
    Case "I"
      intStl = vbOKOnly + vbInformation
      strTtl = "Info"
    Case "E"
      intStl = vbOKOnly + vbExclamation
      strTtl = "Error!"
    Case "W"
      intStl = vbOKOnly + vbExclamation
      strTtl = "Error!"
    Case "A"
      intStl = vbOKOnly + vbCritical
      strTtl = "Critical error!"
  End Select

  conn.Logoff

  If strMsg = "" Then
    strMsg = "File checked in!"
    strTtl = "Info"
    intStl = vbOKOnly + vbInformation
    MsgBox strMsg, intStl, strTtl
  Else
    MsgBox strMsg, intStl, strTtl
  End If
  
End Function

Message was edited by: Maurice Brouwers

Former Member
0 Likes

The solution:

REPORT ztestdms .

DATA: it_files  LIKE TABLE OF bapi_doc_files2 WITH HEADER LINE.
DATA: ln_return LIKE bapiret2.

MOVE 'C:tempDMS_Test.txt' TO it_files-docfile.
MOVE 'TXT' TO it_files-wsapplication.
<b>MOVE 'DMS_C1_ST' TO it_files-storagecategory.</b>
APPEND it_files.

CALL FUNCTION 'BAPI_DOCUMENT_SETCOMMITMODE'
     EXPORTING
          auto_commit = 'X'.

CALL FUNCTION 'BAPI_DOCUMENT_CHECKIN2'
  EXPORTING
    documenttype            = 'TEK'
    documentnumber          = '0000000000000010000000047'
    documentpart            = '000'
    documentversion         = '00'
*   HOSTNAME                = ' '
*   STATUSINTERN            = ' '
*   STATUSEXTERN            = ' '
    statuslog               = 'test mb'
*   REVLEVEL                = ' '
*   AENNR                   = ' '
*   PF_FTP_DEST             = ' '
*   PF_HTTP_DEST            = ' '
  IMPORTING
    return                  = ln_return
  TABLES
    documentfiles           = it_files
*   COMPONENTS              =
*   DOCUMENTSTRUCTURE       =
          .

WRITE ln_return.

Added line

MOVE 'DMS_C1_ST' TO it_files-storagecategory.

Which is a value maintained in customizing.

Former Member
0 Likes

Hello,

I don't know the FM BAPI_DOCUMENT_SETCOMMITMODE and can't find it in our 4.7 system.

Are you sure you don' need to call BAPI_TRANSACTION_COMMIT (or COMMIT WORK) after your call to BAPI_DOCUMENT_CHECKIN2? Because the sample in the documentation explicitly calls COMMIT WORK.

Regards, Joerg

Former Member
0 Likes

Joerg thanks for your reply.

This BAPI_DOCUMENT_SETCOMMITMODE is described in note 806605 and is used to have the DMS BAPI's use an auto commit instead of an explicit commit as in the example code. Also using an explicit commit (as in the example code) does not solve my problem.

Regards,

Maurice