Thursday, April 15, 2010

Mail adapter in SAP PI

1.XSD format for sending mails
<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions targetNamespace="" xmlns:wsdl=""><wsdl:types><xsd:schema targetNamespace="" xmlns:p0="" xmlns:xsd=""><xsd:element name="Mail"><xsd:annotation><xsd:documentation>Mail package for XI - Mail Adapter</xsd:documentation></xsd:annotation><xsd:complexType><xsd:sequence><xsd:element name="Subject" type="xsd:string" minOccurs="0"/><xsd:element name="From" type="xsd:string" minOccurs="0"/><xsd:element name="To" type="xsd:string" minOccurs="0"/><xsd:element name="Reply_To" type="xsd:string" minOccurs="0"/><xsd:element name="Content_Type" type="xsd:string" minOccurs="0"/><xsd:element name="Date" type="xsd:dateTime" minOccurs="0"/><xsd:element name="Message_ID" type="xsd:string" minOccurs="0"/><xsd:element name="X_Mailer" type="xsd:string" minOccurs="0"/><xsd:element name="Content" minOccurs="0"><xsd:annotation><xsd:documentation>any type</xsd:documentation></xsd:annotation></xsd:element></xsd:sequence><xsd:attribute name="encoding" type="xsd:string"/></xsd:complexType></xsd:element><xsd:element name="MailReceipt"><xsd:annotation><xsd:documentation>Mail Receipt for XI - Mail Adaper</xsd:documentation></xsd:annotation><xsd:complexType><xsd:sequence><xsd:element name="Server" type="xsd:string"/><xsd:element name="Format" type="xsd:string"/><xsd:element name="UseMailPackage" type="xsd:boolean"/><xsd:element name="Encoding" type="xsd:string"/><xsd:element name="Subject" type="xsd:string" minOccurs="0"/><xsd:element name="From" type="xsd:dateTime" minOccurs="0"/><xsd:element name="To" type="xsd:string" minOccurs="0"/><xsd:element name="Date" type="xsd:dateTime" minOccurs="0"/></xsd:sequence></xsd:complexType></xsd:element></xsd:schema></wsdl:types><wsdl:message name="Mail"><wsdl:part name="Mail" element="p4:Mail" xmlns:p4=""/></wsdl:message><wsdl:message name="MailReceipt"><wsdl:part name="MailReceipt" element="p4:MailReceipt" xmlns:p4=""/></wsdl:message></wsdl:definitions>
Link for way to Insert xml code in blog
2. Way to send mail using java code( with our mail adapter)
Link From wiki

Java Mail Codepackage mail.sdn;
import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.Session;import javax.mail.Transport;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;import java.util.Properties;
public class email {
public void postMail(String mailhst, String recivers, String subject, String message, String from) throws MessagingException { boolean debug = false;
Properties props = new Properties(); props.put("", mailhst); Session session = Session.getDefaultInstance(props, null); session.setDebug(debug); Message msg = new MimeMessage(session); InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); String recipients[] = recivers.split(","); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i <>
code as per pi format
Java Mapping Codepackage mail.sdn;
import;import;import java.util.Map;import java.util.Properties;
import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.Session;import javax.mail.Transport;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.transform.Transformer;import javax.xml.transform.TransformerFactory;import javax.xml.transform.dom.DOMSource;import;
import org.w3c.dom.Document;
/** * @author Santhosh.Vellingiri */public class emailjavamapping implements StreamTransformation {
public void setParameter(Map param) { Map map = param; }
public void execute(InputStream in, OutputStream out) throws {
/* Code to Send Email
email obj1 = new email(); obj1.send("", "", "Test Email", "test message from mapping", "");/*End of Email Code
/*Code to Transform the Input stream to Output
try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder();
TransformerFactory tf = TransformerFactory.newInstance(); Transformer transform = tf.newTransformer();
Document doc = db.parse(in);
DOMSource domS = new DOMSource(doc);
transform.transform((domS),new StreamResult(out)); } catch (Exception e) { System.out.print("Problem parsing the file: " + e.getMessage()); e.printStackTrace(); }}}

Email using UDF in Message Mapping.
1. Import this file as Imported Archive in Integration Repository and activate.

2. In the UDF import the package mail.sdn.*;

3. Create an Object for email class and call method send() , with the following parameters
a. Mail Host name b. Receivers (multiple receivers separated by comma)
c. Subject d. Message e. From

Code in udf
email mail = new email();
mail.send("mailhost", "to emailid", "subject", "content", "from emailid");

Java Mapping with SAX DOM parsers and testing of java mapping and UDF in IDE

Section 1:This is about how to write code using java mapping
Section 2: How to test(IDE) java code before going to use in PI
Section 3:Testing procedure to test UDF at IDE(NWDS)
Section 1:
XSD’s of source and target

sample output

Code--- Package- Import packages--DOM import;import;
import java.util.Map;import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;import;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class JavaMappingDOM implements StreamTransformation {
public void setParameter(Map arg0) { }
public void execute(InputStream inputStream, OutputStream outputStream) throws StreamTransformationException {
try { // create a DOM parser
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder(); // parse input to create document tree Document doc = builder.parse(inputStream); // transform the tree
Node orders = doc.getFirstChild(); // gets the root element NodeList children = orders.getChildNodes(); // gets children of the root
Node lastHeader = null;
for (int item = 0; item < node =" children.item(item);">
if ("Header".equals(node.getNodeName()))
{ lastHeader = node; // store reference to last Header node }
else if ("Line".equals(node.getNodeName())) {
orders.removeChild(node); // remove Line node from root
lastHeader.appendChild(node); // add Line node to last Header
} } // create transformer for producing XML output
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// create source and result wrappers and perform transformation
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(outputStream);
transformer.transform(source, result); }
catch (Exception e) { throw new StreamTransformationException("Mapping failed", e); } }
--using SAX
import;import;import;import;import java.util.Map;
import javax.xml.transform.Result;import javax.xml.transform.sax.SAXTransformerFactory;import javax.xml.transform.sax.TransformerHandler;import;
import org.xml.sax.InputSource;import org.xml.sax.XMLReader;import org.xml.sax.helpers.XMLFilterImpl;import org.xml.sax.helpers.XMLReaderFactory;
public class JavaMappingSAX implements StreamTransformation {
public void setParameter(Map arg0) { }
public void execute(InputStream inputStream, OutputStream outputStream) throws StreamTransformationException { try { // create a TransformerHandler for producing XML output SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler th = factory.newTransformerHandler(); Result result = new StreamResult(outputStream); th.setResult(result);
// create a MyFilter instance based on standard XMLReader XMLReader reader = XMLReaderFactory.createXMLReader(); XMLFilterImpl filter = new MyFilter(reader); filter.setContentHandler(th);
// parse input, filtering to produce output InputSource source = new InputSource(inputStream); filter.parse(source); } catch (Exception e) { throw new StreamTransformationException("Mapping failed", e); } }}
Section 2
Testing Code:
-->Before PI 7.1package sample;
import*;import*;import java.util.Map;
public class MyJavaMapping implements StreamTransformation {
public static void main(String[] args) { try { InputStream in = new FileInputStream(new File("in.xml")); OutputStream out = new FileOutputStream(new File("out.xml")); MyJavaMapping myMapping = new MyJavaMapping(); myMapping.execute(in, out); } catch (Exception e) { e.printStackTrace(); } }
public void setParameter(Map map) { }
public void execute(InputStream in, OutputStream out) throws StreamTransformationException { // Add your code here }}
-->PI 7.1 package sample;
public class MyJavaMapping extends AbstractTransformation{
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException { this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream()); }
public void execute(InputStream in, OutputStream out) throws StreamTransformationException { // Add your code here }
public static void main(String[] args) { try { InputStream in = new FileInputStream(new File("in.xml")); OutputStream out = new FileOutputStream(new File("out.xml")); MyJavaMapping myMapping = new MyJavaMapping(); myMapping.execute(in, out); } catch (Exception e) { e.printStackTrace(); } }}
Section 3
For PI 7.0(3.0) you need the libraries: aii_mt_rt.jar, aii_map_api.jar, aii_utilxi_misc.jar
For PI 7.1 you need the libraries:,,
Links :
Testing UDF

blog content


Correctly parsing XML using JAXP (SAX or DOM) is fairly straight-forward and familiar to many. However, correctly emitting XML is a little more complicated, and many resort to using simple String manipulation rather than using the API. This almost invariably results in difficulties with special characters such as & and < which must be escaped as & and <, respectively.
I hope to rectify this situation somewhat by providing code samples of parsing and emitting XML using both DOM and SAX in XI Java mapping programs. Although mapping programs are the context of this blog, the XML processing techniques described are equally applicable in other contexts, for instance in XI adapter modules.

Example mapping

Both the DOM and SAX mappings will be functionally identical and take an input document structured as follows:
Notice that the Header and Line elements are all children of Orders. This is what might be produced by the File/FTP adapter using Content Conversion. This will be mapped to the following structure, where each Line element has become the child of the preceding Header element:
Here is an example of a full input document and the desired mapping output.

DOM Mapping

Implementing this mapping using DOM is conceptually very simple:
1.       Parse the input into a DOM document
2.       Modify the document to achieve the desired structure
3.       Emit the changed document as XML
Parsing in DOM is extremely simple and can be done with 3 lines of code.
Modifying the structure is also quite simple. We basically iterate over the children of the Orders node, i.e. the collection of Header and Line nodes, keeping a reference to the last Header node encountered. Each Line node is then moved from its initial position as a child of Orders to be a child of the last encountered Header node.
Finally, to emit the resulting document as XML, we use a javax.xml.transform.Transformer object. This class essentially takes XML from a source and outputs it to a sink, possibly performing a transformation along the way. The transformation performed would usually be XSLT. For our purposes, we'll feed it our DOM tree as source and our OutputStream wrapped in a StreamResult as sink, and we won't have it do any actual transformation.
Complete code
Here is the complete code for the above JavaMappingDOM class.

About SAX

Below I'll show how to implement the same mapping using SAX. SAX uses a completely different programming model than DOM and may for many seem much less intuitive to use. As we saw above, a DOM parser produces a complete object tree representation of the XML input, leaving you the entire document to work with at once. A SAX parser works in an entirely different way. No object tree is created by the parser. Instead, as the parser works its way through the XML input, it fires parse events via callbacks to a ContentHandler that you have provided. Possible callbacks include startElement, characters, and endElement, which are called with appropriate parameters when the parser encounters something like:
This leaves it to your callback handler to listen for the parse events that you are interested in and take whatever action is required. Specifically, you must explicitly store all the data and state information you need since no complete representation of the document is created for you.
Most importantly, the same event-based model should be used to emit XML. In this case, your code fires the SAX events to a handler capable of emitting XML. Such a handler can be obtained as follows.
With the transformer in hand, we can create a simple XML document:
Here is the XML it generates:
...and here is the complete code of this XMLHelloWorld class:

SAX Mapping

Before showing you how to implement the mapping using SAX, I need to briefly explain the XMLFilterImpl class. Instances of this class sit between an XMLReader(basically the SAX parser) and the application and (as the name implies) filters the SAX events coming from the XMLReader before passing them on to the application. XMLFilterImpl itself is actually a non-filter - it just passes on all events unchanged. But by subclassing XMLFilterImpl and overriding the relevant methods, we can filter the SAX events to perform the desired mapping.
Filter Implementation
For the mapping example in this blog, we only need to filter the startElement and endElement events. Recall that we want to end up with the Line elements nested under their preceding Header element. This can be achieved by withholding endElement events for Header elements and outputting them only after we have parsed past the Line elements to be nested. How do we know when we have passed all the relevant Line elements? Either when we encounter the next Header start element or when we reach the Orders end element.
Below is the complete code for the MyFilter class which extends XMLFilterImpl. Notice how we call super.startElement(...) and super.endElement(...) to pass along SAX events as required.
Mapping program
Although the actual mapping work is carried out by the MyFilter class, we still need a bit of boiler-plate code in the mapping program itself, i.e. in the class which implements StreamTransformation. This class basically just connects an XMLReader to one end of MyFilter to be able to parse the XML input, connects a TransformerHandler to the other end of the filter in order to produce XML output, and starts the parser by calling the filter's parse method. Here is the source code for the mapping program.
In some forum entries I found a question about debugging Java Mapping. There are a lot of Blogs about Java Mappings like this one of Thorsten Søbirk:
Using JAXP to both parse and emit XML in XI Java mapping programs 

Now, how should you debug your code before a upload it to the XI? It is quite simple: Add a main method to your Java Mapping class.

Here is a template for a Java Mapping class with a main method:

All you have to do is placing an xml file "in.xml" in the working directory of your Java program, set a break point and start the program.
Remark: For compiling you need the library aii_map_api.jar (XI 3.0/PI 7.0) or (PI 7.1)
This is an approach for the new PI 7.1 API:
API Documentation

Working with alerts

Working with alert
/Nalertcatdef at abap stack
1.create an alert category
2.and add variable to container to used that variable to display message.
In this example, I used existence alert category( because rwb-> I did not found my alert catogry)

Then enter our required msg in short text or long text

It is very helpful to specify the container variable and abap dictionary dataype.

document Link
Rwb-> alert configuration.
Choose your alert category what u have created in sap pi ( abap stack using alertcatdef tcode)
Add rule as said in the below blog
And save

In put invalid xml in source directory, then you will get error, you can view in alert inbox in the RWB

alerts as emails( using tcodes, SU01, scott ) please lookinto fallowing url for more information

XML files as field in XSD (or) Working with CDATA

Xml file as a filed in XSD/ XML SAP XI /PI (or) Working with CDATA in xml in SAP XI/PI
Weblog: 12219
Refer ,comments by Deviprasad to find more information in the above blog

Using java mapping wiki help

Monday, April 12, 2010

Typical JDBC scenarios

Jdbc driver not supported for SAP PI
Solution: download driver from sap service market place.

DataBase huge message, handling with sap pi
1.using TOP in sql statement, 2.Transaction level is serilizable in adapter settings

Experiance with boco

1.Exlustion of files at sender side -> Mickael Huchet
2.Adapter specific message attributes ->also michal blog

3.understanding structure of the orders.order05 idoc type
fields like E1EDP01(item),and partial orders field.
Clearly explained about this from caluswaller weblog.

4.stop processing duplicate files, with help custom module

5.idoc to idoc adatper

6.FILE to iDOC -> adding logical system name to File business system
else Unable to convert Sender system to ALE logical system
also michalBlog_Relating to ALE Logical system error

7.Language convertion tool for understanding german language

8.Working with idoc acknowledgement. additional settings.
1.article on Handling idoc ack in PI with examples, errors usecases
search with PI IDOC ACK in article section.

9.Renaming FileSender
solutions with help of forum

10.Message recorded in sap xi moni.
Error due to sending message with another (Using another)client TO PI.
11.Understanding variable subtitution, Adapter modules and Dynamic configuration Bean

Sunday, April 11, 2010

SAP PI Reference

This blog is for SAP PI reference. and also concentrating on different famous users and and blogs and their topics discussed those blog. and also important source code and everything will be discussed in this blogspot.

important sdn URLS:
Home page of sdn

what is new in PI 7.1


SAP 7.1 ehp1 Technical documentation

Problem analysis guide

SAP PI mapping , How to use the Node functions.

1) Claus Wallacher : How to use Node functions, in different ways and with some examples

2) Stefan Grube : How to use pi Node functions ( covered most of all) with real time examples, testing UDF, AUDF and also java proxies and how to use sap standard modules , and trouble shooting on http, mail, soap scenarios with examples, and article on how to develop custom module with example. and so on.

3) Jin Shin :
how to use idoc scenarios( using AAE) using sender idoc adapter with help of pod cast. and various examples on mapping and usage.

4) Wiiliam Li: concentrated on various typical scenarios, how to configure adapters, with out using IR objects running scenario

5)Peter Gutsche: new in pi 7.1 ; pi 7.1 installation steps with podcast. Providing pi 7.1 reference and reference document.

6) Michal krawczyk: Every xi/ pi consultant refer his weblog in his pi journey
( covered all technical concepts in his weblogs in simple manner)

7)Shabarish Vijayakumar: Latest updates on SAP XI/PI technologies, good blogs on RFC,SOAP,FILE adapters.

8)Ale settings for SAP XI IDOC Scenarios

9)About UDDI ,SOAP,JDBC advanced Settings, Rfc, SAP XI types of errors

10)Thorsten Nordholm Søbirk : About SAP PI java mapping procedure, SAP PI tcodes

11)Siva Maranani: all basics of SAP XI

Steps to import SLD object in ESR ( No need to import sld objects in IR/esr) is telling about pi 7.1 hardware requirements and step by step installations step at your home