‎2006 Nov 27 6:43 AM
Hi there!
I have an excel file with 14 columns that would like to be posted:
ITEMNO_ACC DOC_TYPE GL_ACCOUNT DOC_DATE BLINE_DATE CURRENCY COSTCENTER
COMP_CODE HEADER_TEXT REF_DOC_NO ALLOC_NMBR ITEM_TEXT SP_GL_IND AMT_DOCCURI created a selection screen to key in 'posting date' and upload this excel file.
I use FM ALSM_EXCEL_TO_INTERNAL_TABLE to convert the excel file into an internal table 'itab'. Now, i would like to use <b>FM BAPI_ACC_DOCUMENT_CHECK</b> to do checking before posting.
But I have no idea how to use this BAPI FM? Does anybody have example on this?
thanks a lot!
‎2006 Nov 27 7:02 AM
Hi,
Check the following link.
report zsandeep1.
types: begin of ts_exceldata,
col1(20) type c,
col2(20) type c,
col3(20) type c,
col4(20) type c,
col5(20) type c,
col6(20) type c,
col7(20) type c,
col8(20) type c,
col9(20) type c,
col10(20) type c,
col11(20) type c,
col12(20) type c,
col13(20) type c,
end of ts_exceldata,
tt_exceldata type table of ts_exceldata.
For Document Header
types: begin of ts_docheader,
bus_act type bapiache09-bus_act,
header_txt type bapiache09-header_txt,
comp_code type bapiache09-comp_code,
doc_date type bapiache09-doc_date,
pstng_date type bapiache09-pstng_date,
doc_type type bapiache09-doc_type,
ref_doc_no type bapiache09-ref_doc_no,
unique_no type n,
end of ts_docheader,
tt_docheader type table of ts_docheader.
For Account GL
types: begin of ts_accountgl,
gl_account type bapiacgl09-gl_account,
item_text type bapiacgl09-item_text,
acct_key type bapiacgl09-acct_key,
alloc_nmbr type bapiacgl09-alloc_nmbr,
tax_code type bapiacgl09-tax_code,
taxjurcode type bapiacgl09-taxjurcode,
costcenter type bapiacgl09-costcenter,
profit_ctr type bapiacgl09-profit_ctr,
orderid type bapiacgl09-orderid,
trade_id type bapiacgl09-trade_id,
cs_trans_t type bapiacgl09-cs_trans_t,
unique_no type n,
end of ts_accountgl,
tt_accountgl type table of ts_accountgl.
For Account Tax
types: begin of ts_accounttax,
tax_code type bapiactx09-tax_code,
taxjurcode type bapiactx09-taxjurcode,
unique_no type n,
end of ts_accounttax,
tt_accounttax type table of ts_accounttax.
For Currency Amount
types: begin of ts_curramount,
curr_type type bapiaccr09-curr_type,
currency type bapiaccr09-currency,
amt_doccur type bapiaccr09-amt_doccur,
amt_base type bapiaccr09-amt_base,
unique_no type n,
end of ts_curramount,
tt_curramount type table of ts_curramount.
data: lv_doc type c,
lv_pk type c,
lv_unique_no type n.
data: ls_exceldata type ts_exceldata,
lt_exceldata type tt_exceldata,
ls_intern type alsmex_tabline,
lt_intern type table of alsmex_tabline,
For Document Header
ls_docheader type ts_docheader,
lt_docheader type tt_docheader,
For Account GL
ls_accountgl type ts_accountgl,
lt_accountgl type tt_accountgl,
lt_accountgl_bapi type tt_accountgl,
For Account Tax
ls_accounttax type ts_accounttax,
lt_accounttax type tt_accounttax,
lt_accounttax_bapi type tt_accounttax,
For Currency Amount
ls_curramount type ts_curramount,
lt_curramount type tt_curramount,
lt_curramount_bapi type tt_curramount.
data: lv_index type i.
field-symbols: <fs>.
constants: lc_bus_act type bapiache09-bus_act value 'RFBU',
lc_doc_type type bapiache09-doc_type value 'SA',
lc_curr_type type bapiaccr09-curr_type value '00'.
Read Excel file into internal table
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = 'C:\given_excel_format'
i_begin_col = 1
i_begin_row = 1
i_end_col = 100
i_end_row = 100
tables
intern = lt_intern
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc eq 0.
check 1 eq 1.
endif.
sort lt_intern by row col.
loop at lt_intern into ls_intern.
move ls_intern-col to lv_index.
assign component lv_index of structure ls_exceldata to <fs>.
move ls_intern-value to <fs>.
at end of row.
append ls_exceldata to lt_exceldata.
clear ls_exceldata.
endat.
endloop.
loop at lt_exceldata into ls_exceldata.
translate ls_exceldata-col1 to upper case.
To skip headings
if ls_exceldata-col1 eq 'DOC DATE'.
lv_doc = 'X'.
lv_pk = ' '.
lv_unique_no = lv_unique_no + 1.
continue.
elseif ls_exceldata-col1 eq 'PK'.
lv_doc = ' '.
lv_pk = 'X'.
continue.
endif.
To get header data into header internal table
if lv_doc = 'X'.
lv_doc = ' '.
Document header
ls_docheader-bus_act = lc_bus_act.
ls_docheader-doc_type = lc_doc_type.
ls_docheader-doc_date = ls_exceldata-col1.
ls_docheader-pstng_date = ls_exceldata-col2.
ls_docheader-comp_code = ls_exceldata-col3.
ls_docheader-ref_doc_no = ls_exceldata-col5.
ls_docheader-header_txt = ls_exceldata-col6.
ls_docheader-unique_no = lv_unique_no.
append ls_docheader to lt_docheader.
clear ls_docheader.
Currnecy Amount item
ls_curramount-currency = ls_exceldata-col4.
endif.
***********************************************
Fill line item data *
*
***********************************************
To get item data into item internal table
if lv_pk = 'X'.
Account GL item
ls_accountgl-gl_account = ls_exceldata-col2.
ls_accountgl-tax_code = ls_exceldata-col4.
ls_accountgl-taxjurcode = ls_exceldata-col6.
ls_accountgl-costcenter = ls_exceldata-col7.
ls_accountgl-orderid = ls_exceldata-col8.
ls_accountgl-profit_ctr = ls_exceldata-col9.
ls_accountgl-acct_key = ls_exceldata-col10.
ls_accountgl-cs_trans_t = ls_exceldata-col10.
ls_accountgl-trade_id = ls_exceldata-col11.
ls_accountgl-alloc_nmbr = ls_exceldata-col12.
ls_accountgl-item_text = ls_exceldata-col13.
ls_accountgl-unique_no = lv_unique_no.
append ls_accountgl to lt_accountgl.
clear ls_accountgl.
Account Tax item
ls_accounttax-tax_code = ls_exceldata-col4.
ls_accounttax-taxjurcode = ls_exceldata-col6.
ls_accounttax-unique_no = lv_unique_no.
append ls_accounttax to lt_accounttax.
clear ls_accounttax.
Currnecy Amount item
ls_curramount-curr_type = lc_curr_type.
ls_curramount-amt_doccur = ls_exceldata-col3.
ls_curramount-amt_base = ls_exceldata-col5.
ls_curramount-unique_no = lv_unique_no.
append ls_curramount to lt_curramount.
clear ls_curramount.
endif.
endloop.
Check if there are any errors
loop at lt_docheader into ls_docheader.
Get Account GL item for specific document
loop at lt_accountgl into ls_accountgl
where unique_no eq ls_docheader-unique_no.
append ls_accountgl to lt_accountgl_bapi.
endloop.
Get Account Tax item for specific document
loop at lt_accounttax into ls_accounttax
where unique_no eq ls_docheader-unique_no.
append ls_accounttax to lt_accounttax_bapi.
endloop.
Get Currency Amount for specific document
loop at lt_curramount into ls_curramount
where unique_no eq ls_docheader-unique_no.
append ls_curramount to lt_curramount_bapi.
endloop.
Call BAPI
call function 'BAPI_ACC_DOCUMENT_CHECK'
exporting
documentheader = ls_docheader
tables
accountgl = lt_accountgl_bapi[]
accounttax = lt_accounttax_bapi[]
currencyamount = lt_curramount_bapi[].
endloop.
Rgds,
Sunil.K
‎2006 Nov 27 7:54 AM
Hi Sunil!
thanks for your prompt reply.. i am now trying it. Thanks a lot!
Best regards,
ying