Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

NFE Outbound B2B - Sending the XML to Buyer and Carrier using Enhanced Receiver Determination

Applies to: SAP GRC NFE 1.0


In this Wiki an overview how to send the NFE B2B XML to the Buyer as well as to the Carrier using Enhanced Receiver Determination is presented. The Wiki explains the relevant background as well as the required implementation steps in SAP NetWeaver Process Integration.

Update: Since SP 20 the logic changed slightly in order to allow the carrier to be the sole message recipient. The relevant changes are highlighted in italics below.

Author(s):  Denny Schreber

Company:     cbs Corporate Business Solutions GmbH
Created on:    29.10.2010
Author(s) Bio
Denny Schreber is a senior consultant for SAP NetWeaver and a member of the Business Integration Technology team at cbs Corporate Business Solutions. He is specialized in Java and adapter development in the field of SAP NetWeaver Process Integration.

Table of Contents

1. Introduction

According to stage:Ajuste SINIEF #8, from 07/09/2010 companies which issue NF-e's have to send the NF-e XML to the Nota Fiscal receiver (Buyer - identified by the <dest> tag, within the XML) and to the carrier (logistics service provider - identified by the <transp>/<transporta> tag, within the XML). There already exists the Wiki NFE Outbound B2B - sending the XML to the carrier (dynamic configuration) that presents a solution for sending the XML via email to the carrier using dynamic configuration. In addition to this, a more generic approach using Enhanced Receiver Determination is presented in this Wiki. The aim is to automatically send the message to the Carrier if the necessary fields are populated in the XML. The solution outlined in this Wiki can only be applied for sending the NF-e (NTB2B) to the Buyer and the Carrier, because the Cancellation of a NF-e (CFB2B) does not contain the carrier CNPJ.

The following assumptions are made to enable the sending:

  • Receiver (Buyer) of the NF-e is already maintained as a valid B2B partner in the /XNFE/TB2B table
  • NF-e is only send once to the Receiver (Buyer) because the Message duplication is done on the PI layer

In the remainder of the Wiki the sending of a NF-e to the Buyer and the Carrier is presented in more detail.

2. Implementation Steps

In this section the necessary steps to implement the proposed solution are presented.

2.1. Message Mapping for the Enhanced Receiver Determination

In order to identify the relevant receivers some details from the message received from the GRC ABAP WebAS need to be extracted. The Message mapping should therefore map from the external message NTB2B_NFeToB2BReceiver from Namespace to the Message Type Receivers that can be found in Namespace in e.g. SWCV SAP BASIS 7.00 or SAP BASIS 7.10 (depending on the used PI release). An overview of the Message mapping procNFe_TO_Receivers is shown on the screenshot below.

Afterwards, the Receiver, Party and Service fields must be mapped with the relevant data. The required mappings are now explained in more detail on field level:
1) The Receiver Node must be duplicated (right mouse-click and select Duplicate Subtree
2) The first occurrence of the Receiver node is for the Buyer and should be mapped in the following way:

  • Receiver field is mapped with CNPJRec to get the node created
  • Party field should be mapped with the CNPJRec field, but the CNPJ must be translated into the correct service. In our implementation we have used the Value mapping functionality to maintain the translation in the Directory / Configuration. However, using FixValues conversion or a Lookup would work as well.
  • Service field should be mapped in the same way as the Party field.

3) The second occurrence of the Receiver node is for the Carrier. This can be implemented as follows:

  • Receiver Tag - A condition is put in place that the tag is only created if the CNPJ of the carrier exists. This involves a User-defined Function Extract Transporta CNPJ that is explained later.
    *** Update: Since SP20 it is possible to send messages solely to the carrier. In order to reflect this changes we have to amend the mapping of the receiver tag as proposed in the screenshot below. The GRC ABAP part will put the CNPJ of the carrier in the CNPJRec field when no B2B partner apart from the carrier is found. If the extracted carrier CNPJ then equals the CNPJ in the CNPJRec field it doesn't make sense to send the message twice (in most cases). Therefore, we have to suppress the second message.

  • Party field - The user defined Function Extract Transporta CNPJ is used to parse the Carrier CNPJ from the XML. The CNPJ has to be translated into the correct Party using a Value mapping, FixValues or a Lookup.
  • Service field shoulde be mapped in the same way as the Party field.

The User-defined function used in the mapping should have the following signature with the XML String (procNFeString) as input parameter:

The following additional imports (shown in white color) are required:
 A sample implementation for the extractCNPJ UDF (Carrier B2B) is shown in the code section below:

// Create return value as empty string
String carrierCNPJ = "";

// unmask (unescape) XML string
String nfeProc = xmlString.replaceAll("(<|<)", "<").
replaceAll("(>|>)", ">").replaceAll("(&|F)", "&").
replaceAll("'", "'").replaceAll(""", "\"").
replaceAll(" ", " ");

DocumentBuilderFactory factory = null;
DocumentBuilder builder = null;
Document resultDocument = null;

try {
// create a document object
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
Reader inputXML = new StringReader(nfeProc);
InputSource src = new InputSource(inputXML);
resultDocument = builder.parse(src);
NodeList testNodes = resultDocument.getElementsByTagName("transporta");
// expecting only one occurence of the transporta tag according to the Gov Schema Files
if (testNodes.getLength() > 0) {
Node testNode = testNodes.item(0);
// CNPJ is first entry
testNode = testNode.getFirstChild();
if (testNode.getLocalName().equals("CNPJ")) {
carrierCNPJ = testNode.getFirstChild().getNodeValue();
} catch (Exception e) {
throw new StreamTransformationException("Exception while trying to read CNPJ number occured. The exception is: " + e.getMessage());
return carrierCNPJ;

And that's it for the mapping. Save & Activate your changes.

2.2. Interface (Operations) Mapping

Create an Interface (Operations) Mapping named procNFe_TO_ReceiverDetermination. The source interface should be NTB2B_procNFe_OB from Namespace and the target interface ReceiverDetermination from namespace in e.g. SWCV SAP BASIS 7.00 or SAP BASIS 7.10 (depending on the used PI release). Set the Message Mapping created in section 2.1 as the one to be executed.

3. Configuration

You have to amend the Receiver Configuration, i.e. you have to set the type of the Receiver Determination to Extended and you have to choose the Interface (Operations) Mappings created in section 2.2.
Furthermore, you have to create two interface determinations (one for each receiver) and two receiver agreements (one for each receiver) with the relevant communication channels. If you already have created the interface determination and the receiver agreements for you B2B partner you can copy the existing ones and just amending the Receiver details and assigning the relevant Communication Channel to allow the sending to the carrier.
You can still use the SAP-delivered standard mapping in the interface determination, but you can still use E-Mail lookups as described in Using SAP PI Lookup API and Dynamic Configuration in SAP GRC NFE Outbound B2B Interface for Dynamic E-mail Determination.

4. Testing

The testing of this functionality requires that the relevant fields for Carrier data are correctly populated in the NFe XML. If SAP ERP is used to issue the NF-e please take care that a Vendor with type Carrier is included as Partner.

If you followed all steps you should see the message duplication on the XI/PI system as shown on the screenshot below.

A more detailed explanation how to test is available in the Wiki referenced in the Introduction.

Related Content

NFE Outbound B2B - sending the XML to the carrier (dynamic configuration)
Enhanced Receiver Determination in SAP XI
Using SAP PI Lookup API and Dynamic Configuration in SAP GRC NFE Outbound B2B Interface for Dynamic E-mail Determination

Useful Information

Sending the NFE B2B XML to the Buyer as well as to the Carrier using Enhanced Receiver Determination in XI/PI