cancel
Showing results for 
Search instead for 
Did you mean: 

[ASK] successful create document in DMS using BAPI_DOCUMENT_CREATE2 but error Error while checking out:

0 Kudos

Dear Expert,


I am really need your advise. I try to create document and upload file TXT to SAP easy DMS.

I am success create this document but when i access it through CV03N there is a message


"Error while checking out: DMO000000000000001000000002100000 Message no. 26254 "


This is my code..


DATA: ls_doc LIKE bapi_doc_draw2 OCCURS 0 WITH HEADER LINE ,

         lt_files LIKE bapi_doc_files2 OCCURS 0 WITH HEADER LINE ,

         itabobjectlinks LIKE bapi_doc_drad OCCURS 0 WITH HEADER LINE,

         li_files TYPE TABLE OF bapi_doc_files2,

         ls_files TYPE bapi_doc_files2,

         ls_return TYPE bapiret2,

         lf_doctype LIKE  bapi_doc_aux-doctype,

         lf_docnumber LIKE  bapi_doc_aux-docnumber,

         lf_docpart LIKE  bapi_doc_aux-docpart,

         lf_docversion LIKE  bapi_doc_aux-docversion.

   DATA: BEGIN OF errmsg OCCURS 10.

           INCLUDE STRUCTURE bapiret2.

   DATA: END OF errmsg.

   CONSTANTS : lc_pdf TYPE bapi_doc_files2-wsapplication

               VALUE 'TXT',

               lc_path TYPE bapi_doc_files2-docpath

               VALUE 'D:\',

               lc_x   TYPE c VALUE 'X'.

   ls_doc-documenttype 'DMO'.

   "ls_doc-documentnumber = '0000000000000010000000013'.

   ls_doc-documentversion = '00'.

   ls_doc-documentpart  = '000'.

   ls_doc-description = 'Document Sample TXT'.

   ls_doc-docfile1 = 'D:\sample.txt'.

   ls_doc-savedocfile1 = 'D:\sample.txt'.

   ls_doc-wsapplication1 = 'TXT'.

   ls_doc-datacarrier1 = 'SAP-SYSTEM'.

   ls_doc-SAVEDATACARRIER1 = 'SAP-SYSTEM'.

   APPEND ls_doc.

   lt_files-documenttype = 'DMO'.

   lt_files-storagecategory = 'DMS_C1_ST'.

   lt_files-docfile 'D:\sample.txt'.

   lt_files-wsapplication = 'TXT'.

   lt_files-description = 'Document Sample TXT'.

   lt_files-sourcedatacarrier = 'SAP-SYSTEM'.

   APPEND lt_files.

*  CLEAR itabobjectlinks.

*  REFRESH itabobjectlinks.

*  itabobjectlinks-objecttype = 'VBAP'.

*  itabobjectlinks-objectkey = '2142342'.

*  APPEND itabobjectlinks.

   CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'

     EXPORTING

       documentdata         = ls_doc

*     HOSTNAME             =

*     docbomchangenumber   =

*     DOCBOMVALIDFROM      =

*     DOCBOMREVISIONLEVEL  =

*     CAD_MODE             = ' '

*     PF_FTP_DEST          = ' '

*     PF_HTTP_DEST         = ' '

*     DEFAULTCLASS         = 'X'

     IMPORTING

       documenttype         = lf_doctype

       documentnumber       = lf_docnumber

       documentpart         = lf_docpart

       documentversion      = lf_docversion

       return               = errmsg

     TABLES

*     CHARACTERISTICVALUES =

*     CLASSALLOCATIONS     =

*     DOCUMENTDESCRIPTIONS =

       objectlinks          = itabobjectlinks

*     DOCUMENTSTRUCTURE    =

       documentfiles        = lt_files

*     LONGTEXTS            =

*     COMPONENTS           =

     .

   IF sy-subrc NE 0.

     CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

   ELSE.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

       EXPORTING

         wait = 'X'.

   ENDIF.

   "ls_files-storagecategory  = 'SAP-SYSTEM'.

   ls_files-docpath          = lc_path.

   ls_files-docfile          = 'sample.txt' .

   ls_files-wsapplication    = lc_pdf.

   ls_files-checkedin        = lc_x.

   APPEND ls_files TO li_files.

   CLEAR : ls_files.

*

