Você está na página 1de 26

Tax Code - Pgina : 1

Estrutura do Tax Code Muito foi mexido na estrutura original dos tax codes para permitir o desenvolvimento do sistema de localizao para o Brasil. Algumas funcionalidades Standard foram alteradas e outras extendidas. Como exemplo de funcionalidades alteradas temos o valor da Taxa-de-Imposto que no Standard, aceita que se digite diretamente o percentual de imposto, ao passo que para o Brasil, s aceita os valores 100 e -100, indicando que esta linha de configurao do Tax Code est ativa. Com relao as extenses, o R/3 permite a customizao do sistema para que a rotina de clculo dos impostos seja feita externamente ao sistema, sendo exatamente o que ocorre com a localizao Brasil, por exemplo, a rotina original que considerava apenas o Vendor para determinao correta dos impostos, agora considera Vendor, ship-from, ship-to, uso do material, etc substituindo as frmulas originais para tratamento dos impostos pelas Frmulas de Condio que so nada mais do que programas chamados pelo sistema, que executam algumas operaes internas e retornam os parmetros j calculados para o R/3. Condition Formulas 301 IPI for the industrialization case (301 + 302 may occur together) 302 IPI for the consumption case (301 + 302 may occur together) 303 ICMS for all cases 304 Substituicao Tributaria 305 ICMS complement (in MM) and ICMS Zona Franca discount (in SD) 306 ISS (only calculated in SD) 307 ICMS Sub.Trib. on freight offset 308 not used 309 Zero value Embora possa-se configurar diferentes valores e formas de clculo diretamente nas customizaes de tax codes, as Frmulas de Condio aliadas s rotinas de clculo de impostos ( ambas em ABAP/4 ) tm prioridade na utilizao dos mesmos, ou seja, a customizao, juntamente com os dados da compra da mercadoria, simplesmente oferecem as informaes s frmulas e programas e so estes que decidem como estas informaes sero processadas. Veja por exemplo, na configurao do Tax Code C3, que embora as linhas de complemento de ICMS estivessem ativas, as mesmas no foram calculadas na emisso do pedido; isto porque a Frmula de Condio ( 305 no caso ) analisou as condies de material, ship-from, ship-to, entre outras e decidiu que esta linha deveria ter valor zero.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 2

Na configurao de Tax Code ( C3 )


CgImposto ICMS Ind.Clear.Off. Nvel 300 IPI consumo entr. ICMS ativo fixo entr ICMS consumo entr. Sub.Tr.consumo entr. ICMS complemento ICMS complemento 100 Nvel 500 IPI do SD sada ICMS do SD sada ChCta ICC NVV VS2 NVV NVV ICP ICX MW1 MW2 Taxa-de-imposto Nvel 275 300 310 315 330 340 350 360 500 510 520 De-nvel 230 0 100 100 100 100 100 350 0 100 100 TpCondi IC1O IPI2 ZCM2 ICM2 ICS2 ICOP ICOX IPI3 ICM3

100,000 100,000 100,000 100,000-

No detalhe do Pedido
TipC Denominao Montante Moeda BASB Montante base Clculo ext. 15,00 BRL Nvel 200 15,00 BRL Nvel 300 15,00 BRL IPI2 IPI consumo entr. 12,000 % ICM2 ICMS consumo entr. 21,000 % ICOP ICMS complemento 100,000 % ICOX ICMS complemento 100 100,000-% Nvel 500 21,97 BRL Outros impostos 21,97 BRL Valor condio BRL 150,00 150,00 150,00 150,00 23,54 46,13 0,00 0,00 219,67 219,67

Estrutura de Funcionamento Na tela de Registros de Tipos de Condio ( transao OBQ1 ), pode-se definir as diferentes condies que faro parte do clculo dos impostos. O campo Sequencia de Acesso define como este registro ser tratado, ou seja: Em branco : levado em conta no clculo dos montantes independentemente do tax code e das frmulas de condies. Ex.: BASB Preo Base MWST : estar sujeito as configuraes de impostos bem como as decises tomadas pelas frmulas. Ex. ICM1 A rotina de impostos, baseada no Esquema de Clculo ( TAXBRJ ), comear ento a analisar os impostoss na seguinte forma: Leitura das condies ativas definidas pelo tax code; Para cada linha ativa, analisa o Preo do Item, Produto, Estado de Origem, Estado de Destino, Pas de Orgem, Sujeio a Substituio Tributria ou no, Condies de Venda da mercadoria ( Exemplo: Consignao ), Informaes do Tax Code ( 100, 100- e Frmulas de Condies definidas ), e demais customizaes dos impostos ( Ex.: Alquotas) e decide se haver incidncia do imposto para esta condio ou no. Caso haja, so checados ento as configuraes contbeis para lanamento dos impostos.
Marcos Roberto Pinotti

SAP Brasil - Fone: (011) 5503-2400

Tax Code - Pgina : 3

Observaes: O sistema Standard vem hoje com uma srie de opes de impostos que tem seus valores definidos segundo uma srie de informaes (Preo do Item, Produto, Estado de Origem, Estado de Destino, Pas de Orgem, Sujeio a Substituio Tributria ou no, Condies de Venda da mercadoria (Exemplo: Consignao), Informaes do Tax Code ( 100, 100- e Frmulas de Condies definidas )). Quaisquer condies diferentes das apresentadas pelo sistema standard ( ICM1, IPI1, STFR, ICS1) podem incorrer em erros, principalmente com relao a parte fiscal, sendo que sua utilizao deve ser feita de forma extremamente criteriosa. Fica como sujesto, quando da ocorrncia de situaes onde seja necessrio criar um novo tax code especfico, que seja feito um estudo das caractersticas de cada uma das conditions type e se existe alguma maneira de enganar o sistema Genricos Caso seja necessrio adicionar novas funcionalidades ao sistema, pode-se alterar a estrutura das frmulas, que nada mais so do que pequenos programas feitos em ABAP/4. Nossa sugesto de que sejam criadas novas frmulas em substituio das originais. As frmulas na verdade servem apenas para definir algumas variveis para o sistema principal, como valores dos impostos, valor base e percentuais. Para editar uma frmula: IMG >> Contab.financeira >> Opes bsicas contab.financeira >> IVA >> Configurao >> Verificar esquemas de clculo >> Esquemas >> Seleciona o TAXBRJ >> Controle >> Seleciona a Frmula desejada >> F4 >> Seleciona a frmula desejada >> Texto de Origem. Obs.: Para que esta operao funcione, necessrio que se tenha acesso a edio de programas, ou seja, senha de desenvolvedor. Programas e funes envolvidas com Impostos: SAPLJ1BR Impostos: clc.externo imposto SAPLF80T Atualizao de tabelas de imposto SAPLTAX1 Impostos SAPLTAX2 Repartio de impostos SAPLFYTX Interface de sistemas fiscais externos J_1BDETERMINE_JURISDICTION J_1BCALCULATE_TAXES ** **

