Skip to Content
0
Former Member
Jan 05, 2011 at 10:41 PM

'BAPI_DOCUMENT_CREATE2': store attachment using 'SAP-SYSTEM'

968 Views

while i am checkin a document (attachment) using storage category KPRO ,the document is getting stored but when i use SAP-SYSTEM the Document is not getting stored. How can I get it stored using 'SAP-SYSTEM'

Following is the code;

DATA:

lv_docnum TYPE bapi_doc_aux-docnumber,

lw_docdata TYPE bapi_doc_draw2,

lw_return TYPE bapiret2,

lw_dsp TYPE bapi_doc_drat,

lw_objlink TYPE bapi_doc_drad,

lw_docfile TYPE bapi_doc_files2,

lt_dsp TYPE STANDARD TABLE OF bapi_doc_drat,

lt_objlink TYPE STANDARD TABLE OF bapi_doc_drad,

lt_docfile TYPE STANDARD TABLE OF bapi_doc_files2.

START-OF-SELECTION.

*

*CALL 'SAPCORE' ID 'ID' FIELD 'VERSION'

ID 'TABLE' FIELD kernel_version-sys*.

*READ TABLE kernel_version INDEX 11.

*w_hostname = kernel_version-data.

CLEAR lw_docdata.

lw_docdata-documenttype = 'ZAP'.

lw_docdata-documentversion = 'A0'.

lw_docdata-documentpart = '000'.

lw_docdata-laboratory = '001'.

CLEAR lw_dsp.

lw_dsp-description = 'Test created by xyz'.

lw_dsp-language = 'E'.

APPEND lw_dsp TO lt_dsp.

lw_docfile-docfile = 'C:\test.pdf'.

  • lw_docfile-docpath = 'C:\test.pdf'.

  • LW_DOCFILE-ORIGINALTYPE = '1'.

lw_docfile-storagecategory = 'SAP-SYSTEM'.

  • lw_docfile-storagecategory = 'DMS_C1_ST'.

lw_docfile-wsapplication = 'PDF'.

lw_docfile-language = 'E'.

lw_docfile-checkedin = ' '.

  • lw_docfile-checkedin = 'X'.

lw_docfile-active_version = 'X'.

APPEND lw_docfile TO lt_docfile.

CLEAR lw_objlink.

lw_objlink-objecttype = 'VBAP'.

lw_objlink-objectkey = '0040011233000010'.

lw_objlink-documentdirection = 'X'.

APPEND lw_objlink TO lt_objlink.

CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'

EXPORTING

documentdata = lw_docdata

pf_ftp_dest = 'SAPFTPA'

pf_http_dest = 'SAPHTTPA'

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

IMPORTING

documentnumber = lv_docnum

return = lw_return

TABLES

documentdescriptions = lt_dsp

objectlinks = lt_objlink

documentfiles = lt_docfile.

IF lw_return-type CA 'EA'.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

MESSAGE ID lw_return-id

TYPE lw_return-type

NUMBER lw_return-number.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

CLEAR lw_return.

CALL FUNCTION 'BAPI_DOCUMENT_CHECKIN2'

EXPORTING

documenttype = 'ZAP'

documentnumber = lv_docnum

documentpart = '000'

documentversion = 'A0'

IMPORTING

return = lw_return

TABLES

documentfiles = lt_docfile.

IF lw_return-type CA 'EA'.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

MESSAGE ID lw_return-id

TYPE lw_return-type

NUMBER lw_return-number.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

WRITE: / 'document number = ', lv_docnum.

ENDIF.

ENDIF.