Credit: this text isn’t mine. Renan Correa wrote it for the SPED and NF-e SCN blog (https://scn.sap.com/community/portuguese/sped-and-nf-e). That blog is in Portuguese and this content is too good to miss, so I translated it. All credit goes to Renan and the SAP localization team.
Cancellation by event not finished in ERP
How do you analyze it, and where do you start?
Always start with J1BNFE, the ERP NF-e monitor.
Check the fields Required Process Step (ACTION_REQU), Document Status (DOCSTA), System Communication Status (SCSSTA) and Messaging System Status (MSSTAT). Also click the events flag to see the event status.
The status needed for each process step (authorization, cancellation and skipping) is in the ERP help: http://help.sap.com/erp2005_ehp_07/helpdata/en/e6/2d713a377e49d2a69a864c8a34c762/content.htm
To understand the cancellation process better, read on. Also, always search SAP Notes using the objects involved (function modules, tables, structures) or SAP’s automated tools such as ANST (Automated Note Search Tool).
1) NF-e inconsistent between J_1BNFE_EVENT and J_1BNFE_ACTIVE
In the case below, the document is inconsistent: the event status is “authorized” while the NF-e status is “waiting for messaging system”.
The most common cause is missing OSS Note 2029305.
The manual fix is to run function J_1B_NFE_XML_IN, simulating the cancellation authorization with these parameters:
| Parameter | Value |
|---|---|
| DOCNUM | The document number |
| AUTHCODE | SEFAZ protocol |
| AUTHDATE | SEFAZ authorization date |
| AUTHTIME | SEFAZ authorization time |
| CODE | 101 (cancellation) |
| MSGTYP | 4 (cancellation authorization) |

2) NF-e (no error or inconsistency) waiting for the GRC cancellation answer
The fix above is for when the ERP events table is out of sync with J_1BNFE_ACTIVE.
But there are error cases where both tables are in sync, both waiting for an answer from SAP NFE (GRC):

Here, check the document status in GRC. If the cancellation status is OK (01, green), run “Repeat process step”:

This function is available from SP20.
If the cancellation status was “135 – Authorized” and the “Update to ERP” step has an error (02, red), run “Continue process”:

If you’re not on SP20 and need to send the result back to ERP, run program /XNFE/PROCSTEP_EV_ERPUPDAT in SAP NF-e to resend the OK status.
These new procedures to push the GRC update back to ERP may still fail for many reasons: missing OSS Notes, modified core functions, wrong validations or a commit work in a BAdI, RFC or connection issues, and so on.
3) NF-e (no error or inconsistency) waiting for the GRC answer, but the GRC update failed
If nothing above worked, the last option is to run function J_1BNFE_EVENT_IN in ERP to simulate the process, and debug it to find out why the update fails.

You need the parameters below to run the function manually. If you don’t know how to fill them, set a breakpoint in SAP NFE (GRC) before the call to J_1BNFE_EVENT_IN and run function /XNFE/PROCSTEP_EV_ERPUPDAT. You’ll see the parameters GRC passes to ERP.

On the ERP side, J_1BNFE_EVENT_IN starts with FORM process_nfe_for_cancel_event, which checks that the cancellation was authorized and that all required data came from SAP NFE. Then it calls function J_1B_NFE_XML_IN.

J_1B_NFE_XML_IN validates the status in the active table, calls method check_subsequent_documents of BAdI CL_NFE_PRINT, and checks the accounting period.

At this point you can add business rules to check or reverse other documents that aren’t normally part of the NF-e flow.

Remember that the program also checks that the company code’s accounting period is open. The ERP cancellation logic won’t reverse a document in a closed period. Before closing, carefully check all NF statuses for documents in cancellation that weren’t reversed, to avoid tax issues and penalties (an NF canceled at SEFAZ can no longer be canceled in ERP).


4) NF-e already canceled in J_1BNFE_ACTIVE but stuck at step “2 – Cancel source document”
Often ERP passes the validations above but doesn’t finish the cancellation, and stops at this status:

Here the cancellation itself succeeded (J_1BNFE_ACTIVE was updated), but the source document (billing document, material document and so on) couldn’t be reversed.
To see why, click the J1BNFE log (red flag). If the error isn’t clear (for example “No batch input data for screen XXXX XXXX”), you can request the source document reversal (see below) and debug the cancellation to see where it fails.

The code below is part of function J_1B_NFE_CANCEL. It identifies the source document type and calls the matching reversal transaction:

To debug it, change variable lv_mode from P to A. The reversal transaction then runs on screen, and any error shows up there too.

That’s it for today, with more to come. Thanks again to Renan Correa for such good content.



Leave a Reply