cancel
Showing results for 
Search instead for 
Did you mean: 

special characters from payload

former_member452321
Participant
0 Kudos


Hi

We are getting sometimes various specail characters in payload coming from idoc as source in different fields . Is there anyway we can remove these special characters in payload without applying to  individual field

Thanks

Mahesh

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Mahesh,

use a java mapping to remove special characters. below code will replace all the special characters you provide in the check string array with a null value.

public class REPLACESC implements StreamTransformation {

private AbstractTrace trace = null;

private Map param = null;
String  inputFileName;


public void setParameter(Map param) {
  this.param = param;
  if (param == null) {
   this.param = new HashMap();
  }
}
   


     public void execute(InputStream in, OutputStream out)
               throws StreamTransformationException {
      trace = (AbstractTrace) param.get(StreamTransformationConstants.MAPPING_TRACE);
   trace.addWarning("JAVA Mapping Start");
  
   /*this block of code will remove all the not allowed special characters from outbound xml*/
          try
          {
               byte b[]=new byte[in.available()];
               String encoding="UTF-8";
               in.read(b);
               String inputXML=new String(b);
                
              
        
               String[] check = { "]", "&", "<", ">", """, ",", "#", "\\$", "@", "\\[", "\\)"};
               for (int i = 0; i < check.length; i++) {
             inputXML=inputXML.replaceAll(check[i],"");
               }
               out.write(inputXML.getBytes(encoding));
          }    
          catch(Exception e)
          {
               throw new StreamTransformationException(e.getCause().toString());
          }  
         
        
     }
   

     public void transform(TransformationInput arg0, TransformationOutput arg1)
               throws StreamTransformationException {
      this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
         
     }
}

you can also use an excel file to store special characters and do a file lookup if the number of special characters are not fixed. let me know if you want to use this option , i will share the code.

former_member452321
Participant
0 Kudos

Thank u. The no of special characters are not fixed. We are getting the data with the specail characters as below in different fields coming from idoc as source and receiver side SOAP .Where should I apply udf ?

879234530�A.ï

849031B?Â

9453070� kaON

1Â TVERCDSAÂ AVEÂ BLDGÂ 47599

1040Â NOUTHÂ KITAÂ RD 

537879020Ã?Â

Thank for your help

Former Member
0 Kudos

Hello,

I can see some french characters like Â, so are u sure u really want to delete these characters from ur data?

Technically speaking ur receiver should accept the data in the format which is coming from SAP becuase if u delete these special characters then u are actully truncating the values which is not right?

Thanks

Amit Srivastava

Former Member
0 Kudos

The above code I shared will check the whole Idoc for special characters you hard coded and replace it with null value.

This is not a udf, you have to create a java map using imported archive and apply it in operation mapping before message mapping...follow the link shared by Hareesh above on how to create a java map.

Let me know if you have any questions!!

Thanks

Navneet.

nabendu_sen
Active Contributor
0 Kudos

Hi Mahesh,

You can check the Java Mapping code of in the below thread:

If you want to handle this field basis, you can go for Standard Function replaceString().

Regards,

Nabendu.

anupam_ghosh2
Active Contributor
0 Kudos

Thanks for mentioning me in the thread.

former_member452321
Participant
0 Kudos

HI Anupam,

Could u please give step by step details to use your mapping . I need to apply for it payload not individaul field for removing different special characters.What arguments we need to pass to this udf  etc...? and mapping ???  Thanks for your help.

former_member184720
Active Contributor
0 Kudos

In your interface mapping you need to add this java class as first step and then your existing graphical mapping.

former_member184720
Active Contributor
0 Kudos

Possible options :

former_member452321
Participant
0 Kudos

Thank u Harish. Please let me know where should i use this map to apply for whole payload

sender - IDOC - Receiver side -SOAP

nabendu_sen
Active Contributor
0 Kudos

Hi Mahesh,

You can use / call before your Message Mapping in Operation Mapping steps.

If you want to use Java Mapping compiled outside of PI with other tools like Eclipse / Netbeans etc., follow below:

Otherwise you can check the below to write code directly in ESR:

Regards,

Nabendu.