‎2007 Aug 27 4:37 AM
hi,
i was using BAPI_ACC_DOCUMENT_POST to do document posting, but should it give me a document number when successfully posted ? for example, when using f-43 and press save button, it'll said "Document XXXX was posted to.....".
i wander to know if BAPI_ACC_DOCUMENT_POST do same things as f-43, and if so, how to get the document XXXX number ? there's no such number in the return parameter.
(Note i a do commit it using BAPI_TRANSACTION_COMMIT )
thank you !
‎2007 Aug 27 4:57 AM
Hello Zhang
Have you checked the value in EXPORTING parameter <b>OBJ_KEY</b>?
Assuming that you post a FI document the object key should look like:
- <company code><document number>
Example:
- Company code = '1000'
- Document number -> internal number when new document is created ('1234567890'
=> obj_key= '10001234567890'
Regards
Uwe
‎2007 Aug 27 4:57 AM
Hello Zhang
Have you checked the value in EXPORTING parameter <b>OBJ_KEY</b>?
Assuming that you post a FI document the object key should look like:
- <company code><document number>
Example:
- Company code = '1000'
- Document number -> internal number when new document is created ('1234567890'
=> obj_key= '10001234567890'
Regards
Uwe
‎2007 Aug 27 5:17 AM
Hi Zhang,
After you call the BAPI_ACC_DOCUMENT_POST with correct parameters, the FI document (in your case vendor invoice) should be successfully posted and return table RETURN filled with system messages. Now loop at/read table RETURN with field TYPE = 'S' and ID = 'RW' and NUMBER = '605'. (These values have been hard-coded within the BAPI code by SAP - so you need not worry). <b>If the read was successful, the document number posted will be the first 10 characters in the field MESSAGE_V2 in table RETURN.</b>
Don't forget to reward points.
Cheers,
Sougata.
‎2007 Oct 08 7:50 AM
Hi ,
Can you send me thr program to post document through BAPI_ACC_DOCUMENT_POST.I have a scenerio to post document through Transaction Code : f-43.
Regards,
L Srikanthan
‎2007 Oct 11 3:26 AM
hi,
code part my place
data:
documentheader like bapiache09,
accountgl like table of bapiacgl09 with header line,
accountpayable like table of bapiacap09 with header line,
currencyamount like table of bapiaccr09 with header line,
return like table of bapiret2 with header line,
obj_type like bapiache09-obj_type,
obj_key like bapiache09-obj_key,
obj_sys like bapiache09-obj_sys.
form main_bapi.
loop at it_data into wa_data.
" prepare posting code for items
case wa_data-bschl.
when '22' or '25' or '26'. " 借
flag = 'D'.
when '31' or '35' or '36'.
flag = 'C'.
endcase.
" fill document header
documentheader-doc_date = wa_data-bldat. " 凭证日期
documentheader-pstng_date = p_budat. " 记帐日期
documentheader-doc_type = wa_data-blart. " 凭证类型
documentheader-fis_period = p_monat. " 过账期间
documentheader-comp_code = '3100'. " 公司代码
" 货币
documentheader-ref_doc_no = wa_data-xblnr. " 参照
documentheader-header_txt = wa_data-bktxt. " 凭证抬头文本
documentheader-username = sy-uname.
documentheader-bus_act = 'RFBU'. " 总帐事务类型
" fill line items
if wa_data-blart = 'KZ'.
clear accountpayable.
accountpayable-itemno_acc = 1.
accountpayable-vendor_no = wa_data-lifnr. " 供应商
accountpayable-bline_date = wa_data-zfbdt. " 基准日期
accountpayable-alloc_nmbr = '310100'. " 分配
accountpayable-item_text = wa_data-sgtxt. " 项目文本
append accountpayable.
clear accountgl.
accountgl-itemno_acc = 2.
accountgl-gl_account = '9999999999'.
accountgl-item_text = wa_data-sgtxt.
accountgl-doc_type = 'S'.
accountgl-alloc_nmbr = '0000310100'.
accountgl-profit_ctr = '0000310100'.
accountgl-funds_ctr = '0000310100'.
append accountgl.
clear currencyamount.
currencyamount-itemno_acc = 1. " 行项目编号
currencyamount-currency = 'CNY'. " 货币
if flag = 'C'.
currencyamount-amt_doccur = wa_data-wrbtr * ( -1 ).
else.
currencyamount-amt_doccur = wa_data-wrbtr.
endif.
currencyamount-disc_base = currencyamount-amt_doccur.
append currencyamount.
clear currencyamount.
currencyamount-itemno_acc = 2. " 行项目编号
currencyamount-currency = 'CNY'. " 货币
if flag = 'C'.
currencyamount-amt_doccur = wa_data-wrbtr .
else.
currencyamount-amt_doccur = wa_data-wrbtr * ( -1 ).
endif.
currencyamount-disc_base = currencyamount-amt_doccur.
append currencyamount.
endif.
if wa_data-blart = 'RE'.
clear it_bseg.
refresh it_bseg.
" line items table IT_BSEG
select bukrs belnr buzei gjahr koart lifnr
zuonr wrbtr ebeln ebelp bschl projk
sgtxt zterm zfbdt
from bseg
into corresponding fields of table it_bseg
where bukrs = wa_data-bukrs
and belnr = wa_data-belnr
and gjahr = wa_data-gjahr.
loop at it_bseg where koart = 'K'.
t_lifnr = it_bseg-lifnr.
endloop.
" loop through line items
index = 1.
loop at it_bseg.
if it_bseg-koart = 'K'.
t_lifnr = it_bseg-lifnr.
" if vendor item, generate a G/L item accordingly
clear accountgl.
accountgl-gl_account = '9999999999'. " 总分类帐帐目
accountgl-acct_type = 'S'. " 帐户类型
accountgl-itemno_acc = index. " 行项目编号
accountgl-profit_ctr = '0000310100'. " 利润中心
accountgl-alloc_nmbr = '0000310100'. " 分配
accountgl-funds_ctr = '0000310100'. " 基金中心
accountgl-item_text = it_bseg-sgtxt." 项目文本
append accountgl.
" fill currency item in each loop of it_bseg
clear currencyamount.
currencyamount-itemno_acc = index. " 行项目编号
currencyamount-currency = 'CNY'. " 货币
if flag = 'C'.
currencyamount-amt_doccur = it_bseg-wrbtr. " 凭证货币金额
else.
currencyamount-amt_doccur = it_bseg-wrbtr * ( -1 ).
endif.
currencyamount-disc_base = currencyamount-amt_doccur.
append currencyamount.
else.
" if not vendor items, generate vendor items
if flag = 'C' and it_bseg-bschl(1) = '8'. " 贷借
flag2 = -1.
endif.
if flag = 'C' and it_bseg-bschl(1) = '9'. " 贷贷
flag2 = 1.
endif.
if flag = 'D' and it_bseg-bschl(1) = '8'. " 借借
flag2 = -1.
endif.
if flag = 'D' and it_bseg-bschl(1) = '9'. " 借贷
flag2 = 1.
endif.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = it_bseg-ebelp
importing
output = it_bseg-ebelp.
concatenate
wa_data-gjahr(4) ' + ' wa_data-belnr ' + ' it_bseg-ebeln ' + ' it_bseg-ebelp
into it_bseg-sgtxt.
clear accountpayable.
accountpayable-itemno_acc = index. " 行项目编号
accountpayable-vendor_no = t_lifnr. " 供应商
accountpayable-bline_date = wa_data-zfbdt. " 基准日期
accountpayable-alloc_nmbr = '310100'. " 分配
accountpayable-item_text = it_bseg-sgtxt. " 项目文本
append accountpayable.
" fill currency item in each loop of it_bseg
clear currencyamount.
currencyamount-itemno_acc = index. " 行项目编号
currencyamount-currency = 'CNY'. " 货币
currencyamount-amt_doccur = it_bseg-wrbtr * flag2 .
currencyamount-disc_base = currencyamount-amt_doccur.
append currencyamount.
endif.
index = index + 1.
endloop.
endif.
call function 'BAPI_ACC_DOCUMENT_CHECK'
exporting
documentheader = documentheader
CUSTOMERCPD =
CONTRACTHEADER =
tables
accountgl = accountgl
ACCOUNTRECEIVABLE =
accountpayable = accountpayable
ACCOUNTTAX =
currencyamount = currencyamount
CRITERIA =
VALUEFIELD =
EXTENSION1 =
return = return
PAYMENTCARD =
CONTRACTITEM =
EXTENSION2 =
REALESTATE =
.
call function 'BAPI_ACC_DOCUMENT_REV_POST'
exporting
reversal =
bus_act =
tables
return =
.
loop at return.
if return-type = 'E' or return-type = 'A'.
bapiflag = 'E'.
endif.
write:/ return-message.
endloop.
refresh return.
if bapiflag <> 'E'.
call function 'BAPI_ACC_DOCUMENT_POST'
exporting
documentheader = documentheader
importing
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
tables
accountgl = accountgl
accountpayable = accountpayable
currencyamount = currencyamount
return = return.
loop at return.
if return-type = 'E' or return-type = 'A'.
bapiflag = 'E'.
endif.
write:/ return-message.
endloop.
refresh return.
endif.
if bapiflag <> 'E'.
call function 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
importing
return = return.
.
loop at return.
if return-type = 'E' or return-type = 'A'.
bapiflag = 'E'.
endif.
write:/ return-message.
endloop.
refresh return.
if bapiflag <> 'E'.
wa_data-belnr2 = obj_key(10) .
modify it_data from wa_data.
endif.
endif.
refresh: accountgl, accountpayable, currencyamount .
clear: documentheader, obj_key.
clear bapiflag.
endloop.
endform. "main_bapi