Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

'BAPI_DOCUMENT_CREATE2'

Former Member
0 Likes
2,922

Hello,

I am trying to create document "CV01N" with PDF attachment.

I am using BAPI 'BAPI_DOCUMENT_CREATE2' to create document. It is creating document but is not attaching the PDF document. I am running in foreground mode. Tried to seach forum but did not find solution.

Following is the code i am using:

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.

CLEAR lw_docdata.

lw_docdata-documenttype = 'ZAC'.

lw_docdata-documentversion = 'A0'.

lw_docdata-documentpart = '000'.

lw_docdata-laboratory = '001'.

CLEAR lw_dsp.

lw_dsp-description = 'Test '.

lw_dsp-language = 'E'.

APPEND lw_dsp TO lt_dsp.

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

  • LW_DOCFILE-ORIGINALTYPE = '1'.

lw_docfile-storagecategory = 'SAP-SYSTEM'.

lw_docfile-wsapplication = 'PDF'.

lw_docfile-language = 'E'.

  • 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 = '0040081239000010'.

lw_objlink-documentdirection = 'X'.

APPEND lw_objlink TO lt_objlink.

CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'

EXPORTING

documentdata = lw_docdata

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 = 'ZTR'

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.

8 REPLIES 8
Read only

Former Member
0 Likes
2,036

Hello,

the document must be exist for checkin a file.

In you code, you create a documenttype = 'ZAC' and you want to checkin on a documenttype = 'ZTR'

For checkin a document, Y use BAPI_DOCUMENT_CHANGE2

CLEAR lt_documentfiles_new. REFRESH lt_documentfiles_new.

lt_documentfiles_new-sourcedatacarrier = carrier.

lt_documentfiles_new-storagecategory = storage.

lt_documentfiles_new-wsapplication = dappl.

lt_documentfiles_new-docfile = filep.

APPEND lt_documentfiles_new.

CALL FUNCTION 'BAPI_DOCUMENT_CHANGE2'

EXPORTING

documenttype = dokar

documentnumber = doknr

documentpart = doktl

documentversion = dokvr

documentdata = ls_doc

documentdatax = ls_docx

pf_ftp_dest = 'SAPFTP'

pf_http_dest = 'SAPHTTP'

IMPORTING

return = ls_return

TABLES

documentfiles = lt_documentfiles_new.

Hope this can help you

Thierry

Read only

0 Likes
2,036

I made both the document types ZTR but still it does not work.

THanks

Read only

0 Likes
2,036

I am able to create document and load attachments after applying oss note 0001173675. But some how it is uploading duplicate attachment instead of only one. Any suggestion?

THanks.

Read only

0 Likes
2,036

I am able to attach only 2 files as attachment. How do you increase number in configuration.\

Also when i do file checkin the file name in disappearing. How can I keep the file name.

Thanks.

Read only

0 Likes
2,036

I am using FM 'BAPI_DOCUMENT_CREATE2' and FM ''CVAPI_DOC_CHECKIN'' to create document and attachment and then checkin the document.

I am able to accomplish all the step. when i do file checkin the file name in disappearing. How can I keep the file name? When i attach the file I can see the name but when I checkin the file name disappers but the files are there.

I am able to attach only 2 files as attachment. How do you increase number in configuration.

Thanks,

Read only

0 Likes
2,036

Hello,

>>the file name disappers but the files are there.

Perhaps you must filled the PT_FILES_X-FILENAME

Thierry

Read only

0 Likes
2,036

Hello Thierry,

In FM ''CVAPI_DOC_CHECKIN'' I am passing the file to be updated in parameter PT_FILES_X-FILENAME. Still it is not working. If i do manual check in. It shows the file name.

Thanks.

Read only

0 Likes
2,036

Hello,

And did you try to fill the PT_COMP_X-FILENAME ?

If it is ok with manuel check, then the problem is on a paramter of the function

there is examples with that function on the forum :

-

-

Thierry