** Estas funes podem ser definidas pelo path : IMG >> Contab.financeira >> Opes bsicas contab.financeira >> IVA >> Configurao >> Clculo de impostos externo >> Definir destino lgico Ou ainda podem ser visualizadas via transao SE37. Os programas SAPLF80T, SAPLTAX1, SAPLTAX2, SAPLFYTX no sero apresentados em detalhe neste relatrio uma vez que so programas auxiliares, com funces pouco relevantes, neste momento, para determinao de possveis novas funcionalidades.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 4

______________________________________________________________________

Programas

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 5

SAPLJ1BR Impostos: clc.externo imposto Este o principal programa utilizado para determinao das taxas e impostos para a Localizao Brasil. Nele so analizadas as informaes do processo ( no caso de compras, material, ship-from, ship-to, usage ) e determinadas os valores corretos. Em seu processamento, esta rotina executa as seguintes checagens: Existncia excluso de base de ICMS Taxas Ativas Uso do material : 1=industrialization 2=consumption Processamento de Frete Movimento de entrada ou sada Aplicao das taxas Existncia de IPI Split para fornecedor no industrial Sujeio de Customer a IPI / ICMS / Sub. Trib. Active taxes(1): IPI / ICMS / Sub.Trib Active taxes(2): Complement of ICMS / ISS Percentual de IPI pelo NBM-code, valor base, excesso e direito tributrio Se no encontrado, pega o default Acesso ao ICMS pelo country, state+from, state+to, material Se encontrado, pega : rate / valor base, excesso e direito tributrio Se no encontrado, pega o default Comp.ICMS required in MM for state+to Comp.ICMS exception rules found: pega base e exemption Se no encontrado, pega o default Comp.ICMS finalmente determinado Regras para Sub.Trib Ou pega o default ( 0 ) ou faz clculo em cima dos dados encontrados Regras para percentual ISS encontrada para o material, pega o percentual Se no, pega o default do sistema ( sem ISS ) Preenchimento do ICMS e IPI nos registros ativos ('X' = YES) Sub.Trib.ICMS encontrado, determina taxa e base Checa se um processo de Retorno de MM, ou retorno de Invoice Se Conhecimento: Determina os novos Vendor e Jurisdiction ( estado ) Se IPI Pauta, determina: amount / no unit / uom ( unidade de medida ) / direito tributrio IPI Pauta por unidade de preo Checa se existe condio de modificao para Sub.Trib. Determina o montante modificado do Sub.Trib. utilizando calc type / preo / fator / unidade Determina surcharge / reduo de base 1 / reduo de base 2 / ICMS com base reduzida
SAP Brasil - Fone: (011) 5503-2400 Marcos Roberto Pinotti

Tax Code - Pgina : 6

Se condio de Sub.Trib. sobre frete for encontrada Calcula o montante base OBS.: O roteiro acima extremamente sinttico, porm serve para dar uma noo dos assuntos tratados por este programa. Quaisquer informaes mais a fundo, necessitaram da ajuda da equipe de programao para anlise detalhada do programa.

J_1BDETERMINE_JURISDICTION
FUNCTION J_1BDETERMINE_JURISDICTION REFRESH LOCATION_RESULTS. IF LOCATION_DATA-STATE NE SPACE. SELECT * FROM J_1BTREGX WHERE LAND1 = LOCATION_DATA-COUNTRY AND BLAND = LOCATION_DATA-STATE. LOCATION_RESULTS = LOCATION_DATA. LOCATION_RESULTS-STATE = J_1BTREGX-TXREG. LOCATION_RESULTS-TXJCD = J_1BTREGX-TXREG. APPEND LOCATION_RESULTS. ENDSELECT. ENDIF. CLEAR LOCATION_ERR. ENDFUNCTION.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 7

J_1BCALCULATE_TAXES Obs.: Este funo controla engloba grande parte da rotina de localizao Brasil, e pelo fato de a mesma ser muito extensa, foi anexado neste documento apenas a parte da documentao da mesma.
*"---------------------------------------------------------------------*"*"Local interface: *" IMPORTING *" VALUE(TAX_DATA) LIKE COM_TAX STRUCTURE COM_TAX *" VALUE(ADD_DATA) LIKE J_1BTXCALC STRUCTURE J_1BTXCALC *" OPTIONAL *" EXPORTING *" VALUE(TAX_ERR) LIKE COM_ERR STRUCTURE COM_ERR *" VALUE(TAX_RESULT) LIKE COM_TAX STRUCTURE COM_TAX *" VALUE(ADD_RESULT) LIKE J_1BTXCALC *" STRUCTURE J_1BTXCALC *"---------------------------------------------------------------------*----------------------------------------------------------------------* * * This function can be called in two ways: * * - Via the external tax interface (FV64A300). In this case the * parameters are TAX_DATA, TAX_ERR and TAX_RESULT. Additional * information about the calculated values is exported via * the tables 'NF_VALUES' and 'NF_LAWS'. * * - Via a special formula exit in SD to calculate the taxes * ICMS and ISS based on a net amount as input data. In this * case the parameters are TAX_DATA, TAX_ERR, TAX_RESULT, * ADD_DATA and ADD_RESULT. * * In this special case only the tax values for ICMS and ISS * are returned to the calling exit. Tables NF_VALUES and NF_LAWS * are not changed. The output values are transferred via the * export parameter 'ADD_RESULT'. * * In this special calling case it is possible to do the calculation * of ICMS based on the price per unit and not on the total. * A restriction then is that this calculation does NOT support * any NF discounts and the base must not include ICMS * * * Expected input values: * * - If the function is called from MM or the function is called * from SD with 'ADD_DATA-ONLY_TAX' = 'X' the calculation expects * the amount not including any taxes. * * - If the function is called from SD with the special parameter * in 'ADD_DATA' the calculation expects the amount including * ICMS and ISS (depending on the setting in 'ADD_DATA' * *----------------------------------------------------------------------*

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 8

