In my other article about Migrating GRC NFE B2B PI Mail Interfaces from 1.0 to 10.0 I suggested an approach to migrate your existing B2B mail interfaces. However, with SAP Process Integration 7.1 onwards it is much simpler. It is still relying on the approach described by described by Henrique Pinto in his article Using SAP PI Lookup API and Dynamic Configuration in SAP GRC NFE Outbound B2B Interface for Dynamic... but you don’t have to do any lookups in PI because the email address can be pre-populated on the GRC NFE system. I don’t go into details for all preparation steps since they are already described in the aforementioned article.
SAP GRC NFE
First, you have to implement the BAdI /XNFE/EMAIL_B2B_OUT on the SAP GRC NFE ABAP system. The screenshot below shows a dummy implementation. This BAdI just writes an email address into an attachment.
In the NWDS you have to create a Java Mapping that extracts the email from the additional attachment that you created in the BAdI implementation. The example below is named AttachmentReader.java and it is designed to run as a stand-alone java mapping after the official java mapping from the PI standard content.
package sdn.sap.com.xi.nfe;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Iterator;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.Attachment;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.InputAttachments;
import com.sap.aii.mapping.api.OutputAttachments;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
/**
* This class is an PI Java Mapping which extracts the email
* from an additional attachment for Dynamic Configuration
*
* @author Denny Schreber
*/
public class AttachmentReader extends AbstractTransformation {
InputAttachments inputAttachments = null;
OutputAttachments outputAttachments = null;
DynamicConfiguration conf = null;
/**
* This method is for testing purposes only.
*/
public static void main(String[] args) throws Exception {
InputStream in = new FileInputStream("C:/Testdaten/b2b_nfe_new.xml");
OutputStream out = new FileOutputStream("C:/Testdaten/b2b_mail_out.xml");
new AttachmentReader().execute(in, out);
in.close();
out.flush();
out.close();
}
/**
* @param tf_in The incoming message
* @param tf_out The transformed message
* @return void
* @throws StreamTransformationException
*/
public void transform(TransformationInput tf_in, TransformationOutput tf_out)
throws StreamTransformationException {
inputAttachments = tf_in.getInputAttachments();
outputAttachments = tf_out.getOutputAttachments();
conf = tf_in.getDynamicConfiguration();
this.execute(tf_in.getInputPayload().getInputStream(), tf_out
.getOutputPayload().getOutputStream());
}
/**
* @param in The incoming message
* @param out The transformed message
* @return void
* @throws StreamTransformationException
*/
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
// getTrace().addInfo("JAVA Mapping Called");
Attachment attachment;
String email = "";
String aid;
if (inputAttachments.areAttachmentsAvailable()) {
Collection<String> attachments = inputAttachments.getAllContentIds(true);
Iterator<String> it = attachments.iterator();
// assuming only one attachment
while (it.hasNext()) {
aid = it.next();
attachment = inputAttachments.getAttachment(aid);
email = new String(attachment.getContent());
outputAttachments.removeAttachment(aid);
}
// Fill the dynamic configuration for the “to” field in the mail
// adapter
DynamicConfigurationKey key = DynamicConfigurationKey.create(
"http://sap.com/xi/XI/System/Mail", "THeaderTO");
conf.put(key, email);
}
// return the stream without doing anything
int c;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
while ((c = in.read()) != -1)
baos.write(c);
out.write(baos.toByteArray());
} catch (Exception e) {
throw new StreamTransformationException(e.getMessage());
}
}
}
If you have an older Support Package in your PI system take care that SAP Note 1641548 is deployed. Otherwise, the attachment with the email address will not be removed and send with your mail.
However, another (not recommended) option would be to extend the Java Mapping from the standard content. When you use the graphical mapping you can run into namespace issues which will render the NF-e xml invalid.
In the Repository, you have to import the Java Mapping under Imported Archives in your own SWCV. Then, copy the Operation Mapping NTB2B_procNFe_TO_procNFe / namespace http://sap.com/xi/NFE/006 from SWCV SAPBO SLL-NFE 10.0 into your SWCV and add the new Java Mapping as the second step after the ProxyNamespaceCleaner. (I’m assuming you have a dependency created between the SWCV). Here, you have to select the “Read Attachments” option in order to allow the Java mapping to access the attachment.
Finally, save and activate all your changes.
In the Integration Directory you have to change the generated Interface Determination and select your new mapping from your SWCV. Save and activate.
Please take care that your email communication channel has the option “Keep Attachments” under General and “Use Adapter-Specific Message Attributes” under the Advanced tab selected. Furthermore, you have to use the MessageTransformBean to rename the attachment.
In the PI monitor, you can see how the additional attachment with the mail address is removed after the mapping.
In the end, the mail recipient should get an email with the NF-e as attachment called NFe.xml.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |