cancel
Showing results for 
Search instead for 
Did you mean: 

JDBC to IDOC scenario with Java mapping

raviteja_satuluri
Contributor
0 Kudos

Hi Experts,

I have developed JDBC to IDOC scenario in PI 7.0.

The problem is with the special character '&'

I am getting different fields for Item, in that there is one field 'Item_description'

I am getting the input value like

<Item_Description>specification for electroless nickel plating &#x16;


When ever i got the payload from the sender system as an xml format and the value for 'Item_description" as specified above

because of special character '&' the message is failed in PI.


I am manually removing that special character from payload and again re sending then it is successfully processed to Target system.


I have decided to go for Java mapping and I have developed the code as below.

Java code:

package com.Mapping;

import java.io.InputStream;

import java.io.OutputStream;

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 Mapping_Java extends AbstractTransformation {

     public void transform(TransformationInput transformationInput,

               TransformationOutput transformationOutput)

               throws StreamTransformationException {

          try {

               InputStream inputstream = transformationInput.getInputPayload()

                         .getInputStream();

               OutputStream outputstream = transformationOutput.getOutputPayload()

                         .getOutputStream();

               byte[] b = new byte[inputstream.available()];

               inputstream.read(b);

               String strContent = new String(b);

              

               if (strContent.contains("&")) {

                    getTrace().addInfo("& is present");

  strContent = strContent.replaceAll(" ", "&");

               }

               outputstream.write(strContent.getBytes());

          } catch (Exception exception) {

               exception.printStackTrace();

          }

     }

}

The above code works for it can replace the "&" by Tab space.

I was stuck here, That I want to remove that '&' symbol only for 'Item_description' field not for remaining fields.

I hope we should write some condition for the above code to replace '&' for only that field.

Please guide me friends,

How to add that condition in that code and how to go for java mapping for PI 7.0 version.

it help full to me a lot.

Thanks in Advance,

Regards,

Teja.

Accepted Solutions (1)

Accepted Solutions (1)

raviteja_satuluri
Contributor
0 Kudos

Hi All Thanks for all your replies and Support. Finally the problem has been solved with out using Java mapping and and with out writing any UDF.

Please find the below screenshots.

Tested in Message mapping and Operation Mapping, it is success.

The message is successfully reached target.

Thanks to all

Regards,

Teja.

Answers (3)

Answers (3)

maheswarareddykonda
Active Contributor
0 Kudos

Hi Teja,

you can follow the code from below link.

and just modify the line as inputContent = inputContent.replaceAll("&", ""); 

since you are thinking to remove that special character to particular field, you can just write a udf for the same logic to that field. instead of creating java mapping

vkaushik82
Active Participant
0 Kudos

You can check for the xml tag as below and do remaining logic in then.

  if(strContent.contains("<Item_description>"))

Former Member
0 Kudos

Hi,

You can right a UDF looking for special characters. Please see below the following links should help.

Regards,

Jannus Botha