cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting or omitting Special characters in PI mapping

former_member205100
Participant
0 Kudos

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.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

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.

former_member205100
Participant
0 Kudos

Hello Martin,

This approach looks good, it would be much thankfull if you let me know the step by step approach.

Im not familiar with JAVA, but if you provide some help I will complete .

Thanks , Sethu.

anupam_ghosh2
Active Contributor
0 Kudos

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

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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