* BAPI to check in all converted PDFs

   CALL FUNCTION 'BAPI_DOCUMENT_CHECKIN2'

     EXPORTING:

       documenttype    = lf_doctype

       documentnumber  = lf_docnumber

       documentpart    = lf_docpart

       documentversion = lf_docversion

     IMPORTING

      return     = ls_return

     TABLES

       documentfiles = li_files.

   IF ls_return-type CA 'EA'.

     CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

   ELSE.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

       EXPORTING

         wait = 'X'.

   ENDIF.


Please help...


Best Regards...

Accepted Solutions (1)

Accepted Solutions (1)

christoph_hopf
Advisor
Advisor
0 Kudos

Dear Anastasius,

I checked your coding and it seems that you try to checkin the original data to storage SAP-SYSTEM. But you hand over the data to table DOCUMENTFILES which is used for originals that should go to the content server.

So if you want to use SAP-SYSTEM you have to put the file data to table DOCUMENTDATA and made sure that the flag "use KPRO" is not set for document type DMO in transaction DC10.

Personally I would recommend you to use the Content server for storing files but than you can use the default storage category 'DMS_C1_ST'. For further information please see the SAP note 766277 where you will find a complete BAPI documentation as attachment.

Best regards,
Christoph

0 Kudos

Dear Christoph,

Thanks a lot for your information and guidance.. solved and this is my code.

FORM create_new.

   DATA: ls_doc LIKE bapi_doc_draw2,

         ls_return LIKE bapiret2.

** key fields for BAPI return

   DATA: lf_doctype LIKE bapi_doc_draw2-documenttype,

   lf_docnumber LIKE bapi_doc_draw2-documentnumber,

   lf_docpart LIKE bapi_doc_draw2-documentpart,

   lf_docversion LIKE bapi_doc_draw2-documentversion.

** table to check in the originals

   DATA: lt_files LIKE bapi_doc_files2 OCCURS 0 WITH HEADER LINE,

** short text

   lt_drat LIKE bapi_doc_drat OCCURS 0 WITH HEADER LINE,

** object links

   lt_drad LIKE bapi_doc_drad OCCURS 0 WITH HEADER LINE.

*********************************************************************

** allocate document data *which will be assigned to the new document

*********************************************************************

   ls_doc-documenttype = 'DMO'.

   ls_doc-documentnumber = 'SAMPLE_PDF'.

   ls_doc-documentversion = '00'.

   ls_doc-documentpart = '000'.

   ls_doc-description = 'Sample document PDF'.

   ls_doc-docfile1 = 'D:\sample.pdf'.

   ls_doc-wsapplication1 = 'PDF'.

   "ls_doc-statusextern = 'AA'.

   "ls_doc-laboratory = '001'.

**********************************************************

** hand over originals

***********************************************************

   REFRESH lt_files.

   CLEAR lt_files.

   lt_files-storagecategory = 'DMS_C1_ST'.

   lt_files-docfile = 'D:\sample.pdf'.

   lt_files-wsapplication = 'PDF'.

*if the original should be checked in the old storage place,

* the assignment

   "lt_files-originaltype = '1'.   " or '2' have to be done

   APPEND lt_files.

*********************************************************

** allocate short texts

**********************************************************

   CLEAR lt_drat.

   REFRESH lt_drat.

   lt_drat-language = 'EN'.

   lt_drat-description = 'Sample PDF'.

   APPEND lt_drat.

   lt_drat-language = 'DE'.

   lt_drat-description = 'Sample PDF'.

   APPEND lt_drat.

**********************************************************

** create object link to material master record

***********************************************************

*  CLEAR lt_drad.

*  REFRESH lt_drad.

*  lt_drad-objecttype = 'MARA'.

*  lt_drad-objectkey = 'M4711'.

*  APPEND lt_drad.

**************************************************************

** call BAPI

**************************************************************

   CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'

   EXPORTING

     documentdata = ls_doc

   IMPORTING

     documenttype = lf_doctype

     documentnumber = lf_docnumber

     documentpart = lf_docpart

     documentversion = lf_docversion

     return = ls_return

   TABLES

     documentdescriptions = lt_drat

     objectlinks = lt_drad

     documentfiles = lt_files.

** error occured ??

   IF ls_return-type CA 'EA'.

     ROLLBACK WORK.

     MESSAGE ID '26' TYPE 'I' NUMBER '000'

     WITH ls_return-message.

   ELSE.

     COMMIT WORK.

     MESSAGE 'Successful insert document!' TYPE 'I'.

   ENDIF.

ENDFORM.                    "create_new_2

Answers (0)