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 'BAPI_ACC_DOCUMENT_POST' Gives me Error when adding more than one

Former Member
0 Likes
2,404

Hi

I have created code that has a loop and adds GL Documents in SAP.

If I only add one document it works fine.

If I add more than one document, the first one goes through fine. The second and anything after fail. The ones that fail give the following error

"FI/CO interface: Line item entered several times"

Usually get this error if you define more than one row with the same row number, in other words they are not unique row n numbers.

But the first GL Document has row id 1 for the 1st row, row id 2 for the 2nd row.

the second GL Document has row id 1 for the 1st row, row id 2 for the 2nd row.

It should not conflict with each other as each document gets "commited" before I start with the next document.

The only thing I can think of is that after I commit the bapi it is not clearing the BAPI. Does one need to clear the BAPI before adding another GL Document??? How does one clear the BAPI???

Does anyone have a simple example using 'BAPI_ACC_DOCUMENT_POST' where you have a loop and add a GL Document a few times???

Any response is appreciated

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,416

it should work once after you commit and refresh the line items and currency table and start with the 2nd document summary lines. I have used the bapi for such documents and it works fine.

3 REPLIES 3
Read only

Former Member
0 Likes
1,417

it should work once after you commit and refresh the line items and currency table and start with the 2nd document summary lines. I have used the bapi for such documents and it works fine.

Read only

0 Likes
1,416

Hi

Thanks for the response. Greatly appreciated.

I was clearing the lines instead of refresh.

Thanks.

Thanks Hema Nagarajan for the example.

Read only

Former Member
0 Likes
1,416

Hi,

This BAPI works fine. I have tried it before. Even I got the same error first time. Collect your data into an internal table. Loop through it, and try adding records to BAPI Structures after clearing and refreshing the structures for every document. It works fine.

This BAPI has a problem, that there is no provision for Posting Key.

Try using following Program

-


REPORT ZFI_GLDOC_POSTING message-id zfimsg.

TYPE-POOLS truxs.

TABLES: BGR00,BBKPF,BBSEG.

types: begin of t_excel,

bldat type bbkpf-bldat,

blart type bbkpf-blart,

bukrs type bbkpf-bukrs,

budat type bbkpf-budat,

waers type bbkpf-waers,

kursf type bbkpf-kursf,

xblnr type bbkpf-xblnr,

newbs type bbseg-newbs,

newbk type bbseg-newbk,

dmbtr type bbseg-dmbtr,

zfbdt type bbseg-zfbdt,

zuonr type bbseg-zuonr,

sgtxt type bbseg-sgtxt,

newko type bbseg-newko,

newum type bbseg-newum,

end of t_excel.

data : i_excel type standard table of t_excel,

wa_excel type t_excel,

it_type type truxs_t_text_data.

data: lt_file_table type filetable,

la_file_table like line of lt_file_table,

l_pcdsn type cffile-filename,

l_rc type i,

va_file(40) type c value 'TEST.TXT',

p_name(10) type c value 'FIDOC',

v_date type d,

v_amount type bseg-dmbtr,

linecount type i.

selection-screen begin of block sel_block1 with frame title text-001.

parameter p_file type grap-filename.

selection-screen end of block sel_block1.

selection-screen begin of block sel_block2 with frame title text-002.

parameters p_gla type c radiobutton group rgrp default 'X'.

parameters p_rec type c radiobutton group rgrp.

parameters p_pay type c radiobutton group rgrp.

selection-screen end of block sel_block2.

at selection-screen on value-request for p_file.

refresh lt_file_table.

clear la_file_table.

clear l_rc.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

CHANGING

file_table = lt_file_table

rc = l_rc

EXCEPTIONS

FILE_OPEN_DIALOG_FAILED = 1

CNTL_ERROR = 2

ERROR_NO_GUI = 3

NOT_SUPPORTED_BY_GUI = 4.

if sy-subrc <> 0.

message i006.

endif.

if l_rc <= 0.

message e007.

endif.

clear p_file.

read table lt_file_table into la_file_table index 1.

l_pcdsn = la_file_table-filename.

move l_pcdsn to p_file.

if not ( p_file cp '*.xls').

message e004.

endif.

at selection-screen on p_file.

if not ( p_file cp '*.xls').

message e004.

endif.

start-of-selection.

if p_gla = 'X'.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_tab_raw_data = it_type

i_filename = p_file

TABLES

i_tab_converted_data = i_excel[]

EXCEPTIONS

CONVERSION_FAILED = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

linecount = 0.

OPEN DATASET VA_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

CLEAR BGR00.

BGR00-STYPE = '0'.

BGR00-GROUP = P_NAME.

BGR00-MANDT = SY-MANDT.

BGR00-USNAM = SY-UNAME.

BGR00-START = ' '.

BGR00-XKEEP = 'X'.

BGR00-NODATA = '/'.

TRANSFER BGR00 TO VA_FILE.

loop at i_excel into wa_excel.

if wa_excel-bukrs is not initial.

linecount = linecount + 1.

if linecount = 11.

CLOSE DATASET VA_FILE.

SUBMIT RFBIBL00 WITH DS_NAME = VA_FILE WITH CALLMODE = 'D' WITH XPOP = 'X' AND RETURN.

commit work.

linecount = 1.

OPEN DATASET VA_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

CLEAR BGR00.

BGR00-STYPE = '0'.

BGR00-GROUP = P_NAME.

BGR00-MANDT = SY-MANDT.

BGR00-USNAM = SY-UNAME.

BGR00-START = ' '.

BGR00-XKEEP = 'X'.

BGR00-NODATA = '/'.

TRANSFER BGR00 TO VA_FILE.

endif.

CLEAR BBKPF.

BBKPF-STYPE = '1'.

BBKPF-TCODE = 'FB01'.

move wa_excel-bldat to v_date.

write v_date to bbkpf-bldat ddmmyy.

BBKPF-BLART = wa_excel-blart.

BBKPF-BUKRS = wa_excel-bukrs.

move wa_excel-budat to v_date.

write v_date to bbkpf-budat ddmmyy.

BBKPF-WAERS = wa_excel-waers.

move wa_excel-kursf to v_amount.

write v_amount to bbkpf-kursf currency wa_excel-waers.

bbkpf-xblnr = wa_excel-xblnr.

bbkpf-sende = '/'.

TRANSFER BBKPF TO VA_FILE.

endif.

CLEAR BBSEG.

BBSEG-STYPE = '2'.

BBSEG-TBNAM = 'BBSEG'.

bbseg-newbs = wa_excel-newbs.

bbseg-newbk = wa_excel-newbk.

move wa_excel-dmbtr to v_amount.

write v_amount to bbseg-dmbtr currency 'INR'.

write v_amount to bbseg-wrbtr currency 'INR'.

move wa_excel-zfbdt to v_date.

write v_date to bbseg-zfbdt ddmmyy.

bbseg-zuonr = wa_excel-zuonr.

bbseg-sgtxt = wa_excel-sgtxt.

bbseg-newko = wa_excel-newko.

bbseg-newum = wa_excel-newum.

bbseg-sende = '/'.

TRANSFER BBSEG TO VA_FILE.

endloop.

CLOSE DATASET VA_FILE.

SUBMIT RFBIBL00 WITH DS_NAME = VA_FILE WITH CALLMODE = 'D' WITH XPOP = 'X' AND RETURN.

commit work.

message i005.

endif.

end-of-selection.

-


We have used this program many times for bulk loading of Accounting Documents.

Regards,

Hema