cancel
Showing results for 
Search instead for 
Did you mean: 

How to run FM CVAPI_DOC_CHECKIN in rfc mode without gui

DanielleinaD
Advisor
Advisor
0 Kudos

Hi experts,

I try to use CVAPI_DOC_CHECKIN to upload documents into my DMS. The problem is that frontend asks for the permission to load the file from my local pc. When I'm running the function module inside a SOAP or REST service the documents won't get checked in. I found a tutorial in the support area but this doesn't work. Is there any option that I could prevent the GUI popup I think it must work somehow. (This function module is also RFC ready by default).

Here you can see the example programs provided by SAP. From the application server and/or in the background.

I can't find any hint there which could prevent the GUI popup for CVAPI_DOC_CHECKIN.

I found out that I haven't configured any SAPFTP destination could this cause any problems? (I'm storing the documents into the Kpro)

***********************************************************************
* Checkin the first original of a document info record                *
* from the application server and/or in the background                *
***********************************************************************

REPORT ZZUZTEST_TEST_CHECKIN .

data: lf_line(255).

data: ls_draw like DRAW,
      ls_message_cvapi like messages,
      lt_files_cvapi type standard table of CVAPI_DOC_FILE,
      lt_files_cvapi_header like CVAPI_DOC_FILE.
data: lt_originals LIKE cvapi_doc_file OCCURS 0 WITH HEADER LINE,
      vo_originals LIKE cvapi_doc_file OCCURS 0 WITH HEADER LINE.


*************** Start-of-selection *****************

start-of-selection.

ls_draw-dokar = 'DRW'.
ls_Draw-doknr = 'UZTEST30'.
ls_Draw-dokvr = '02'.
ls_Draw-doktl = '000'.

* Read Originals contained in the document info record
CALL FUNCTION 'CVAPI_DOC_GETDETAIL'
    EXPORTING
        pf_batchmode    = 'X'
        pf_hostname      = ' '
        pf_dokar        = ls_draw-dokar
        pf_doknr        = ls_draw-doknr
        pf_dokvr        = ls_draw-dokvr
        pf_doktl        = ls_draw-doktl
        pf_active_files = 'X'
      IMPORTING
          psx_draw        = ls_draw
  TABLES
        pt_files        = vo_originals
  EXCEPTIONS
        not_found      = 1
        no_auth        = 2
        error          = 3
        OTHERS          = 4
        .
IF sy-subrc <> 0.
  WRITE 'Error returned by CVAPI_DOC_GETDETAIL'. "#EC NOTEXT
  EXIT.
ENDIF.

* Check if we can really access the file from the application server
read table vo_originals index 1.
open dataset vo_originals-filename for input in text mode.

if not sy-subrc is initial.
  message e500(26) with vo_originals-filename 'not found'.
endif.

read dataset vo_originals-filename into lf_line.

if not sy-subrc is initial.
  message e500(26) with vo_originals-filename 'read error'.
endif.

lt_originals = vo_originals.
lt_originals-STORAGE_CAT = 'DMS_C1_ST'.
append lt_originals.

  CALL FUNCTION 'CVAPI_DOC_CHECKIN'
    EXPORTING
      PF_DOKAR                = ls_draw-dokar
      PF_DOKNR                = ls_draw-doknr
      PF_DOKVR                = ls_draw-dokvr
      PF_DOKTL                = ls_draw-doktl
*    PS_DOC_STATUS            =
    PF_FTP_DEST              = 'SAPFTPA'
    PF_HTTP_DEST             = 'SAPHTTPA'
*    PF_HOSTNAME              = ' '
*     PS_API_CONTROL          =
*    PF_REPLACE              = ' '
*      PF_CONTENT_PROVIDE      = 'SRV'
    IMPORTING
      PSX_MESSAGE              = ls_message_cvapi
    TABLES
      PT_FILES_X              = lt_originals
*    PT_COMP_X                =
*    PT_CONTENT              =
            .

IF ls_message_cvapi-msg_type CA 'EA'.
    ROLLBACK WORK.
    MESSAGE ID '26' TYPE 'I' NUMBER '000'
    WITH ls_message_cvapi-msg_txt.
  ELSE.
    COMMIT WORK and wait.
  ENDIF.






Sandra_Rossi
Active Contributor

Which one of the two function modules do a GUI access?

That's weird, because the two calls seem all right (for the first one, PF_BATCHMODE = 'X', and for the second one, PF_FTP_DEST = 'SAPFTPA' and PF_HTTP_DEST = 'SAPHTTPA', are for accessing files on the application server.)

