Vous êtes sur la page 1sur 9

*&---------------------------------------------------------------------*

*& Report ZF_BAPI_EXTERNAL_TAX_POST


*&
*&---------------------------------------------------------------------*
*& Original only in EB5/000
*&
*& Only Original is attached to the notes 626235 and 1241247
*&---------------------------------------------------------------------*
REPORT zf_bapi_external_tax_post.
* based on note 626235 and 1241247
*----------------------------------------------------------------------------
* BAPI_ACC_DOCUMENT_POST / CHECK
* Special case for BAPIs BAPI_ACC_DOCUMENT_POST / CHECK:
* field AccountTax-Stat_Con does not exist as this feature is derived internally
*----------------------------------------------------------------------
** sample posting in system P7D/000
** FB01: US01/1700000005/2009 calculate tax on
** FB01: US01/1700000050/2009 manuel tax on detail screen
** Bukrs US01 with Vertex and ttxd-txit = X (taxes line-by-line)
**---------------------------------------------------------------------
* in EB5 client 003 and company code DG01 is used

* fitting for BAPI_ACC_DOCUMENT_POST


DATA: ap TYPE TABLE OF bapiacap09 WITH HEADER LINE,
documentheader TYPE bapiache09,
currencyamount TYPE TABLE OF bapiaccr09 WITH HEADER LINE,
accountgl TYPE TABLE OF bapiacgl09 WITH HEADER LINE,
accounttax TYPE TABLE OF bapiactx09 WITH HEADER LINE,
ret TYPE TABLE OF bapiret2 WITH HEADER LINE,
wa_return2 TYPE bapiret2,
sign TYPE i.

FIELD-SYMBOLS: <bapiret2> TYPE bapiret2.

PARAMETER: bypasson DEFAULT space,


credmemo DEFAULT space.

sign = 1.
IF NOT credmemo IS INITIAL.
sign = -1.
ENDIF.

* bypasson = 'X' -> tax bypass is on


* This parameter determines whether the so-called 'tax bypass' is on or not.
* If the bypass is on the tax data are trusted data and only some consistency
* checks are performed.
* If the bypass is off it is tried to recalculate the tax data and to enhance
* and complete the tax data with the results of the recalculation.
* During the recalculation the same standard function modules
* 'CALCULATE_TAX_DOCUMENT' and 'CREATE_BSET_ITEM' are processed as in the
accounting
* transactions as well (FB01, FB60).
* But in most cases the results can't be much better than the input data.
* Therefore it must be the decided aim to provide the best and complete input data
* that is possible. For each business case it must be checked that the resulting
* posted accounting document (tables BSEG and BSET) looks as desired.
*
* The determination whether the tax bypass is on or off can be found in function
module
* FI_TAX_CALCULATION. The result depends on
* - reference procedure (BKPF-AWTYP)
* - reference transaction (BKPF-GLVOR)
* - transaction code
* There is a system table TAX_APPLI where SAP entered the combinations
* of reference procedures, reference transactions and transactions
* for which the bypass is on. This means that for a combination that is
* not listed in TAX_APPLI the tax bypass is off.
* Note also that for ALE processes the bypass is always on, and in addition,
* is even modified in that way that NO CHECKS AT ALL are performed.
*
* Performance aspects:
* If the performance of the entire posting process is a crucial aspect SAP
recommends
* to enter the used reference procedure (AWTYP) into table TAX_APPLI.
* This speeds up enormously the posting process as no lengthy and nevertheless
* uncertain recalculation is tried. But this clearly requires that the data
* that are passed to BAPI are as complete and correct as possible.
*------------------------------------------------------------------------------
* The aim of this example report is to show in detail how to feed correctly
* the BAPI 'BAPI_ACC_DOCUMENT_POST'.
*
* If you set up in tr. OBCO for your calculation procedure (TAXUSX mostly)
* that taxes are to be determined line-by-line (table TTXD, field XTXIT = X)
* then a specific line reference has to be established between the gl-item
* and its corresponding tax items. This is done via the field ITEMNO_TAX.
* It is crucial that the correct logic is applied here !
* This logic had to be changed once by note 1692637 and 1790294.
* Please apply them if they are still missing.
* Please read carefully note 1730413 to understand the new logic.
*
*----------------------------------------------------------------------------
* FB03: posted with BAPI (bypass on)
* Doc.Type : KA ( Vendor document ) Normal document
* Doc. Number 1700000052 Company code US01 Fiscal year
* Doc. date 17.02.2009 Posting date 17.02.2009 Period
* Calculate Tax
* Doc.currency USD
*
* Itm PK Account Account short text Assignment Tx Amount
* 1 31 VENDOR VENDOR U1 100,00-
* 2 40 510020 Consumption - Fin. G US01 U1 109,00
* 3 50 216100 US Sales Tax State U1 6,00-
* 4 50 216110 US Sales Tax Cty U1 2,00-
* 5 50 216130 Tax Accrual Other U1 1,00-
*------------------------------------------------------------------------------
*Table BSEG contains the document data:
* BUZEI BUZID BSCHL SHKZG MWSKZ DMBTR HWBAS TXGRP KTOSL
* 001 31 H U1 100,00 0,00 000
* 002 40 S U1 109,00 0,00 002
* 003 T 50 H U1 6,00 100,00 002 MW1
* 004 T 50 H U1 2,00 100,00 002 MW2
* 005 T 50 H U1 1,00 100,00 002 MW4
**------------------------------------------------------------------------------
*Table BSET contains the tax data for the ERP system:
* BUZEI MWSKZ HKONT SHKZG HWBAS HWSTE KSCHL KBETR TXJLV TAXPS
* 001 U1 S 100,00 6,00 XP1I 60,00 1 000002
* 002 U1 S 100,00 2,00 XP2I 12,50 2 000002
* 003 U1 S 100,00 0,00 XP3I 0,00 3 000002
* 004 U1 S 100,00 1,00 XP4I 10,00 4 000002
* 005 U1 S 100,00 0,00 XP5I 0,00 5 000002
* 006 U1 S 100,00 0,00 XP6I 0,00 6 000002
* 007 U1 0000216100 H 100,00- 6,00 XP1U 60,00 1 000002
* 008 U1 0000216110 H 100,00- 2,00 XP2U 12,50 2 000002
* 009 U1 0000216120 H 100,00- 0,00 XP3U 0,00 3 000002
* 010 U1 0000216130 H 100,00- 1,00 XP4U 10,00 4 000002
* 011 U1 0000216130 H 100,00- 0,00 XP5U 0,00 5 000002
* 012 U1 0000216130 H 100,00- 0,00 XP6U 0,00 6 000002
*
*----------------------------------------------------------------------------------
-
*Tables ETXDCH, ETXDCI and ETXDCJ contain a copy of the data
* sent to the external system
*----------------------------------------------------------------------------------
-
* document where bypass was off: US01/1700000053/2009
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++
IF NOT bypasson IS INITIAL.
documentheader-obj_type = 'IDOC'. "= AWTYP -> tax bypass on if obj_type = 'IDOC'
documentheader-bus_act = 'RFBU'. "= GLVOR
documentheader-obj_key = 'doc-001'. "awref
documentheader-obj_key+10 = 'DG012011'. "aworg
documentheader-obj_sys = 'local'.
ELSE.
* if no obj-type is set then 'BKPFF' is defaulted
* if no glvor is set then 'RFBU' is defaulted
ENDIF.

