Documente Academic
Documente Profesional
Documente Cultură
Note 1018098
Table of Content: 1 2 3 Introduction ....................................................................................................... 3 Document History.............................................................................................. 3 Overview ........................................................................................................... 4 3.1 New IMG Activities................................................................................... 4 3.1.1 Assign XML Version to Region ........................................................... 4 3.1.2 Define SEFAZ Status Codes ............................................................... 4 3.1.3 Maintain Number Ranges for NF-e..................................................... 4 3.1.4 Define NF Type Redetermination for Goods Movements..................... 4 3.1.5 Assign RFC Dest. for Outbound Msg to Co. Code and Bus. Place ...... 4 3.1.6 BAdI: General Enhancements for NF-e .............................................. 5 3.1.7 Define NF Type Redetermination per Business Place ......................... 5 3.1.8 Define NF Type Redetermination per State......................................... 5 3.1.9 BAdI: Redetermination of Nota Fiscal Type per Line Item.................. 5 3.2 Enhanced IMG Activities........................................................................... 5 3.2.1 Define Nota Fiscal Types ................................................................... 5 3.2.2 Assign Numbering and Printing Parameters....................................... 6 3.2.3 Define IPI Tax Laws........................................................................... 6 3.3 New Business Add-In CL_NFE_PRINT .................................................... 6 3.3.1 BAdI Method: RESET_SUBRC........................................................... 6 3.3.2 BAdI Method: CHECK_SUBSEQUENT_DOCUMENTS .................... 6 3.3.3 BAdI Method: FILL_HEADER ........................................................... 7 3.3.4 BAdI Method: FILL_ITEM ................................................................. 7 3.3.5 BAdI Method: CALL_RSNAST00........................................................ 7 3.4 New Business Add In CL_SD_NFTYPE.................................................... 7 3.4.1 BAdI Method: MODIFY ..................................................................... 7 4 Required Configurations .................................................................................... 9 4.1 Creation of NF types for NF-e.................................................................... 9 4.2 Maintain Number Ranges for external NF-e number .................................. 9 4.3 Authorization: User Actions in NF-e Monitor ............................................ 9 4.4 Version of XML Layout............................................................................. 9 4.5 Contingency settings .................................................................................10 4.5.1 Determination of number range in SD and MM.................................10 4.5.2 Determination of the contingency printer in MM ...............................10 2008 SAP Dietmar-Hopp Allee 16 D-69190 Walldorf Version: 2.0 Date: 2007/09/17 Page 1 of 22
4.5.3 Determination of the contingency printer in SD.................................11 4.6 SD: NF-Type Determination .....................................................................11 4.7 MM: NF-Type Redetermination for Goods Movements ............................12 4.8 CBT: Mapping of SubTrib Base Reduction ...............................................12 4.8.1 Create new conditions for MM & SD.................................................12 4.8.2 Maintain calculation procedure TAXBRA..........................................12 4.8.3 Create new internal codes .................................................................12 4.8.4 Assign internal codes to conditions....................................................12 4.9 Maintain Alternate County Key.................................................................13 5 Optional Configurations....................................................................................14 5.1 RFC Destination .......................................................................................14 5.2 Maintenance of SEFAZ Status Codes........................................................14 5.3 Automated Printing of DANFE .................................................................14 5.4 Transition Phase........................................................................................14 5.5 IPI Tax Situation for outgoing NFs ...........................................................15 5.6 Authorization: Access to NF-e Monitor.....................................................15 6 Communication with Messaging System...........................................................16 6.1 Interface for Outbound Messages ..............................................................16 6.2 Interfaces for Inbound Messages ...............................................................17 6.3 Message Type of Inbound Message...........................................................17 6.4 Backend Control .......................................................................................17 6.5 Messaging-System Control .......................................................................17 7 Appendix ..........................................................................................................19 7.1 Example Coding for BAdI Method CALL_RSNAST00 ............................19 7.2 Routine 901 ..............................................................................................19
Page 2 of 22
Introduction
The delivery of the functionality for electronic Notas Fiscas (NF-e) is described in the overview note 989115. The solution for SEFAZ NF-e comprises two parts: (a) an integration of NF-e process logic into the application logic of the SAP backend and (b) a solution for a messaging system supporting the implementation in the backend. This configuration guide describes the mandatory and optional system configurations relevant for NF-e of SEFAZ in the backend. It also gives the information relevant for a solution on the messaging-system side in order to complement and properly interact with the SAP backend.
Document History
History
Version Date 1.0 2.0 Comment (Author) Delivered with development phase 2 note 980213 New authorization profile (note 1070261); application-log objects (note 1094041); BAdI interface changes not included
2007-02-22 2007-09-17
Page 3 of 22
Overview
This section gives an overview of all new and enhanced IMG activities and BAdIs. The purpose and use of these configuration objects is described in the subsequent sections Required Configurations and Optional Configurations.
3.1
Cross-Application Components General Application Functions Nota fiscal Electronic Notas Fiscas (NF-e) Assign XML Version to Region
VIEW:
J_1BNFE_XMLV_V
Cross-Application Components General Application Functions Electronic Notas Fiscas (NF-e) Define SEFAZ Status Codes
VIEW:
Nota fiscal
J_1BSTSCODEV
Cross-Application Components General Application Functions Nota fiscal Electronic Notas Fiscas (NF-e) Maintain Number Ranges for NF-e
TRANSACTION:
J1BI_NFE
J_1BNFTYPEREDMMV
3.1.5 Assign RFC Dest. for Outbound Msg to Co. Code and Bus. Place
IMG: Cross-Application Components
fiscal Electronic Notas Fiscas (NF-e) Messages to Co. Code and Bus. Place
VIEW:
J_1BNFE_RFCD_V 2008 SAP Dietmar-Hopp Allee 16 D-69190 Walldorf Version: 2.0 Date: 2007/09/17 Page 4 of 22
CL_NFE_PRINT (
transaction SE18)
Cross-Application Components General Application Functions Nota fiscal Sales and Distribution - Billing Documents Define Redetermination of Nota Fiscal Type per Business Place
VIEW:
J_1B_NFTYPEBRCHV
Cross-Application Components General Application Functions Nota fiscal Sales and Distribution - Billing Documents Define Redetermination of Nota Fiscal Type per State
VIEW:
J_1B_NFTYPEREGV
Cross-Application Components General Application Functions Nota fiscal Sales and Distribution - Billing Documents BAdI: Redetermination of Nota Fiscal Type per Line Item
BAdI Definition:
CL_SD_NFTYPE (
transaction SE18)
3.2
IMG:
Enhancements: 1) New flag Electronic NF Characterizes the NF type as an NF type for electronic Notas Fiscas 2) New field NF Contin. Type NF type that is used if in case of a contingency switch the contingency NF is not supposed to be an electronic NF
Page 5 of 22
Cross-Application Components General Application Functions Output Assign Numbering and Printing Parameters
VIEW:
Nota fiscal
J_1BB2V
Enhancements: 1) New NF-e sub-area with: 2) New field for the number-range number of the 9-digit NF-e number (number-range object J_1BNFENUM) 3) New field to specify the NF-e output device that is to be used in contingency when the contingency NF should be an NF-e printed on security paper. 4) New Flag Numbering Contin. indicating that the contingency NF should be an NF-e printed on security paper. 5) Re-organization of the screen into three areas containing NF-e specific fields, fields relevant only for non-electronic NFs, and fields relevant for both electronic and nonelectronic NFs.
Financial Accounting Financial Accounting Global Settings Tax on Sales/Purchases Basic Settings Brazil Define IPI Tax Laws
VIEW:
J_1BB2V
Enhancements: New field Tax Sit. IPI Ou in the view for details.
3.3
3.4
See IMG Activity: BAdI: Redetermination of Nota Fiscal Type per Line Item
IS_VBKD (Sales Document: Business Data) IS_LIKP (SD Document: Delivery Header Data) IS_LIPS (SD document: Delivery: Item data) Changing: CV_NFTYPE (Nota Fiscal Type) Exception: ERROR (An error has occurred)
Page 8 of 22
Required Configurations
This section gives a description of all mandatory system configurations. You will find a subsection per configuration topic.
4.1
The system recognizes an NF-e process based on the assigned NF type. For NF-e processes, new NF types must be defined (IMG activity Define Nota Fiscal Types). Copy existing ones and set in the new ones the NF-e flag.
4.2
New number ranges for the external NF-e number you define per number-range group in the IMG activity Maintain Number Ranges for NF-e.
4.3
User actions in the NF-e Monitor (transaction J1BNFE) are subject to authorization checks. The authorization object F_NFBA involved is available with note 687829. User Action Request an authorization to cancel an authorized NF-e Request an authorization to cancel a rejected NF-e Set Contingency per Region or per Business Place Delete NF-e log entries Send NF-e with SCS ' ' (not sent) Set Contingency per NF-e Reset Contingency per NF-e Check XI connection Check NF-e log Display NF-e in NF writer Auth. Object F_NFBA F_NFBA F_NFBA F_NFBA F_NFBA F_NFBA F_NFBA no check no check no check Activity 85 [reverse]) 85 [output]) 85 [reverse]) 35 [output]) 35 [output]) 35 [output]) 35 [output])
4.4
Maintain the current version of the XML layout in the IMG activity Assign XML Version to Region. The current version of the XML layout is defined per state. The XML layout you maintain in the IMG activity Assign XML Version to Region is passed via the outbound interface to the messaging system. Based on the layout, the messaging system maps the NF-e data to the XML message structure. The XML version does not impact the backend logic. You must ensure that the version you maintain is supported by the backend. Implement the relevant notes or upgrade to the required support package. The delivery of the XML versions is described in the overview note 989115.
Page 9 of 22
If you need different XML versions within one state, you must implement the method BAdI Method: FILL_HEADER of the Business Add-In CL_NFE_PRINT to overwrite the version you have maintained in the IMG activity Assign XML Version to Region. This might be the case if different business places of your company located in the same region communicate with different SEFAZ systems (for production and for testing) that require different versions.
4.5
Contingency settings
This section considers NF-es that have been posted under normal process conditions and are switched to contingency. Whenever you decide to continue a business process in contingency, i.e., to print the related, already created invoice without prior authorization by the government you must decide if you want to print the invoice as an electronic NF or as a non-electronic NF. Electronic contingency NFs are to be printed on security paper using a laser printer. In this case, the NF model, e.g., 55 and the NF-e number range remain unchanged. Non-electronic NFs are printed on dot-matrix printers. NF model and NF number range change. In any case, the initial NF must be cancelled together with the source document from SD, MM, or IV and a new NF must be posted.
Nota Fiscal Types. The determination of the dot-matrix printer is then done based on the configurations related to the non-electronic contingency NF type.
4.6
Two new maintenance views are available to enhance the classic Nota Fiscal Type determination based on the sales order type. The determination checks first if a NF type is assigned to the sales-order type (classic determination). If there is one, the system checks if this classic NF type has to be replaced by a Nota Fiscal type defined per business place (view J_1B_NFTYPEBRCHV). If no NF type is maintained per business place, the system checks if the classic NF type has to be replaced by a NF type defined per state (view J_1B_NFTYPEREGV). Eventually, the system checks for an implementation of the BAdI method MODIFY of the BAdI CL_SD_NFTYPE. With this BAdI method it is possible to assign a NF type at line-item level during the billing process. Consequence: The system induces a billing document split to ensure that only line items having the same NF type are included in a billing document. To support this feature the user must maintain the billing document data transport routine 901 (coding in the appendix) for the relevant entries in the following IMG activities: IMG: Sales and Distribution Control for billing documents document IMG: Sales and Distribution Control for billing documents document Billing Billing Documents Maintain Copying Copying control: Sales document to billing Billing Billing Documents Maintain Copying Copying control: Delivery document to billing
Page 11 of 22
4.7
In case of goods movements, the NF type is determined from the movement type. The existing assignment of NF types to movement type in the IMG activity Materials Management Inventory Management and Physical Inventory Nota Fiscal Maintain Nota Fiscal Category Derivation remains unchanged. Assign NF-e types to MM movement types per plant in the IMG activity Define NF Type Redetermination for Goods Movements. A duplication of movement types for NF-e processes is not necessary. A configuration in the IMG activity Define NF Type Redetermination for Goods Movements is thus required for those plant and business transactions (movement types) that are subject to NF-e processing.
4.8
The configurations described in this section are only relevant if condition-based tax calculation used for Brazilian company codes.
Copy BX44 to BX45 Short text: BRSubTrib NF Basred1 Copy BX45 to BX46 Short text: BRSubTrib NF Basred2
Insert two new steps after the step with condition BX44 as copy from step with BX44. In the first new step insert condition BX45, in the second BX46. Repeat the same steps for used SD calculation procedures.
NF_SUBTRIB_BASERED1 Federal base reduction Rate for Subtrib NF_SUBTRIB_BASERED2 State base reduction Rate for Subtrib
Appl. TX V TX V
Page 12 of 22
4.9
With the alternate country key, the IGBE country code is determined and set for the XML File.
IMG:
Set countries
In the detail view insert: Alternate country key 508 Brazil 512 Chile 520 Paraguay 524 Uruguay 528 Argentina
In case of using a country code different from those described above, create corresponding entries.
Page 13 of 22
Optional Configurations
This section gives a description of all optional system configurations. You will find a subsection per configuration topic.
5.1
RFC Destination
The default RFC destination is ENF_BR_2006. The RFC destination ENF_BR_2006 is hard-coded. If you want to use a different RFC destination, you need to maintain it in the IMG activity Assign RFC Dest. for Outbound Messages to Co. Code and Bus. Place. The link between the RFC destination (input channel of the messaging system) and the respective government system for production or testing needs to be defined in the messaging system.
5.2
SEFAZ sends a status code with each response message. These codes provide information about the reason for a particular response, e.g., the reason for a rejection of an authorization request. The SEFAZ status code is a mandatory field of the inbound interface from the messaging system to the backend. The maintenance of status codes with description is possible but not mandatory. Independent of the definition of status codes in the IMG activity Define SEFAZ Status Codes the code itself (not the description) is stored in the NF-e data base.
5.3
When you post a document in Sales and Distribution (SD) or Materials Management (MM) that generates an electronic nota fiscal (NF-e), you cannot print the NF-e immediately; you must first wait for authorization from SEFAZ. Once SEFAZ approves your NF-e and returns a corresponding protocol number, the system does not print the NF-e automatically. You must print the NF-e manually using the NF Writer. You can use the method CALL_RSNAST00 of the BAdI CL_NFE_PRINT to trigger automatic printing of the NF-e upon receipt of authorization from SEFAZ. You can find an example coding in the appendix of this document.
5.4
Transition Phase
During a transition phase from classical NF posting to NF-e processing, the legally relevant notas fiscas are non-electronic, i.e., of model 1/1A. However, the NF data is sent to SEFAZ as an XML message as if the posted NF was an NF-e. The model in the XML message must be 55. The NF number is the 6-digit non-electronic number. It is not required to receive an authorization prior to printing the NF. The DANFE (with 2008 SAP Dietmar-Hopp Allee 16 D-69190 Walldorf Version: 2.0 Date: 2007/09/17 Page 14 of 22
or without protocol number) must be printed and together with the NF of model 1/1A be sent with the goods. To enable this process, you need to do the following: 1) To create an outbound XML message, inset the following entry in the IMG activity Nota Fiscal Output Processing Program: Medium 1 Short text Print output Program J_1BNFEXMLOUTPARALLEL FROM routine ENTRY
2) Enhancement of the report J_1BNFEXMLOUTPARALLEL (optional) The report is delivered via support package or implemented with note 1017488. You may implement checks or logic to fill fields in the XML file directly in the report. Recommendation: copy report to z-report and modify the z-report. In this case, insert the z-report in the IMG activity processing program. 3) Maintain an RFC destination for the parallel phase and link it to the test system of the government (configuration of the messaging system). See chapter RFC Destination. 4) To print the DANFE, create another entry in the IMG activity Nota Fiscal Output Processing Program. For further details, see note 955155.
5.5
The XML layout contains separate fields for the IPI tax situation for incoming and outgoing NF-es. You can maintain an IPI tax situation for outgoing NF-es that is different from the IPI tax situation for incoming NF-es. You do that in the IMG activity Define IPI Tax Laws in the field Tax Sit. IPI Ou. If you do not maintain an entry in this field, the system will take the entry maintained in the field Tax Sit. IPI In for both, incoming and outgoing NF-es.
5.6
The access to the NF-e Monitor via transaction J1BNFE can be restricted. To this end, implement note 687829 and activate the NF authorization checks as described in this note. If authorization checks are activated, only users who have the authorization object F_NFBA, activity 03 [display] assigned to their authorization profile can access the NF-e Monitor via transaction J1BNFE. This is the same authorization as required to use the NF-writer display transaction J1B3N.
Page 15 of 22
This section gives a description of the backend functionalities that are relevant for the communication between backend and messaging system, e.g., the SAP Exchange Infrastructure (XI). Corresponding settings and configuration of the messaging system is mandatory.
6.1
The backend asynchronously sends messages via the outbound interface: J_1B_NFE_XML_OUT (Function Module) This interface provides the NF-e data as required by the authorities according to the currently valid XML layout together with the NF-e document status (DS), the NF-e system communication status (SCS), and the contingency flag. The messaging system has the task to map the NF-e data to the layout structure of the XML file. The NF-e document status and the NF-e system communication status contain the information about the type of outbound message, which could be one of the following: 1) 2) 3) 4) Request for authorization Submission of a Contingency NF-e Request to authorize the cancellation of an authorized NF-e Request to skip the number of a rejected NF-e
The identification of the different types of outbound messages is given by the value of the following interface fields XML_IN- DOCSTAT XML_IN- SCSSTAT XML_IN- CONTING as follows
Message (1) Request for authorization (2) Submission of a contingency NF-e (3) Request to authorize the cancellation of an authorized NF-e (4) Request to skip the number of a rejected NF-e
DOCSTAT
initial initial 1 2
SCSSTAT
0 0 1 3
CONTING
initial X Initial initial
Page 16 of 22
6.2
The back end can receive messages via the inbound interfaces: J_1B_NFE_XML_IN (Function Module) single NF-e processing J_1B_NFE_XML_IN_TAB (Function Module) batch NF-e processing The inbound interfaces can process any of the following message types: 1) 2) 3) 4) 5) 6) 7) SEFAZ authorization of an NF-e SEFAZ rejection of an NF-e SEFAZ denial of an NF-e SEFAZ authorization to cancel an authorized NF-e SEFAZ authorization to cancel a rejected NF-e SEFAZ rejection of a request for authorization to cancel an authorized NF-e SEFAZ rejection of a request for authorization to cancel a rejected NF-e
Protocol number, SEFAZ status code, and the message type are mandatory importing parameters. In addition, the access key of the NF-e or alternatively the SAP internal NF-e document number (if the NF-e was created by the SAP backend, the internal document number is in stored in the random-number field of the access key) must be passed to the backend.
6.3
The backend expects a unique code identifying the type of inbound message. These codes are defined in the backend. The supported message types and their respective codes are: Message code 1 2 3 4 5 6 7 Message type Authorization of NF-e Rejection of NF-e Denial of NF-e Authorization to Cancel an Authorized NF-e Authorization to Cancel a Rejected NF-e (Skipping) Rejection of a Request for Cancellation Rejection of a Request for Skipping
6.4
Backend Control
Important: with the current solution, the backend assumes an NF-e message has reached the authorities once it has successfully been sent to the messaging system. The messaging system must not change the content of the message. This would lead to an inconsistency of data between the backend and SEFAZ. Neither should the messaging system switch an NF-e received from the backend to contingency.
6.5
Messaging-System Control
The messaging system can activate and deactivate contingency in the backend on business-place level. 2008 SAP Dietmar-Hopp Allee 16 D-69190 Walldorf Version: 2.0 Date: 2007/09/17 Page 17 of 22
This is possible via the remote-enabled function module J_1B_NFE_CONTINGENCY_SET. In the interface, the messaging system must specify the fields LAND1, BUKRS, and BRANCH. The field REGIO must remain initial. The messaging system may select or deselect the indicator AS_OUT. This indicator is interpreted by the backend. If it is set, the backend switches to contingency for any subsequent NF-e posting. The indicator can be automatically deactivated through the messaging system or manually by a user with the required authorization profile. IMPORTANT: If the function module J_1B_NFE_CONTINGENCY_SET is called remotely by the messaging system, the importing parameter IV_FIRE_COMMIT must be set to X.
Page 18 of 22
7
7.1
Appendix
Example Coding for BAdI Method CALL_RSNAST00
When during the BADI process error occurs, the messages are written in the error log and can be controlled with the report J_1BNFE_MONITOR.
7.2
Routine 901
Create a new Data Transport Routine, e.g., with the routine no. 901 and the description NF split by NFtype Copy the following source code into the routine and activate the source code.
* Header data * VBRK-xxxxx = ............
Page 19 of 22
* Item data * VBRP-xxxxx = ............ * Additional split criteria DATA: BEGIN OF ZUK, MODUL(3) VALUE '901', VTWEG LIKE VBAK-VTWEG, SPART LIKE VBAK-SPART,1 VSTEL lIKE VBAP-VSTEL, CONTING type j_1bcontingency, NFTYPE type J_1BNFTYPE, END OF ZUK. DATA: lv_branch type J_1BBRANC_, lv_bukrs type bukrs, lv_werks type werks, lv_werks_d type WERKS_d, lv_branch_address type sadr, lv_conting type j_1bcontingency, lv_vgbel type vgbel, lv_vgpos type vgpos, lv_vstel type vstel. ZUK-SPART = VBAK-SPART. ZUK-VTWEG = VBAK-VTWEG. ZUK-VSTEL = VBAP-VSTEL. * Identify the plant lv_werks = vbap-werks. if not likp-werks is initial. lv_werks = likp-werks. endif. if not lips-werks is initial. lv_werks = lips-werks. endif. if lv_werks is initial. raise ERROR. endif. * Identify the shipping point lv_vstel = likp-vstel. if lv_vstel is initial. lv_vstel = vbap-vstel. endif. * Identify the previous doc and posnr lv_vgbel = LIPS-VBELN. lv_vgpos = LIPS-posnr. if lv_vgbel is initial and lv_vgpos is initial. lv_vgbel = vbap-VBELN. lv_vgpos = vbap-posnr. endif. if lv_vgpos is initial or lv_vgbel is initial. raise ERROR. endif.
Page 20 of 22
CALL FUNCTION 'J_1B_BRANCH_DETERMINE' EXPORTING plant = lv_werks IMPORTING branch = lv_branch EXCEPTIONS branch_not_found = 01 plant_not_found = 02 valuation_area_not_found = 03 company_not_found = 04. IF not sy-subrc is initial. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. lv_werks_d = lv_werks. CALL FUNCTION 'DETERMIN_BWKEY_BUKRS_FOR_PLANT' EXPORTING werk = lv_werks_d IMPORTING bukrs = lv_bukrs. CALL FUNCTION 'J_1BREAD_BRANCH_DATA' EXPORTING branch = lv_branch bukrs = lv_bukrs IMPORTING address = lv_branch_address BRANCH_DATA = CGC_NUMBER = ADDRESS1 = TABLES ET_ADR6 = EXCEPTIONS branch_not_found = 1 address_not_found = 2 company_not_found = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. call function 'J_1B_SD_NFTYPE_DET' exporting iv_bukrs = lv_bukrs iv_branch = lv_branch iv_vstel = lv_vstel iv_country = lv_branch_address-land1 iv_regio = lv_branch_address-regio iv_auart = vbak-auart iv_vgbel = lv_vgbel iv_vgpos = lv_vgpos is_vbak = vbak is_vbap = vbap is_lips = lips
* * * * *
Page 21 of 22
if sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif. VBRK-ZUKRI = ZUK.
Page 22 of 22