______________________________________________________________________

Frmulas

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 9

300

Data for the communication to an external tax system

*---------------------------------------------------------------------* * FORM FRM_KONDI_WERT_300 * *---------------------------------------------------------------------* *********************************************************************** ******************* SAP - Sales Tax Interface ************************* *********************************************************************** * Collection of the required data for the communication to * * an external tax system (calculation module). The data is * * collected int an internal communication structure and passed * * over to a function module 'RFC_CALCULATE_TAXES' or the * * corresponding entry in TTXC * *---------------------------------------------------------------------* FORM FRM_KONDI_WERT_300. ********************************************************************** * Data definitions and tables * ********************************************************************** * TABLES: TTX_TAXES, * LFA1, * T007A, * TFDIR, * TTXC. TABLES: TTXP, COM_TAX, COM_ERR. DATA: DATA: BEGIN OF XXKOMV OCCURS 10. INCLUDE STRUCTURE KOMV_INDEX. END OF XXKOMV. "transfer structure "vendor master - global data "valid tax indicators "function modules

* begin of change J1B_0014 (Brazil localization) DATA: BR_KONP LIKE KONP OCCURS 10 WITH HEADER LINE. * end of change J1B_0014 (Brazil localization) DATA: MWSKZ LIKE KOMP-MWSKZ, PLANT LIKE T001W-WERKS, PERCENTAGE LIKE KOMV-KBETR, SAVE_XKOMV LIKE KOMV_INDEX, SAVE_COM_TAX LIKE COM_TAX, POSNR LIKE KOMP-KPOSN, EXEMPT_FLAG, COPY_FLAG, COUNTER TYPE I, AMOUNT TYPE P, QUANTITY TYPE P. "Steuerkennzeichen "Werk

* Macros for default handling DEFINE ASSIGN/DEFAULT. IF &2 IS INITIAL. COM_TAX-&1 = &3. ELSE. COM_TAX-&1 = &2. ENDIF. END-OF-DEFINITION. DEFINE DEFAULT_ON_INITIAL. IF COM_TAX-&1 IS INITIAL OR COM_TAX-&1 = SPACE. COM_TAX-&1 = &2. ENDIF. END-OF-DEFINITION.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 10

* Avoid recalculation on pricing type 'E' * CHECK: PREISFINDUNGSART <> 'E' AND * KONV-KSTEU <> 'E'. * Clear global workfields CLEAR: TAXPCT0, TAXAMT0, TAXPCT1, TAXAMT1, TAXPCT2, TAXAMT2, TAXPCT3, TAXAMT3, TAXPCT4, TAXAMT4, TAXPCT5, TAXAMT5, TAXPCT6, TAXAMT6, TAXPCT7, TAXAMT7, TAXPCT8, TAXAMT8, TAXPCT9, TAXAMT9, COM_TAX, COM_ERR, TTX_TAXES. TAXBAS0, TAXBAS1, TAXBAS2, TAXBAS3, TAXBAS4, TAXBAS5, TAXBAS6, TAXBAS7, TAXBAS8, TAXBAS9,

CHECK KOMK-TRTYP NE 'A' AND XKOMV-KSTEU NE 'E' AND KOMP-PRSOK = 'X'. *----Pricing Copy Logic COPY_FLAG = SPACE. IF XKOMV-KSTEU = 'F'. COPY_FLAG = 'X'. SAVE_XKOMV = XKOMV. COUNTER = 0. LOOP AT XKOMV WHERE KNTYP CA '1234' AND KAPPL = 'TX'. CASE XKOMV-KNTYP. WHEN '1'. AMOUNT = XKOMV-KWERT. COM_TAX-TAXAMT1 = AMOUNT. QUANTITY = XKOMV-KBETR. COM_TAX-TAXPCT1 = QUANTITY. WHEN '2'. AMOUNT = XKOMV-KWERT. COM_TAX-TAXAMT2 = AMOUNT. QUANTITY = XKOMV-KBETR. COM_TAX-TAXPCT2 = QUANTITY. WHEN '3'. AMOUNT = XKOMV-KWERT. COM_TAX-TAXAMT3 = AMOUNT. QUANTITY = XKOMV-KBETR. COM_TAX-TAXPCT3 = QUANTITY. WHEN '4'. COUNTER = COUNTER + 1. IF COUNTER = 1. AMOUNT = XKOMV-KWERT. COM_TAX-TAXAMT4 = AMOUNT. QUANTITY = XKOMV-KBETR. COM_TAX-TAXPCT4 = QUANTITY. ELSEIF COUNTER = 2. AMOUNT = XKOMV-KWERT. COM_TAX-TAXAMT5 = AMOUNT. QUANTITY = XKOMV-KBETR. COM_TAX-TAXPCT5 = QUANTITY. ELSEIF COUNTER = 3. AMOUNT = XKOMV-KWERT. COM_TAX-TAXAMT6 = AMOUNT. QUANTITY = XKOMV-KBETR.
SAP Brasil - Fone: (011) 5503-2400

"save actual XKOMV-entry

Marcos Roberto Pinotti

Tax Code - Pgina : 11

