Skip to Content

Deleting or omitting Special characters in PI mapping

Hello ,

My scenario is , SAP ECC to legacy , ie. IDOC --> XI/PI -BPM --> Legacy(XML) ,

here in Idoc we have a field which gives has a special character '§' which I need to remove this before it goes out from PI.

how to handle this , Is there a best way to do?

Note : From legacy they can handle other character but legacy system could not accept this char.

Regards,

Sethu.

Add comment
10|10000 characters needed characters exceeded

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Feb 01, 2012 at 06:52 PM

    you can easily use "replaceString " in graphical mapping.

    Or if it is standard IDOC then in ECC you can implement some USER EXIT to replace special character.

    Regards

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 01, 2012 at 06:53 PM

    Create UDF and Use replace string method as below or use standard function

    Example

    String str ="HelloWorld$";
    str.replace('$' , '');

    Refer this link too...

    http://www.javadeveloper.co.in/java-example/java-string-replace-example.html

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 01, 2012 at 08:06 PM

    Hi, you can write a Java or XSL mapping which recursively loops through all text nodes and replaces the undesired characters. Run this mapping program after your initial (probably graphical) mapping program in interface determination. This is an elegant approach since you do not have to apply an UDF or replace logic for each and every node in the mapping program. Once the separate mapping program is added, it will take care of replacements in all text nodes.

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Sethu,

      here is the java mapping code to meet your requirement. I assumed you are working on PI 7.1 or above versions.

      The java mapping code pattern,associated library files and compilation enviornment are different in PI7.0 and lower versions.

      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.InputStream;
      import java.io.OutputStream;
      import java.util.Map;
      
      
      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;
      
      
      public class RemoveSpecialChar extends AbstractTransformation {
      
      	/**
      	 * @param args
      	 */
      	
      
      	public void execute(InputStream in, OutputStream out)
      			throws StreamTransformationException {
      		// TODO Auto-generated method stub
      		try
      		{
      			byte b[]=new byte[in.available()];
      			String encoding="UTF-8";
      			in.read(b);
      			String inputXML=new String(b);
      			inputXML=inputXML.replaceAll("§","");
      			out.write(inputXML.getBytes(encoding));
      		}	
      		catch(Exception e)
      		{
      			throw new StreamTransformationException(e.getCause().toString());
      		}	
      		
      	}
      
      	public void setParameter(Map arg0) {
      		// TODO Auto-generated method stub
      		
      	}
      	public static void main(String[] args) {
      		// TODO Auto-generated method stub
      		try{
      			RemoveSpecialChar genFormat=new RemoveSpecialChar();
      			FileInputStream in=new FileInputStream("C:\Apps\my folder\sdn\qmark.xml");
      			FileOutputStream out=new FileOutputStream("C:\Apps\my folder\sdn\qmark1.xml");
      			genFormat.execute(in,out);
      			}
      			catch(Exception e)
      			{
      			e.printStackTrace();
      			}
      	}
      
      	public void transform(TransformationInput arg0, TransformationOutput arg1)
      			throws StreamTransformationException {
      	 this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
      		
      	}
      }
      
      
      

      you need to use this mapping before message goes out of PI server.

      You can consult following articles for further help on java mapping

      http://wiki.sdn.sap.com/wiki/display/XI/BeginnersguidetoJavamappingusingDOMparserinSAPXI

      http://www.saptechnical.com/Tutorials/XI/Mapping/Index.htm

      regards

      Anupam