07-01-2010 8:13 PM
Hi Friends,
Thanks in Advance.
Req : I want to post A/C Documents from Excel file to SAP, like how the user does using F-02 / F-90 ( Standard Transactions )
Here iam using the BAPI BAPI_ACC_DOC_POST, where i cant able to post, getting error in Assets.
Can any body help in this regard.
Regards:
Sridhar.J
07-02-2010 10:42 AM
Hi,
I did this long time before and probably this sample code can help
DATA: l_documentheader TYPE bapiache09,
lt_accountgl TYPE TABLE OF bapiacgl09 WITH HEADER LINE,
lt_accountreceivable TYPE TABLE OF bapiacar09 WITH HEADER LINE,
lt_accounttax TYPE TABLE OF bapiactx09 WITH HEADER LINE,
lt_currencyamount TYPE TABLE OF bapiaccr09 WITH HEADER LINE,
lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE,
l_acc(11) TYPE n,
l_amt(11) TYPE n,
l_tot_exvat_pos LIKE g_total_order_exvat,
l_total_vat_pos LIKE g_total_order_exvat,
l_total_cost_pos LIKE g_total_order_exvat,
l_total_ord_pos LIKE g_total_order_exvat.
REFRESH: lt_accountgl, lt_currencyamount, lt_return,
lt_accountreceivable, lt_accounttax.
CLEAR: lt_accountgl, lt_currencyamount, lt_return, l_documentheader,
lt_accountreceivable, lt_accounttax,
l_tot_exvat_pos, l_total_vat_pos,
l_total_cost_pos,l_total_ord_pos.
... build --> l_documentheader
MOVE c_bus_act TO l_documentheader-bus_act.
MOVE v_username TO l_documentheader-username.
MOVE g_vbak-bukrs_vf TO l_documentheader-comp_code.
MOVE sy-datum TO l_documentheader-doc_date.
MOVE sy-datum TO l_documentheader-pstng_date.
MOVE sy-datum TO l_documentheader-trans_date.
MOVE g_fiscal_year TO l_documentheader-fisc_year.
MOVE g_fiscal_period TO l_documentheader-fis_period.
MOVE v_doc_type TO l_documentheader-doc_type.
MOVE g_rtsorder TO l_documentheader-ref_doc_no.
... build --> lt_accountgl
. debit .
MOVE 2 TO l_acc.
MOVE l_acc TO lt_accountgl-itemno_acc.
MOVE gl_saleret TO lt_accountgl-gl_account.
MOVE v_item_text TO lt_accountgl-item_text.
MOVE v_tax_code TO lt_accountgl-tax_code.
MOVE v_profit_centre TO lt_accountgl-profit_ctr.
MOVE c_saleret_cond TO lt_accountgl-cond_type.
APPEND lt_accountgl.
. add FOC/Stock line
CLEAR lt_accountgl.
ADD 1 TO l_acc.
MOVE l_acc TO lt_accountgl-itemno_acc.
. Stock
MOVE gl_stock TO lt_accountgl-gl_account.
MOVE v_item_text TO lt_accountgl-item_text.
MOVE v_profit_centre2 TO lt_accountgl-profit_ctr.
APPEND lt_accountgl.
. COGS
CLEAR lt_accountgl.
ADD 1 TO l_acc.
MOVE l_acc TO lt_accountgl-itemno_acc.
MOVE gl_cogs TO lt_accountgl-gl_account.
MOVE v_item_text TO lt_accountgl-item_text.
MOVE v_cost_center TO lt_accountgl-costcenter.
APPEND lt_accountgl.
CLEAR lt_accountgl.
... build --> lt_accountreceivable
Do not create entry if the outstanding balance is zero...
MOVE 1 TO l_acc.
MOVE l_acc TO lt_accountreceivable-itemno_acc.
MOVE g_vbpa-kunnr TO lt_accountreceivable-customer.
APPEND lt_accountreceivable.
CLEAR lt_accountreceivable.
... build --> lt_accounttax
MOVE 5 TO l_acc.
MOVE l_acc TO lt_accounttax-itemno_acc.
MOVE gl_vat TO lt_accounttax-gl_account.
MOVE c_vat_cond TO lt_accounttax-cond_key.
MOVE c_vat_acct TO lt_accounttax-acct_key.
MOVE v_tax_code TO lt_accounttax-tax_code.
MOVE 2 TO l_acc.
MOVE l_acc TO lt_accounttax-itemno_tax.
APPEND lt_accounttax.
CLEAR lt_accounttax.
... build --> lt_currencyamount
get negative values for posting
l_tot_exvat_pos = g_total_order_exvat * -1.
l_total_cost_pos = g_total_cost * -1.
l_total_vat_pos = g_total_vat * -1.
l_total_ord_pos = g_total_order * -1.
. customer
Do not create entry if the outstanding balance is zero...
MOVE 1 TO l_amt.
MOVE l_amt TO lt_currencyamount-itemno_acc.
MOVE g_vbak-stwae TO lt_currencyamount-currency.
MOVE l_total_ord_pos TO lt_currencyamount-amt_doccur.
MOVE l_total_ord_pos TO lt_currencyamount-amt_base.
MOVE l_total_ord_pos TO lt_currencyamount-disc_base.
APPEND lt_currencyamount.
CLEAR lt_currencyamount.
. sales return line
ADD 1 TO l_amt.
MOVE l_amt TO lt_currencyamount-itemno_acc.
MOVE g_vbak-stwae TO lt_currencyamount-currency.
MOVE g_total_order_exvat TO lt_currencyamount-amt_doccur.
MOVE g_total_order_exvat TO lt_currencyamount-amt_base.
MOVE g_total_order_exvat TO lt_currencyamount-disc_base.
APPEND lt_currencyamount.
CLEAR lt_currencyamount.
. FOC or Stock
ADD 1 TO l_amt.
MOVE l_amt TO lt_currencyamount-itemno_acc.
MOVE g_vbak-stwae TO lt_currencyamount-currency.
MOVE g_total_cost TO lt_currencyamount-amt_doccur.
MOVE g_total_cost TO lt_currencyamount-amt_base.
MOVE g_total_cost TO lt_currencyamount-disc_base.
APPEND lt_currencyamount.
CLEAR lt_currencyamount.
. COGS
ADD 1 TO l_amt.
MOVE l_amt TO lt_currencyamount-itemno_acc.
MOVE g_vbak-stwae TO lt_currencyamount-currency.
MOVE l_total_cost_pos TO lt_currencyamount-amt_doccur.
MOVE l_total_cost_pos TO lt_currencyamount-amt_base.
MOVE l_total_cost_pos TO lt_currencyamount-disc_base.
APPEND lt_currencyamount.
CLEAR lt_currencyamount.
ADD 1 TO l_amt.
MOVE l_amt TO lt_currencyamount-itemno_acc.
MOVE g_vbak-stwae TO lt_currencyamount-currency.
MOVE g_total_vat TO lt_currencyamount-amt_doccur.
MOVE g_total_order_exvat TO lt_currencyamount-amt_base.
MOVE g_total_vat TO lt_currencyamount-disc_base.
APPEND lt_currencyamount.
CLEAR lt_currencyamount.
... call BAPI
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = l_documentheader
TABLES
accountgl = lt_accountgl
accountreceivable = lt_accountreceivable
accounttax = lt_accounttax
currencyamount = lt_currencyamount
return = lt_return.
... handle errors / commit
READ TABLE lt_return WITH KEY type = c_type_e.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
MESSAGE text-009 TYPE c_type_e RAISING error_posting_ref.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
MESSAGE s286(zc).
ENDIF.
Cheers,
Pramod
09-16-2010 4:07 PM