COM_TAX-TAXPCT6 = QUANTITY. ELSEIF COUNTER = 4. AMOUNT = XKOMV-KWERT. COM_TAX-TAXAMT7 = AMOUNT. QUANTITY = XKOMV-KBETR. COM_TAX-TAXPCT7 = QUANTITY. ELSEIF COUNTER = 5. AMOUNT = XKOMV-KWERT. COM_TAX-TAXAMT8 = AMOUNT. QUANTITY = XKOMV-KBETR. COM_TAX-TAXPCT8 = QUANTITY. ELSEIF COUNTER = 6. AMOUNT = XKOMV-KWERT. COM_TAX-TAXAMT9 = AMOUNT. QUANTITY = XKOMV-KBETR. COM_TAX-TAXPCT9 = QUANTITY. ENDIF. ENDCASE. COM_TAX-TAXAMOV = COM_TAX-TAXAMOV + AMOUNT. COM_TAX-TAXPCOV = COM_TAX-TAXPCOV + QUANTITY. CLEAR: AMOUNT, QUANTITY. ENDLOOP. XKOMV = SAVE_XKOMV. ENDIF. *----End of Pricing Copy Logic POSNR = KOMP-KPOSN. * Initialize MWSKZ IF XKOMV-MWSK1 IS INITIAL. MWSKZ = KOMP-MWSKZ. ELSE. MWSKZ = XKOMV-MWSK1. ENDIF.

"reset XKOMV entry

"MWSKZ aus Position (MM/FI) "MWSKZ aus Kondition (SD)

* Tax Exemptions SELECT SINGLE * FROM T007A WHERE KALSM = T005-KALSM AND MWSKZ = MWSKZ. IF T007A-TXREL = 2. " Tax Exempt * in case of tax exempt customers skip the call to ext. package EXEMPT_FLAG = 'X'. ENDIF. CLEAR PERCENTAGE. * begin of change J1B_0028 (Brazil localization) DATA: J1B_ACTIVE(1) TYPE C. "Indicator Brazil Active CALL FUNCTION 'J_1BSA_COMPONENT_CHECK' EXPORTING COMPONENT = 'BR' EXCEPTIONS COMPONENT_NOT_INSTALLED = 01. IF SY-SUBRC IS INITIAL. CALL FUNCTION 'J_1BSA_COMPONENT_ACTIVE' EXPORTING BUKRS = KOMK-BUKRS COMPONENT = 'BR' EXCEPTIONS COMPONENT_NOT_ACTIVE = 1. IF SY-SUBRC = 0. * set PERCENTAGE so that no exemption is processed PERCENTAGE = 100. J1B_ACTIVE = 'X'. ENDIF.
SAP Brasil - Fone: (011) 5503-2400 Marcos Roberto Pinotti

Tax Code - Pgina : 12

ENDIF. * end of change J1B_0028 (Brazil localization) SAVE_XKOMV = XKOMV. LOOP AT XKOMV WHERE KNTYP CA '1234'. PERCENTAGE = PERCENTAGE + XKOMV-KBETR. IF NOT PERCENTAGE IS INITIAL. EXIT. ENDIF. ENDLOOP. * READ TABLE XKOMV INDEX XKOMV_TABIX. XKOMV = SAVE_XKOMV. IF PERCENTAGE IS INITIAL. * in case of tax exempt customers skip the call to ext. package EXEMPT_FLAG = 'X'. ENDIF. * Initialize TTXD ON CHANGE OF T005-KALSM. SELECT SINGLE * FROM TTXD WHERE KALSM = T005-KALSM. CHECK SY-SUBRC = 0 AND NOT TTXD-XEXTN IS INITIAL. ENDON. * Read T007A SELECT SINGLE * FROM T007A WHERE KALSM = T005-KALSM AND MWSKZ = MWSKZ. IF SY-SUBRC NE 0. MESSAGE S873(FS) WITH T005-KALSM MWSKZ. KOMP-PRSOK = SPACE. XKOMV-KINAK = 'X'. XKOMV-FXMSG = '899'. CALL FUNCTION 'SET_ERROR_FLAG'. ENDIF. * Populate COM_TAX COM_TAX-CLIENT = SY-MANDT. " Client COM_TAX-COMP_CODE = KOMK-BUKRS. " Company Code COM_TAX-COUNTRY = KOMK-ALAND. " Country for Tax Determinatio COM_TAX-DOC_NUMBER = KOMK-BELNR. " Document Reference Number * COM_TAX-ACCNT_NO = KOMK-KUNNR. " Customer/Vendor Account Numb COM_TAX-TXJCD_L1 = TTXD-LENG1. " Length of the 1th part of Ju COM_TAX-TXJCD_L2 = TTXD-LENG2. " Length of the 2th part of Ju COM_TAX-TXJCD_L3 = TTXD-LENG3. " Length of the 3th part of Ju COM_TAX-TXJCD_L4 = TTXD-LENG4. " Length of the 4th part of Ju COM_TAX-MATNR = KOMP-MATNR. " Material * begin of change J1B_ (Brazil localization) * com_tax-unit = komp-vrkme. " Sales Unit of Measure * MGLME + MEINS belong together / also on LTAX1U02 and LTAX1U07 COM_TAX-UNIT = KOMP-MEINS. IF COM_TAX-UNIT IS INITIAL. COM_TAX-UNIT = KOMP-VRKME. ENDIF. * end of change J1B_ (Brazil localization) COM_TAX-CURRENCY = KOMK-WAERK. " Currency Key * COM_TAX-TAX_TYPE = ' '. " Indicator: sales/use/rental * COM_TAX-EXEMPT_IND = '0'. " Exempt from Taxes * COM_TAX-CREDIT_IND = " Credit/Debit Indicator * COM_TAX-FREIGHT_AM = * COM_TAX-EXEMPT_AMT = AMOUNT = XKOMV-KAWRT. IF NOT XKOMV-KSTAT IS INITIAL OR XKOMV-KSCHL IS INITIAL. IF AMOUNT IS INITIAL. AMOUNT = XKOMV-KWERT.
SAP Brasil - Fone: (011) 5503-2400 Marcos Roberto Pinotti

Tax Code - Pgina : 13