SAPFTPA and SAPHTTPA are created automatically and can be checked with programs RSFTP005 and RSHTTP05.

DanielleinaD
Advisor
Advisor
0 Kudos

Hi Sandra, I think there must be something wrong with

* Check if we can really access the file from the application server
read table vo_originals index 1.
open dataset vo_originals-filename for input in text mode.

You were right, the function module runs in the background with the provided parameters(I was running it with se37 and there the GUI also pops up with the parameters SAPHTTPA and SAPFTPA).

Do you have any idea which could cause the error with the open dataset?

Somehow this should work I mean it is no problem to check in the document with the GUI popup.

DanielleinaD
Advisor
Advisor
0 Kudos

I tried several options also open dataset in binary mode etc. but it seems that the system can't find the file on the application server. Maybe I open another post, therefore.

Sandra_Rossi
Active Contributor

if open dataset doesn't find the file, and you made sure that it exists, that's either because of unix or SAP authorization (check SU53 or add the MESSAGE word to get more info), or you have several application servers (check that with SM51) and the path is only available from one server.

DanielleinaD
Advisor
Advisor
0 Kudos

okay I found out, that I only have one application server running. I'm receiving the message "No such file or directroy". I don't understand why this work with the front end but not with open dataset.

Sandra_Rossi
Active Contributor

Open dataset is not to open a file on the frontend, it's to open a file on the application server.

Well, in fact, I don't understand anymore what you are trying to do. Open dataset and SAPFTPA/SAPHTTPA are for uploading a file stored on the application server and it works well in background, but you are also talking about loading from the GUI which is to be done via SAPFTP/SAPHTTP.

If you want to use a WS, then you have to store the file temporarily on the application server (open dataset in output mode) and then use SAPFTPA/SAPHTTPA.

DanielleinaD
Advisor
Advisor
0 Kudos

Okay, now everything makes sense.

So I should first upload the file with FM Gui upload or Archivefile_client_to_server into the application server and afterward, I can check it into the kpro?

I was confused because of the GUI popup it seemed that the file is directly loaded from my local machine to the Kpro.

Sandra_Rossi
Active Contributor

"...sense" for you, but not for me. I am totally confused. If you use a WS, then why do you use GUI_UPLOAD ? (the file should be transmitted as bytes inside the WS, and the server will do the checkin) If you don't use a WS, then you don't need to write the file to the application server, simply checkin directly the frontend file with SAPFTP/SAPHTTP (not SAPFTPA/SAPHTTPA), and then yes you possibly have a SAPGUI security popup to confirm the upload (refer to Colleen Hebbert answer).

DanielleinaD
Advisor
Advisor
0 Kudos

Okay sorry for confusing you 🙂

1. I want to use a WS but first I will make sure that I can run cvapi_doc_checkin inside SAP without the GUI pop up (see screenshot)

2. I was thinking that it would be enough to provide only the file-path(from my local machine) to the cvapi_doc_checkin module so that the file will be transferred automatically. For example, if I use the function module without the SAPHTTPA/SAPFTPA parameters and only provide the file-path "c:\Users\..." to the parameter filename the GUI pops up and ask for permission to access my local machine. If I allow this request the file gets transferred and is check-in without any further action.

But I would like to run this with the SAPHTTPA/SAPFTPA parameters (to use this in my WS) and if I understood you correctly, in this case, the function module doesn't look for the file on my local machine rather than on the application server. But there is no file because I haven't uploaded it on the application server yet.

So I understood that before I can use the CVAPI_checkin with the SAPHTTPA/SAPFTPA parameters I need to upload the file to the application server. Because I want to run the whole process in my WS I need another function module which I can provide a file-path on my local machine and which uploads the file to the application server.

Therefore I was thinking about the FM's "GUI_UPLOAD" or "Archivefile_client_to_server" but now I see that both modules are not RFC ready per default which means it could be a problem to use them in a WS. And now I will try "open dataset in output mode" which you recommended loading the file from my local machine to the application server.

Sandra_Rossi
Active Contributor

Okay now I'm in line with you. For your test, of course you may use GUI_UPLOAD, but you won't be able to use it with RFC or WS, so it's not worth coding it (instead, use any existing file for the time of your test, or if you want to upload a file (I don't see any good reason for that) use any FTP client or winscp or Unix command line or even transaction code CG3Z if you have a SAP ECC system, or okay you may even do a separate custom program to upload your file).

Accepted Solutions (0)

Answers (1)

Answers (1)

Colleen
Advisor
Advisor

are you able to look at the GUI security settings and try to enter a custom rule for your file path to allow it? Fix the SAPGUI settings as opposed to handling programmatically?