documentheader-username = sy-uname.
documentheader-pstng_date = sy-datum.
documentheader-doc_date = sy-datum.
documentheader-comp_code = 'DG01'. "'US01'.
documentheader-doc_type = 'KA'.
*---------------------------------------------------
* vendor line item
ap-itemno_acc = '10'.
ap-vendor_no = 'VENDOR'.
APPEND ap.
currencyamount-itemno_acc = '10'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = -100 * sign.
APPEND currencyamount.
CLEAR currencyamount.
*---------------------------------------------------
* gl-line expense item
accountgl-itemno_acc = '20'.
*accountgl-itm_number = '002'. "before note 1692637
*accountgl-itm_number = '001'. "after note 1692637

* if itemno_tax available use it instead of itm_number


accountgl-itm_number = '000'.
*accountgl-itemno_tax = '002'. "before note 1692637
accountgl-itemno_tax = '001'. "after note 1692637

accountgl-gl_account = '0000400000'. "'0000510020'.


accountgl-tax_code = 'U1'.
accountgl-taxjurcode = '0508525201'.
accountgl-costcenter = '0000000001'. "'US01'.
accountgl-bus_area = '0001'.
currencyamount-itemno_acc = '20'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = 109 * sign.
*currencyamount-amt_doccur = '108.25'. "would be correct
APPEND accountgl.
APPEND currencyamount.
*-----------------------------------------------------
*NVV tax line items (Non deductible tax)
CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '30'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'NVV'.
accounttax-cond_key = 'XP1I'.
accounttax-tax_rate = '6.00'.
accounttax-taxjurcode = '0500000000'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '1'.
*----------------------------------------------------
* establish reference of tax item to corresponding gl-item
* via the same value in field accountgl-itemno_tax
* (or accountgl-itm_number)
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
*----------------------------------------------------
*accounttax-stat_con = 'X'.
currencyamount-itemno_acc = '30'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = 6 * sign.
currencyamount-amt_base = 100 * sign.
APPEND accounttax.
APPEND currencyamount.

CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '40'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'NVV'.
accounttax-cond_key = 'XP2I'.
accounttax-tax_rate = '1.25'.
accounttax-taxjurcode = '0508500000'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '2'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
* accounttax-stat_con = 'X'.
currencyamount-itemno_acc = '40'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = 2 * sign.
*currencyamount-amt_doccur = '1.25'. "Would be correct
currencyamount-amt_base = 100 * sign.
APPEND accounttax.
APPEND currencyamount.
CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '50'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'NVV'.
accounttax-cond_key = 'XP3I'.
accounttax-tax_rate = '0.00'.
accounttax-taxjurcode = '0508525200'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '3'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
* accounttax-stat_con = 'X'.
currencyamount-itemno_acc = '50'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = 0 * sign.
currencyamount-amt_base = 100 * sign.
APPEND accounttax.
APPEND currencyamount.

CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '60'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'NVV'.
accounttax-cond_key = 'XP4I'.
accounttax-tax_rate = '1.00'.
accounttax-taxjurcode = '0508525201'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '4'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
* accounttax-stat_con = 'X'.
currencyamount-itemno_acc = '60'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = 1 * sign.
currencyamount-amt_base = 100 * sign.
APPEND accounttax.
APPEND currencyamount.

CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '70'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'NVV'.
accounttax-cond_key = 'XP5I'.
accounttax-tax_rate = '0.00'.
accounttax-taxjurcode = '0508525201'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '5'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
* accounttax-stat_con = 'X'.
currencyamount-itemno_acc = '70'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = 0 * sign.
currencyamount-amt_base = 100 * sign.
APPEND accounttax.
APPEND currencyamount.

CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '80'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'NVV'.
accounttax-cond_key = 'XP6I'.
accounttax-tax_rate = '0.00'.
accounttax-taxjurcode = '0508525201'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '6'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
* accounttax-stat_con = 'X'.
currencyamount-itemno_acc = '80'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = 0 * sign.
currencyamount-amt_base = 100 * sign.
APPEND accounttax.
APPEND currencyamount.
*-----------------------------------------------------
* Output tax (self assessed)
CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '90'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'MW1'.
accounttax-cond_key = 'XP1U'.
accounttax-tax_rate = '6.00-'.
accounttax-taxjurcode = '0500000000'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '1'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
currencyamount-itemno_acc = '90'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = -6 * sign.
currencyamount-amt_base = -100 * sign.
APPEND accounttax.
APPEND currencyamount.

CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '100'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'MW2'.
accounttax-cond_key = 'XP2U'.
accounttax-tax_rate = '1.25-'.
accounttax-taxjurcode = '0508500000'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '2'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
currencyamount-itemno_acc = '100'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = -2 * sign.
*currencyamount-amt_doccur = '1.25'. "Would be correct
currencyamount-amt_base = -100 * sign.
APPEND accounttax.
APPEND currencyamount.

CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '110'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'MW3'.
accounttax-cond_key = 'XP3U'.
accounttax-tax_rate = '0.00-'.
accounttax-taxjurcode = '0508525200'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '3'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
currencyamount-itemno_acc = '110'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = -0 * sign.
currencyamount-amt_base = -100 * sign.
APPEND accounttax.
APPEND currencyamount.

CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '120'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'MW4'.
accounttax-cond_key = 'XP4U'.
accounttax-tax_rate = '1.00-'.
accounttax-taxjurcode = '0508525201'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '4'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
currencyamount-itemno_acc = '120'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = -1 * sign.
currencyamount-amt_base = -100 * sign.
APPEND accounttax.
APPEND currencyamount.

CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '130'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'MW4'.
accounttax-cond_key = 'XP5U'.
accounttax-tax_rate = '0.00-'.
accounttax-taxjurcode = '0508525201'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '5'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
currencyamount-itemno_acc = '130'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = -0 * sign.
currencyamount-amt_base = -100 * sign.
APPEND accounttax.
APPEND currencyamount.

CLEAR accounttax.
CLEAR currencyamount.
accounttax-itemno_acc = '140'.
accounttax-tax_code = 'U1'.
accounttax-acct_key = 'MW4'.
accounttax-cond_key = 'XP6U'.
accounttax-tax_rate = '0.00-'.
accounttax-taxjurcode = '0508525201'.
accounttax-taxjurcode_deep = '0508525201'.
accounttax-taxjurcode_level = '6'.
accounttax-itemno_tax = '002'. "before note 1692637
accounttax-itemno_tax = '001'. "after note 1692637
currencyamount-itemno_acc = '140'.
currencyamount-curr_type = '00'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = -0 * sign.
currencyamount-amt_base = -100 * sign.
APPEND accounttax.
APPEND currencyamount.

*-----------------------------------------------------------------
CLEAR accounttax.
CLEAR currencyamount.

CALL FUNCTION 'EXTERNAL_TAX_DOC_START_PRICING'


EXPORTING
* I_NO_UPD = ' '
* I_BELNR = ' '
i_refresh_complete = 'X'.
.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'


EXPORTING
documentheader = documentheader
TABLES
accountpayable = ap
accountgl = accountgl
accounttax = accounttax
currencyamount = currencyamount
return = ret.

LOOP AT ret ASSIGNING <bapiret2>.


WRITE: /
<bapiret2>-id,
<bapiret2>-number,
<bapiret2>-message,
<bapiret2>-message_v1,
<bapiret2>-message_v2,
<bapiret2>-message_v3,
<bapiret2>-message_v4.
ENDLOOP.

COMMIT WORK.

Vous aimerez peut-être aussi