ENDIF. ENDIF. COM_TAX-AMOUNT

= AMOUNT.

" Gross Amount

QUANTITY = KOMP-MGLME. COM_TAX-QUANTITY = QUANTITY. IF KOMP-KPOSN <> '999999'. COM_TAX-POS_NO = KOMP-KPOSN. ELSE. IF KOMK-VERSI IS INITIAL. COM_TAX-POS_NO = SPACE. ELSE. COM_TAX-POS_NO = KOMK-VERSI. POSNR(3) = KOMK-VERSI. POSNR+3(3) = '999'. ENDIF. ENDIF.

" Quantity

ASSIGN/DEFAULT TAX_DATE KOMK-FBUDA KOMK-PRSDT. DEFAULT_ON_INITIAL TAX_DATE SY-DATUM. * Force consumer use tax depending in T007A setting SAVE_XKOMV = XKOMV. "save actual XKOMV-entry LOOP AT XKOMV WHERE KNTYP CA '1234'. T007A-MWSKZ = XKOMV-MWSK1. " get tax code from XKOMV EXIT. ENDLOOP. XKOMV = SAVE_XKOMV. "reset XKOMV entry SELECT SINGLE * FROM T007A WHERE KALSM = T005-KALSM AND MWSKZ = T007A-MWSKZ. IF SY-SUBRC = 0. COM_TAX-TAX_TYPE = T007A-TXIND. "Rental/Lease,Service COM_TAX-EXEMPT_IND = T007A-TXREL. "Tax Relevant Indicator ENDIF. * Determine decimals for currency CLEAR TCURX. SELECT SINGLE * FROM TCURX WHERE CURRKEY = COM_TAX-CURRENCY. ASSIGN/DEFAULT CURR_DEC TCURX-CURRDEC '002'. * Determine Jurisdictioncodes for tax calculation PLANT = T001W-WERKS. IF PLANT IS INITIAL. PLANT = KOMP-WERKS. ENDIF. CASE T007A-MWART. WHEN 'A'. * A/R taxes COM_TAX-ACCNT_NO = KOMK-KUNNR. " Customer Account Number COM_TAX-APAR_IND = 'A'. SELECT SINGLE * FROM T001W WHERE WERKS = PLANT. IF SY-SUBRC = 0. MOVE: T001W-TXJCD TO COM_TAX-TXJCD_SF. ELSE. MOVE: KOMK-TXJCD TO COM_TAX-TXJCD_SF. ENDIF. DEFAULT_ON_INITIAL TXJCD_SF KOMK-TXJCD. MOVE: KOMK-TXJCD TO COM_TAX-TXJCD_ST. WHEN 'V'. * A/P taxes COM_TAX-ACCNT_NO = KOMK-LIFNR. " Vendor Account Number COM_TAX-APAR_IND = 'V'.
SAP Brasil - Fone: (011) 5503-2400 Marcos Roberto Pinotti

Tax Code - Pgina : 14

SELECT SINGLE * FROM LFA1 WHERE LIFNR = KOMK-LIFNR. IF SY-SUBRC = 0. MOVE: LFA1-TXJCD TO COM_TAX-TXJCD_SF. ELSE. MOVE: KOMK-TXJCD TO COM_TAX-TXJCD_SF. ENDIF. DEFAULT_ON_INITIAL TXJCD_SF KOMK-TXJCD. MOVE: KOMK-TXJCD TO COM_TAX-TXJCD_ST. WHEN OTHERS. MESSAGE S874(FS) WITH T007A-MWART. KOMP-PRSOK = SPACE. XKOMV-KINAK = 'X'. XKOMV-FXMSG = '899'. CALL FUNCTION 'SET_ERROR_FLAG'. EXIT. ENDCASE. * begin of change J1B_0041 (Brazil localization) IF J1B_ACTIVE = 'X' AND EXEMPT_FLAG = SPACE. * fill jurisdiction-code for external customers or vendors CASE T007A-MWART. WHEN 'A'. * A/R taxes IF KOMK-KUNNR <> SPACE. CALL FUNCTION 'J_1BFOREIGN_JURISDICTION' EXPORTING BR_COUNTRY = KOMK-ALAND FOREIGN_COUNTRY = KOMK-LAND1 CHANGING TAX_JCD = COM_TAX-TXJCD_ST EXCEPTIONS FOREIGN_REGION_NOT_FOUND = 4. IF SY-SUBRC = 4. MESSAGE S316(8B) WITH KOMK-LAND1 RAISING TAX_DETERMINATION_ERROR. EXIT. ENDIF. ENDIF. WHEN 'V'. * A/P taxes IF KOMK-LIFNR <> SPACE. CALL FUNCTION 'J_1BFOREIGN_JURISDICTION' EXPORTING BR_COUNTRY = KOMK-ALAND FOREIGN_COUNTRY = LFA1-LAND1 CHANGING TAX_JCD = COM_TAX-TXJCD_SF EXCEPTIONS FOREIGN_REGION_NOT_FOUND = 4. IF SY-SUBRC = 4. MESSAGE S316(8B) WITH LFA1-LAND1 RAISING TAX_DETERMINATION_ERROR. EXIT. ENDIF. ENDIF. ENDCASE. ENDIF. * end of change J1B_0041 (Brazil localization) * begin of change J1B_0041 (Brazil localization) * process check only if Brazil is not active IF J1B_ACTIVE = SPACE. * end of change J1B_0041 (Brazil localization)
SAP Brasil - Fone: (011) 5503-2400 Marcos Roberto Pinotti

Tax Code - Pgina : 15

IF KOMK-TXJCD = EXEMPT_FLAG = ENDIF. * begin of change ENDIF. * end of change

T001-TXJCD. 'X'. J1B_0041 (Brazil localization) J1B_0041 (Brazil localization)

