‎2008 Aug 31 12:55 PM
Hi All,
I have to use BAPI_ACC_GL_POSTING_POST for gl account posting.
I have a flat file with multiple Headers and each header will have multiple line items.
1.How to post these type of flat file using Bapi?(i have to pass 998 line items as one set,and 999th set shound be balancing entry).
2.After posting through bapi_acc_gl_posting_post, i have to generate a report showing Detail of line item in which error has occured.(details like lineitem,company code,costcenter,profit center posting key,amt,tax amont and total).
3.And also if bapi fails to popst set of 998 line items,all these have to go to BDC session.
please suggest me something regarding this requirement.(if that would be code related to this requirement it will be more help full).
Thank you all in advance!!!!
Kiran
‎2008 Sep 01 11:47 AM
Hi Ravikiran,
Please follow these steps
First step: Please build a internal table with fields from you file.
i hope you would have the following fields in the file
data: BEGIN OF gt_table,
blart TYPE bkpf-blart, "(Document type)
message(120) TYPE c, "(message)
bldat TYPE bkpf-bldat, "(Document date)
budat TYPE bkpf-budat, "(Posting date)
waers TYPE bkpf-waers, "(Currency)
xblnr TYPE bkpf-xblnr, "(Header Ref)
bktxt TYPE bapiache09-header_txt, "(Header Text)
newbs TYPE rf05a-newbs, "(Posting Key)
newbw TYPE rf05a-newbw, "(Transaction type)
newko TYPE bapiacgl09-gl_account, "(Account code)
aufnr TYPE cobl-aufnr, "(Internal order)
prctr TYPE bseg-prctr, "(Profit center)
kostl TYPE cobl-kostl, "(Cost center)
wrbtr TYPE bseg-wrbtr, "(Amount in Transaction Curr)
zuonr TYPE bseg-zuonr, "(Assignment)
sgtxt TYPE bseg-sgtxt, "(Text)
mwskz TYPE bseg-mwskz, "(Tax Code)
zterm TYPE bseg-zterm, "(payment terms)
kkber TYPE bseg-kkber, "(Credit control area)
zfbdt TYPE bseg-zfbdt, "(Baseline Date)
bukrs TYPE bkpf-bukrs, "(Company Code)
gjahr TYPE bseg-gjahr, "(Fiscal Year)
end of gt_table.
Second step:
Use the FM GUI_UPLOAD with the following parameters to upload the data in the flat file into your internal table.,
EXPORTING
filename = lv_filename
filetype = 'ASC'
has_field_separator = cl_abap_char_utilities=>horizontal_tab
TABLES
data_tab = gt_table
Third step:
There are seperate structures in the Bapi, ie, DOCUMENTHEADER, ACCOUNTGL, CURRENCYAMOUNT which needs to be filled from the internal table.
You cannot post all the documents to gether in a single call to the bapi. So you have to loop at the table and at the end of each document you should call the bapi and pass the relevant details to the structures.
I will give the mandatory fields that you have to pass to the structures, anythign additional pls add as per you requirement.
looping at the table
Header structure: DOCUMENTHEADER,
wa_header-username = g_uname.
wa_header-comp_code = p_bukrs.
wa_header-doc_date = wa_table-bldat.
wa_header-pstng_date = wa_table-budat.
wa_header-doc_type = wa_table-blart.
wa_header-fisc_year = wa_table-gjahr.
wa_header-header_txt = wa_table-bktxt.
G/L account structure : ACCOUNTGL
wa_accountgl-itemno_acc = '0000000001'.
wa_accountgl-gl_account = wa_table-newko.
wa_accountgl-item_text = wa_table-sgtxt.
wa_accountgl-doc_type = wa_table-blart.
wa_accountgl-comp_code = wa_table-bukrs.
wa_accountgl-fisc_year = wa_table-gjahr.
wa_accountgl-pstng_date = wa_table-budat.
wa_accountgl-costcenter = wa_table-kostl.
wa_accountgl-profit_ctr = wa_without_copa-prctr.
wa_accountgl-orderid = wa_without_copa-aufnr.
wa_accountgl-alloc_nmbr = wa_without_copa-zuonr.
wa_accountgl-tax_code = wa_without_copa-mwskz.
append wa_accountgl to gt_accountgl.
Currency structure: CURRENCYAMOUNT
wa_currency-itemno_acc = '0000000001'.
wa_currency-CURRENCY = wa_without_copa-waers.
IF wa_without_copa-newbs IN r_newbs.
wa_currency-amt_doccur = wa_without_copa-wrbtr * -1.
ELSE.
wa_currency-amt_doccur = wa_without_copa-wrbtr.
ENDIF.
APPEND wa_currency TO gt_currency.
Note : 1) Please note that
wa_header is of type BAPIACHE08
gt_accountgl and wa_accountgl are of type BAPIACGL08,
gt_currency and wa_currency are of type BAPIACCR08.
2) The itemno_acc, a item number should maintained same for a line item in both accountgl and currency structure.
3) PLease append header details only at the start of new document, do not fil it for all line items.
4) To pass the posting key we dont have a parameter, so better decide the number posting keys used and in the amount please add the sign according to the posting key , in my case i have created a range for negative posting keys and have put a condition to decide on the sign of the amount.
Fourth step: At the end of a document, call the bapi, BAPI_ACC_GL_POSTING_POST
CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
EXPORTING
documentheader = wa_header
CUSTOMERCPD =
CONTRACTHEADER =
IMPORTING
obj_type =
obj_key = g_objkey
OBJ_SYS =
TABLES
accountgl = gt_accountgl
currencyamount = gt_currency
VALUEFIELD =
extension1 =
return = gt_return
PAYMENTCARD =
CONTRACTITEM =
EXTENSION2 =
REALESTATE =
ACCOUNTWT =
.
I would request you to try to pass the values manually into the Bapi and then do it, so that you will understand better.
gt_return will get you the error or success message for each posting, so you can fetch the error records from that.
To create a BDC session you can use the FMs
BDC_OPEN_GROUP , BDC_insert and BDC_CLOSE_GROUP.