Skip to Content

Introduction:

      Sender channel picks the dummy sender XML file from FTP and then it takes the currency exchange rate through URL  then send it to PI and update in SAP.

Objective:


                This document is describe the step by step process of maintain the exchange rate information in SAP system.


Process Flow:

currex.JPG

Source System File – Structure


Source System ECC – Structure


Target System SAP- Structure

/wp-content/uploads/2013/12/fdfd_jpg_342228.png

PI Configuration:


Step to create ESR Configurations:


Step1

                Go to menu  object->New, select Namespace, it should start with urn:  and next word should be relevant to the interface project.


Step2

                Create data type and enter the name of the type and select namespace and software component version.


Step3

                Select Add symbol below and insert the elements and define the data type.


Step4

                Need to import the RFC, which is created in ECC side, right click the imported objects and select import of SAP Objects.

Enter the SAP system details with user name and password, click next.

Select the correct RFC name and click finish.  It import the structure of the RFC .

Step5

                Create message type for source and target data type


Step6

                Create service interfaces for outbound and inbound


Step7

                Create imported archive and select the correct jar file, which handle the java mapping of the URL.                                  


Step8

                Create the operation mapping and select the correct inbound and outbound service interface, in mapping program select the correct java mapping file.


Step to create ID Configurations:



Step1

                Create configuration scenario, in menu New -> object set the name as P_RFC for group the all ID objects.


Step2

                Create business component for source and target system

Step3

                In business component select the service interface which is created in ESR.


Step4

                Create the dummy sender communication channel


Step5

                Create the receiver communication channel for RFC:


Step6

                Create interface determination and assign Operation mapping, which is created in ESR.


Step7

                Create receiver determination and link the source and target system.


Step8

                Create sender agreement and assign the sender file communication channel.


Step9

                Create receiver agreement and assign the receiver communication channel.




Code Appendix for Java Mapping:


package com.sap.pi.httpcall;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.StringReader;

import java.net.MalformedURLException;

import java.net.URL;

import java.net.URLConnection;

import java.text.Format;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Date;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

import org.xml.sax.InputSource;

import org.xml.sax.SAXException;

import com.sap.pi.dto.CurrencyStatus;

public class HttpCall {

          

                public static void main(String[] args) throws IOException {

                                System.out.println(“coming”);

                                HttpCall callUrl= new HttpCall();

                                callUrl.readUrl();

                }

          

                public ArrayList<CurrencyStatus> readUrl()

                {

                                ArrayList<CurrencyStatus> currencyArr = new ArrayList<CurrencyStatus>();

                                try

                                {

                                int len=0;

                                CurrencyStatus currency=null;                  

                                String content=””,allContent=””;

                                URL url= new URL(” ****.xml“);

                                URLConnection connection = url.openConnection();

                                len=connection.getContentLength();

                                System.out.println(“coming1  “+len);

                                if(len>0)

                                {

                                                BufferedReader  input = new BufferedReader(new InputStreamReader(connection.getInputStream()));

                                                while((content=input.readLine())!=null)

                                                {                                                             

                                                                allContent += content;

                                                }

                                                input.close();

                                                System.out.println(allContent);

                                                currencyArr = this.xmlToTable(allContent);

                                                System.out.println(“Currency Arr length  “+currencyArr.size());

                                }else{

                                                System.out.println(“Content not available”);

                                }

                                }catch(IOException e)

                                {

                                                e.printStackTrace();

                                }

                                return currencyArr;

                }

          

                private ArrayList<CurrencyStatus> xmlToTable(String xmlValue)