SAVE_COM_TAX = COM_TAX. * Try to fill product code from table T007A SELECT SINGLE * FROM TTXP WHERE XEXTN = TTXD-XEXTN AND PROCD = T007A-PROCD. IF SY-SUBRC = 0. COM_TAX-PROD_CODE = TTXP-XPRCD. ENDIF. * PERFORM FIND_EXT_PRODUCT_CODE(RFYTXPCD) * USING KOMP-MATNR TTXD-XEXTN * CHANGING EXT_PRODCD. * Copy XKOMV to XXKOMV as argument for user-exit REFRESH XXKOMV. SAVE_XKOMV = XKOMV. LOOP AT XKOMV. XXKOMV = XKOMV. APPEND XXKOMV. ENDLOOP. XKOMV = SAVE_XKOMV. * User exit for COM_TAX CALL CUSTOMER-FUNCTION '001' EXPORTING I_KOMK = KOMK I_KOMP = KOMP I_T007A = T007A I_TTXD = TTXD TABLES T_KOMV = XXKOMV CHANGING C_COM_TAX = COM_TAX. DEFAULT_ON_INITIAL DEFAULT_ON_INITIAL DEFAULT_ON_INITIAL DIVISION KOMK-GSBER. TXJCD_POA COM_TAX-TXJCD_SF. TXJCD_POO COM_TAX-TXJCD_ST. " Business Area " Point of order acc " Point of order ori

IF COM_TAX-TXJCD_SF IS INITIAL. MESSAGE S882(FS) RAISING TAX_DETERMINATION_ERROR. ENDIF. IF COM_TAX-TXJCD_ST IS INITIAL. MESSAGE S883(FS) RAISING TAX_DETERMINATION_ERROR. ENDIF. * Following fields should not be manipulated by the user-exit COM_TAX-CLIENT = SAVE_COM_TAX-CLIENT. COM_TAX-COMP_CODE = SAVE_COM_TAX-COMP_CODE. COM_TAX-COUNTRY = SAVE_COM_TAX-COUNTRY. COM_TAX-DOC_NUMBER = SAVE_COM_TAX-DOC_NUMBER. COM_TAX-POS_NO = SAVE_COM_TAX-POS_NO. COM_TAX-AMOUNT = SAVE_COM_TAX-AMOUNT. COM_TAX-CURRENCY = SAVE_COM_TAX-CURRENCY. COM_TAX-CURR_DEC = SAVE_COM_TAX-CURR_DEC. COM_TAX-TAX_DATE = SAVE_COM_TAX-TAX_DATE. COM_TAX-TXJCD_L1 = SAVE_COM_TAX-TXJCD_L1. COM_TAX-TXJCD_L2 = SAVE_COM_TAX-TXJCD_L2.
SAP Brasil - Fone: (011) 5503-2400 Marcos Roberto Pinotti

Tax Code - Pgina : 16

COM_TAX-TXJCD_L3 COM_TAX-TXJCD_L4

= SAVE_COM_TAX-TXJCD_L3. = SAVE_COM_TAX-TXJCD_L4.

* begin of change J1B_0014 (Brazil localization) IF J1B_ACTIVE = 'X'. CALL FUNCTION 'J_1BNF_TAX_DATA_RESET_PART' EXPORTING KNUMV = KOMK-KNUMV KPOSN = KOMP-KPOSN BUZEI = KOMK-VERSI. ENDIF. * end of change J1B_0014 (Brazil localization) IF COM_TAX-AMOUNT NE 0 AND EXEMPT_FLAG <> 'X'. IF KOMK-HWAER = SPACE. KOMK-HWAER = T001-WAERS. ENDIF. IF KOMK-HWAER <> KOMK-WAERK. begin of change J1B_0041 (Brazil localization) process message only if Brazil is not active IF J1B_ACTIVE = SPACE. end of change J1B_0041 (Brazil localization) CALL FUNCTION 'CUSTOMIZED_MESSAGE' EXPORTING I_ARBGB = 'FS' I_DTYPE = 'E' I_MSGNR = '885'. begin of change J1B_0041 (Brazil localization) ENDIF. end of change J1B_0041 (Brazil localization) ENDIF. Determine DESTINATION for external system ON CHANGE OF TTXD-XEXTN. SELECT SINGLE * FROM TTXC WHERE XEXTN = TTXD-XEXTN AND EVENT = 'TAX'. IF SY-SUBRC <> 0. RAISE RFCDEST_NOT_FOUND. ELSE. TRANSLATE TTXC-RFCDEST TO UPPER CASE. IF TTXC-FUNCNAME IS INITIAL. TTXC-FUNCNAME = 'RFC_CALCULATE_TAXES'. ENDIF. ENDIF. ENDON. Let the external system CLEAR: COM_TAX-TAXAMT1, COM_TAX-TAXAMT4, COM_TAX-TAXAMT7, COM_TAX-TAXAMOV, CLEAR: COM_TAX-TAXPCT1, COM_TAX-TAXPCT4, COM_TAX-TAXPCT7, COM_TAX-TAXPCOV, do the calculation COM_TAX-TAXAMT2, COM_TAX-TAXAMT3, COM_TAX-TAXAMT5, COM_TAX-TAXAMT6, COM_TAX-TAXAMT8, COM_TAX-TAXAMT9, COM_TAX-TAXAMT0. COM_TAX-TAXPCT2, COM_TAX-TAXPCT3, COM_TAX-TAXPCT5, COM_TAX-TAXPCT6, COM_TAX-TAXPCT8, COM_TAX-TAXPCT9, COM_TAX-TAXPCT0. " Don't Update Tax Registr

* * *

* *

COM_TAX-UPDATE_IND = ' '.

* begin of change J1B_0014 (Brazil localization) DATA: BR_KOMV LIKE KOMV. "XKOMV also contains Index ! BR_KOMV = XKOMV. IF J1B_ACTIVE = 'X'.
SAP Brasil - Fone: (011) 5503-2400 Marcos Roberto Pinotti

Tax Code - Pgina : 17

