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_CREATE error

Former Member
0 Likes
551

Hi Guys,

I am using this bapi to create one document number but I am getting error: BAPI Error creating REF doc

Below is my code can somebody tell me wht I am missing?

data: ls_doc like bapi_doc_draw,

ls_return like bapiret2.

data: lf_doctype like bapi_doc_draw-documenttype,

lf_docnumber like bapi_doc_draw-documentnumber,

lf_docpart like bapi_doc_draw-documenttype,

lf_docversion like bapi_doc_draw-documenttype.

    • Allocate document data

ls_doc-documenttype = 'REF'.

ls_doc-documentnumber = doknr.

ls_doc-documentversion = '000'.

ls_doc-documentpart = '00'.

ls_doc-description = dktxt.

ls_doc-statusextern = 'FR'.

ls_doc-authoritygroup = p_auth_group.

call function 'BAPI_DOCUMENT_CREATE'

exporting: documentdata = ls_doc

importing: documenttype = lf_doctype

documentnumber = lf_docnumber

documentpart = lf_docpart

documentversion = lf_docversion

return = ls_return.

clear bdc_status.

bdc_status-session_name = e_group.

bdc_status-tran_id = 'BAPI'.

bdc_status-object_id = part32.

bdc_status-plant = ' '.

bdc_status-process_date = sy-datum.

bdc_status-process_time = sy-uzeit.

    • Error occurred ??

if ls_return-type ca 'EA'.

rollback work.

bdc_status-message_type = 'E'.

bdc_status-message_nbr = '000000'.

concatenate 'BAPI Error creating REF doc' doknr

into bdc_status-messages separated by space.

append bdc_status.

bdc_status-messages = ls_return-message.

append bdc_status.

else.

bdc_status-message_type = 'S'.

bdc_status-message_nbr = '000000'.

concatenate 'REF doc' doknr 'Created successfully'

into bdc_status-messages separated by space.

append bdc_status.

commit work and wait.

endif.

Thanks!

3 REPLIES 3
Read only

lijisusan_mathews
Active Contributor
0 Likes
472

Did you try running this BAPI from se37 with all the parameters you are passing through the program. if not try it, . You can see teh messages and understand if any error occurs.

Read only

0 Likes
472

It worked in SE37. But not workin in program. I don't know what I am missing in code

Read only

0 Likes
472

Hi,

do you run the BAPI several times in a loop, if yes then does it work first time? If yes, that would mean that the BAPI buffer has not been refreshed between the 2 calls. To do it, you must use function modules BAPI_TRANSACTION_COMMIT and BAPI_TRANSACTION_ROLLBACK, instead of COMMIT WORK and ROLLBACK WORK respectively.

There seems to be some batch input somewhere (I see variables BDC...) in your program, around the BAPI?, how do they work together?

BR

Sandra