                {

                                Document doc=null;

                                CurrencyStatus currency = null;

                                ArrayList<CurrencyStatus> currencyArr = new ArrayList<CurrencyStatus>();

                                try

                                {

                                                doc = this.strToDocument(xmlValue);

                                                NodeList nodeList =doc.getElementsByTagName(“item”);

                                                System.out.println(“item node length”+nodeList.getLength());

                                                for(int i=0;i<nodeList.getLength();i++)

                                                {

                                                                currency = new CurrencyStatus();

                                                                Node node=nodeList.item(i);

                                                                if (node.getNodeType() == Node.ELEMENT_NODE) {

                                                                                //Get title element

                                                                                Element element = (Element) node;

                                                                                NodeList nodelist = element.getElementsByTagName(“title”);

                                                                                if(nodelist.getLength()>0)

                                                                                {

                                                                                                Element element1 = (Element) nodelist.item(0);                                                                                             

                                                                                                //System.out.print(“title : ” + element1.getChildNodes().item(0).getNodeValue());

                                                                                                currency.setTitle(element1.getChildNodes().item(0).getNodeValue());

                                                                                }

                                                                                //Get like element

                                                                                Element element2 = (Element) node;

                                                                                NodeList nodelist1 = element2.getElementsByTagName(“link”);

                                                                                if(nodelist1.getLength()>0)

                                                                                {

                                                                                                Element element3 = (Element) nodelist1.item(0);

                                                                                                currency.setLink(element3.getChildNodes().item(0).getNodeValue());

                                                                                                //System.out.print(”    link : ” + element3.getChildNodes().item(0).getNodeValue());

                                                                                }

                                                                                //Get guid element

                                                                                Element element4 = (Element) node;

                                                                                NodeList nodelist2 = element4.getElementsByTagName(“guid”);

                                                                                if(nodelist2.getLength()>0)

                                                                                {

                                                                                                Element element5 = (Element) nodelist2.item(0);

                                                                                                currency.setGuid(element5.getChildNodes().item(0).getNodeValue());

                                                                                                //System.out.print(”   guid : ” + element5.getChildNodes().item(0).getNodeValue());

                                                                                }

                                                                                //Get pubDate element

                                                                                Element element6 = (Element) node;

                                                                                NodeList nodelist3 = element6.getElementsByTagName(“pubDate”);

                                                                                if(nodelist3.getLength()>0)

                                                                                {

                                                                                                Element element7 = (Element) nodelist3.item(0);

                                                                                                //currency.setPubDate(element7.getChildNodes().item(0).getNodeValue());

                                                                                                Format formatter1 = new SimpleDateFormat(“E, dd MMM yyyy HH:mm:ss Z”);

                                                                                                Format formatter = new SimpleDateFormat(“yyyyMMdd”);

                                                                                                currency.setPubDate(formatter.format((Date)formatter1.parseObject(element7.getChildNodes().item(0).getNodeValue())));

                                                                                            

                                                                                                //System.out.print(” pubDate : ” + element7.getChildNodes().item(0).getNodeValue());

                                                                                }

                                                                                //Get description element

                                                                                Element element8 = (Element) node;

                                                                                NodeList nodelist4 = element8.getElementsByTagName(“description”);

                                                                                if(nodelist4.getLength()>0)

                                                                                {

                                                                                                Element element9 = (Element) nodelist4.item(0);

                                                                                                currency.setDescription(element9.getChildNodes().item(0).getNodeValue());

                                                                                                //System.out.print(”  description : ” + element9.getChildNodes().item(0).getNodeValue());

                                                                                }

                                                                                //Get category element

                                                                                Element element10 = (Element) node;

                                                                                NodeList nodelist5 = element10.getElementsByTagName(“category”);

                                                                                if(nodelist5.getLength()>0)

                                                                                { 

                                                                                                Element element11 = (Element) nodelist5.item(0);

                                                                                                currency.setCategory(element11.getChildNodes().item(0).getNodeValue());

                                                                                                //System.out.println(”   category : ” + element11.getChildNodes().item(0).getNodeValue());

                                                                                }

                                                                                currencyArr.add(currency);

                                                                }                                                             

                                                }

                                }catch(Exception e)

                                {

                                                System.out.println(e.getMessage());

                                }

                                return currencyArr;

                }

          

                public Document strToDocument(String xmlVal)

                {

                                Document doc=null;                      

                                try

                                {

                                                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

                                    DocumentBuilder builder = factory.newDocumentBuilder();

                                    InputSource is = new InputSource(new StringReader(xmlVal));

                                    doc = builder.parse(is);                                            

                                }catch(IOException e)

                                {

                                                e.printStackTrace();

                                } catch (SAXException e) {

                                                e.printStackTrace();

                                } catch (ParserConfigurationException e) {

                                                e.printStackTrace();

                                }

                                return doc;

                }

}

package com.sap.pi.httpcall;

import java.util.ArrayList;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

import com.sap.pi.dto.CurrencyStatus;

public class HttpCallMapping extends AbstractTransformation {

                /**

                 * @param args

                 */         

                @Override

                public void transform(TransformationInput in, TransformationOutput out)

                                                throws StreamTransformationException {

                                ArrayList<CurrencyStatus> currencyArr = new ArrayList<CurrencyStatus>();

                                StringBuilder xmlValue = new StringBuilder();

                                String rate = “”;

                                try

                                {

                                getTrace().addInfo(“JAVA Mapping is Initiated”);

                                HttpCall call = new HttpCall();

                                currencyArr = call.readUrl();

                                xmlValue.append(“<?xml version=\”1.0\” encoding=\”UTF-8\”?><ns0:ZGTFI xmlns:ns0=\”urn:sap-com:document:sap:rfc:functions\”> <GT_TCURR>”);

                                for (CurrencyStatus currencyStatus : currencyArr) {

                                                xmlValue.append(“<item>”);

                                                xmlValue.append(“<KURST>M</KURST>”);

                                                xmlValue.append(“<FCURR>”+currencyStatus.getTitle().substring(4,currencyStatus.getTitle().length())+”</FCURR>”);

                                                xmlValue.append(“<TCURR>”+currencyStatus.getTitle().substring(0,3)+”</TCURR>”);

                                                xmlValue.append(“<GDATU>”+currencyStatus.getPubDate()+”</GDATU>”);

                                                rate = currencyStatus.getDescription().substring(currencyStatus.getDescription().indexOf(“= “)+1,currencyStatus.getDescription().length());

                                                rate =rate.trim().substring(0,rate.trim().indexOf(” “));

                                                //this code should remove

                                                if(rate.length()>9)

                                                {

                                                                rate = rate.substring(0,4);

                                                }

                                                xmlValue.append(“<UKURS>”+rate+”</UKURS>”);

                                                //xmlValue.append(“<description>”+currencyStatus.getDescription()+”</description>”);

                                                xmlValue.append(“<FFACT>1</FFACT>”);

                                                xmlValue.append(“<TFACT>1</TFACT>”);

                                                xmlValue.append(“</item>”);

                                }

                                xmlValue.append(“</GT_TCURR></ns0:ZGTFI>”);

                                out.getOutputPayload().getOutputStream().write(xmlValue.toString().getBytes(“UTF-8”));

                                }catch(Exception e)

                                {

                                                getTrace().addWarning(“Error in Mapping “, e);

                                }

                          

                }

}





To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Felipe Rodriguez

    Hi Monikandan, thanks for your blog, very intersting, but  i’m struggling to find out where the com.sap.pi.dto.CurrencyStatus JAR file is located, do you know where or how can i get the JAR?

    thanks!

    (0) 

Leave a Reply