fill BR_KONP REFRESH BR_KONP. LOOP AT XKONP. BR_KONP = XKONP-KONP. APPEND BR_KONP. ENDLOOP. CALL FUNCTION 'J_1BCOMPLETE_TAX_DATA' EXPORTING I_KOMK = KOMK I_KOMP = KOMP I_T007A = T007A I_KOMV = BR_KOMV TABLES T_KOMV = XXKOMV T_KONP = BR_KONP. * changing * c_tax = com_tax. ENDIF. * end of change J1B_0014 (Brazil localization) CALL FUNCTION TTXC-FUNCNAME DESTINATION EXPORTING TAX_DATA IMPORTING TAX_RESULT TAX_ERR EXCEPTIONS COMMUNICATION_FAILURE SYSTEM_ERROR

TTXC-RFCDEST = COM_TAX = COM_TAX = COM_ERR = 01 = 02.

IF SY-SUBRC NE 0. MESSAGE S870(FS). KOMP-PRSOK = SPACE. XKOMV-KINAK = 'X'. XKOMV-FXMSG = '899'. CALL FUNCTION 'SET_ERROR_FLAG'. EXIT. ELSEIF COM_ERR-RETCODE <> 0. MESSAGE S872(FS) WITH COM_ERR-ERRCODE COM_ERR-ERRMSG. KOMP-PRSOK = SPACE. XKOMV-KINAK = 'X'. XKOMV-FXMSG = '899'. CALL FUNCTION 'SET_ERROR_FLAG'. EXIT. ENDIF. ELSE. " gross amount is zero COM_TAX-TAXAMT0 = 0. " Federal Tax Amount COM_TAX-TAXAMT1 = 0. " State Tax Amount COM_TAX-TAXAMT2 = 0. " County Tax Amount COM_TAX-TAXAMT3 = 0. " City/Local Tax Amount COM_TAX-TAXAMT4 = 0. " Distict Tax Amount COM_TAX-TAXAMT5 = 0. " Secondary City Tax Amount COM_TAX-TAXAMT6 = 0. " Other Tax Amount COM_TAX-TAXAMT7 = 0. " Other Tax Amount COM_TAX-TAXAMT8 = 0. " Other Tax Amount COM_TAX-TAXAMT9 = 0. " Other Tax Amount COM_TAX-TAXAMOV = 0. " Total overall Tax Amount COM_TAX-TAXPCT0 COM_TAX-TAXPCT1 COM_TAX-TAXPCT2 COM_TAX-TAXPCT3 = = = = 0. 0. 0. 0. " " " " Federal Tax Rate State Tax Rate County Tax Rate City/Local Tax Rate
Marcos Roberto Pinotti

SAP Brasil - Fone: (011) 5503-2400

Tax Code - Pgina : 18

COM_TAX-TAXPCT4 COM_TAX-TAXPCT5 COM_TAX-TAXPCT6 COM_TAX-TAXPCT7 COM_TAX-TAXPCT8 COM_TAX-TAXPCT9 COM_TAX-TAXPCOV ENDIF.

= = = = = = =

0. 0. 0. 0. 0. 0. 0.

" " " " " " "

District Tax Rate Secondary City Tax Rate Other Tax Rate Other Tax Rate Other Tax Rate Other Tax Rate Total overall Tax Rate

* Save in external memory IF KOMK-VRGAR <> SPACE AND KOMP-KPOSN = '999999'. "Called via RW-IN - dont save in memory ELSE. CALL FUNCTION 'US_TAXES_UPDATE_TAX_MEMORY' EXPORTING I_KPOSN = POSNR I_MWSKZ = MWSKZ I_XEXTN = TTXD-XEXTN I_TAXIN = COM_TAX. ENDIF. * Fill global workfields from internal structure TAXAMT0 = COM_TAX-TAXAMT0. TAXAMT1 = COM_TAX-TAXAMT1. TAXAMT2 = COM_TAX-TAXAMT2. TAXAMT3 = COM_TAX-TAXAMT3. TAXAMT4 = COM_TAX-TAXAMT4. TAXAMT5 = COM_TAX-TAXAMT5. TAXAMT6 = COM_TAX-TAXAMT6. TAXAMT7 = COM_TAX-TAXAMT7. TAXAMT8 = COM_TAX-TAXAMT8. TAXAMT9 = COM_TAX-TAXAMT9. TAXPCT0 TAXPCT1 TAXPCT2 TAXPCT3 TAXPCT4 TAXPCT5 TAXPCT6 TAXPCT7 TAXPCT8 TAXPCT9 = = = = = = = = = = COM_TAX-TAXPCT0. COM_TAX-TAXPCT1. COM_TAX-TAXPCT2. COM_TAX-TAXPCT3. COM_TAX-TAXPCT4. COM_TAX-TAXPCT5. COM_TAX-TAXPCT6. COM_TAX-TAXPCT7. COM_TAX-TAXPCT8. COM_TAX-TAXPCT9.

* begin of change J1B_0020 (Brazil localization) IF J1B_ACTIVE = 'X'. TAXBAS1 = COM_TAX-TAXBAS1. TAXBAS2 = COM_TAX-TAXBAS2. TAXBAS3 = COM_TAX-TAXBAS3. TAXBAS4 = COM_TAX-TAXBAS4. TAXBAS5 = COM_TAX-TAXBAS5. TAXBAS6 = COM_TAX-TAXBAS6. TAXBAS7 = COM_TAX-TAXBAS7. TAXBAS8 = COM_TAX-TAXBAS8. TAXBAS9 = COM_TAX-TAXBAS9. ENDIF. * end of change J1B_0020 (Brazil localization) ENDFORM.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 19

301

IPI for the industrialization case (301 + 302 may occur together)

*---------------------------------------------------------------------* * FORM FRM_KONDI_WERT_301 * *---------------------------------------------------------------------* * Set tax values and percentage into condition structure and * * fill tax base amount * *---------------------------------------------------------------------* FORM FRM_KONDI_WERT_301. CHECK KOMK-TRTYP NE 'A'. * take over rates and values from internal fields IF XKOMV-KBETR NE 0. XKOMV-KWERT = TAXAMT1. XKWERT = TAXAMT1. IF XKOMV-KAWRT NE 0. XKOMV-KBETR = TAXPCT1. ENDIF. ELSE. * reset fields for zero percent tax codes XKOMV-KBETR = 0. XKWERT = 0. ENDIF. TAXBAS1 ENDFORM. = XKOMV-KAWRT.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 20

302

IPI for the consumption case (301 + 302 may occur together)

*---------------------------------------------------------------------* * FORM FRM_KONDI_WERT_302 * *---------------------------------------------------------------------* * Set tax values and percentage into condition structure and * * fill tax base amount * *---------------------------------------------------------------------* FORM FRM_KONDI_WERT_302. CHECK KOMK-TRTYP NE 'A'. * take over rates and values from internal fields IF XKOMV-KBETR NE 0. XKOMV-KWERT = TAXAMT2. XKWERT = TAXAMT2. IF XKOMV-KAWRT NE 0. XKOMV-KBETR = TAXPCT2. ENDIF. ELSE. * reset fields for zero percent tax codes XKOMV-KBETR = 0. XKWERT = 0. ENDIF. TAXBAS2 ENDFORM. = XKOMV-KAWRT.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 21

303

ICMS for all cases

*---------------------------------------------------------------------* * FORM FRM_KONDI_WERT_303 * *---------------------------------------------------------------------* * Set tax values and percentage into condition structure and * * fill tax base amount * *---------------------------------------------------------------------* FORM FRM_KONDI_WERT_303. CHECK KOMK-TRTYP NE 'A'. * take over rates and values from internal fields IF XKOMV-KBETR NE 0. XKOMV-KWERT = TAXAMT3. XKWERT = TAXAMT3. IF XKOMV-KAWRT NE 0. XKOMV-KBETR = TAXPCT3. ENDIF. ELSE. * reset fields for zero percent tax codes XKOMV-KBETR = 0. XKWERT = 0. ENDIF. TAXBAS3 ENDFORM. = XKOMV-KAWRT.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 22

304

Substituicao Tributaria

*---------------------------------------------------------------------* * FORM FRM_KONDI_WERT_304 * *---------------------------------------------------------------------* * Set tax values and percentage into condition structure and * * fill tax base amount * *---------------------------------------------------------------------* FORM FRM_KONDI_WERT_304. CHECK KOMK-TRTYP NE 'A'. * take over rates and values from internal fields IF XKOMV-KBETR NE 0. XKOMV-KWERT = TAXAMT4. XKWERT = TAXAMT4. IF XKOMV-KAWRT NE 0. XKOMV-KBETR = TAXPCT4. ENDIF. ELSE. * reset fields for zero percent tax codes XKOMV-KBETR = 0. XKWERT = 0. ENDIF. TAXBAS4 ENDFORM. = XKOMV-KAWRT.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 23

305

ICMS complement (in MM) and ICMS Zona Franca discount (in SD)

*---------------------------------------------------------------------* * FORM FRM_KONDI_WERT_305 * *---------------------------------------------------------------------* * Set tax values and percentage into condition structure and * * fill tax base amount * *---------------------------------------------------------------------* FORM FRM_KONDI_WERT_305. CHECK KOMK-TRTYP NE 'A'. * take over rates and values from internal fields IF XKOMV-KBETR NE 0. XKOMV-KWERT = TAXAMT5. XKWERT = TAXAMT5. IF XKOMV-KAWRT NE 0. XKOMV-KBETR = TAXPCT5. ENDIF. ELSE. * reset fields for zero percent tax codes XKOMV-KBETR = 0. XKWERT = 0. ENDIF. TAXBAS5 ENDFORM. = XKOMV-KAWRT.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 24

306

ISS (only calculated in SD)

*---------------------------------------------------------------------* * FORM FRM_KONDI_WERT_306 * *---------------------------------------------------------------------* * Set tax values and percentage into condition structure and * * fill tax base amount * *---------------------------------------------------------------------* FORM FRM_KONDI_WERT_306. CHECK KOMK-TRTYP NE 'A'. * take over rates and values from internal fields IF XKOMV-KBETR NE 0. XKOMV-KWERT = TAXAMT6. XKWERT = TAXAMT6. IF XKOMV-KAWRT NE 0. XKOMV-KBETR = TAXPCT6. ENDIF. ELSE. * reset fields for zero percent tax codes XKOMV-KBETR = 0. XKWERT = 0. ENDIF. TAXBAS6 ENDFORM. = XKOMV-KAWRT.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 25

307

ICMS Sub.Trib. on freight offset

*---------------------------------------------------------------------* * FORM FRM_KONDI_WERT_307 * *---------------------------------------------------------------------* * Set tax values and percentage into condition structure and * * fill tax base amount * *---------------------------------------------------------------------* FORM FRM_KONDI_WERT_307. CHECK KOMK-TRTYP NE 'A'. * take over rates and values from internal fields IF XKOMV-KBETR NE 0. XKOMV-KWERT = TAXAMT7. XKWERT = TAXAMT7. IF XKOMV-KAWRT NE 0. XKOMV-KBETR = TAXPCT7. ENDIF. ELSE. * reset fields for zero percent tax codes XKOMV-KBETR = 0. XKWERT = 0. ENDIF. TAXBAS7 ENDFORM. = XKOMV-KAWRT.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti

Tax Code - Pgina : 26

309

Zero value

*---------------------------------------------------------------------* * FORM FRM_KONDI_WERT_309 * *---------------------------------------------------------------------* * Set tax values and percentage into condition structure and * * fill tax base amount * *---------------------------------------------------------------------* FORM FRM_KONDI_WERT_309. CHECK KOMK-TRTYP NE 'A'. * take over rates and values from internal fields IF XKOMV-KBETR NE 0. XKOMV-KWERT = TAXAMT9. XKWERT = TAXAMT9. IF XKOMV-KAWRT NE 0. XKOMV-KBETR = TAXPCT9. ENDIF. ELSE. * reset fields for zero percent tax codes XKOMV-KBETR = 0. XKWERT = 0. ENDIF. TAXBAS9 ENDFORM. = XKOMV-KAWRT.

SAP Brasil - Fone: (011) 5503-2400

Marcos Roberto Pinotti