cancel
Showing results for 
Search instead for 
Did you mean: 

payload containing "&" in many fields

Former Member
0 Kudos

hi experts,

I have got a payload, which has got the character "&" in many fields,and that needs to be replaced with any other caharcter to make the payload suitable to work with in the integration engine.

please suggest possible solutions to my problem.

Thank you,

Shreya.

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Shreya,

here you can write a simple User defined function in mapping to replace all '&' with character of your choice. Below I have written a simple java code to do so . The name of the UDF is function. For input "&g&jo" it gives output "ANDgANDjo". You can change the value of string replaceWith with any value of your choice. Then you will obtain the desired output. This UDF has to be put in every mapping to target xml message.

public class replaceChars {

public static String function(String s)

{

try

{

int i;

char r='&';

String replaceWith="AND";

String d="";

for(i=0;i<s.length();++i)

{

if(s.charAt(i)==r)

{

d+=replaceWith;

continue;

}

else

{

d+=s.charAt(i);

}

}

s=d;

}

catch(Exception e)

{

e.printStackTrace();

}

return s;

}

public static void main(String[] args) {

String s="&g&jo";

System.out.println(function(s));

}

}

regards

Anupam

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi ,

If the source system is ECC and the payload is either an Idoc or RFC, then the special characters can be handled by making your RFC destination at the Sender side (ECC) as Unicode compatible as follows.

SM59>R3 connections> RFC destination> Special options tab> check the checkbox for Unicode.

If not the case mentioned above, follow this SDN guide:

[http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42]

Regards,

Kalpana.

Former Member
0 Kudos

Hi,

You have possible to write the UDF to convert the Ampersend chacter to other chacter.

Thank you,

Sateesh

stefan_grube
Active Contributor
0 Kudos

> You have possible to write the UDF to convert the Ampersend chacter to other chacter.

A UDF will not work, as an & makes the XML invalid and the graphical mapping work will reject the payload.

Former Member
0 Kudos

hi,

yes i need to convert the "&" character to some other character.

Can you pls sugegst the possible code to do this conversion

Shreya

stefan_grube
Active Contributor
0 Kudos

> yes i need to convert the "&" character to some other character.

> Can you pls sugegst the possible code to do this conversion

This has been provided in the other replies to your thread already.

Former Member
0 Kudos

Hi,

As Stefen explained clearly u cannot achieve this just with a UDF.

To solve this problem i have 3 options...

1.Ask the source file provider to change the & to &amp; and send the payload to the PI/XI.

2.Use an adapter module to convert the incoming message to proper format and sent to Integration engine(I dont recommend this)

3.Use an Java mapping to convert the incoming message to proper format.

Now step by step review which is best possible for u..

Now if u want to for 3 option search for java mapping and check for the code to convert the characters.

If u cannot find let us know any1 here wil provide the code

Here is the method in Java mapping u need to incorporate


static String stringFormat(String str) {
		str = str.replace("&", "&amp;");
		str = str.replace("'", "&apos;");
		str = str.replace("<", "&lt;");
		str = str.replace(">", "&gt;");
		str = str.replace("\"", "&quot;");
		return str;
	}

Babu

Edited by: hlbabu123 on Jan 3, 2011 4:09 PM

Former Member
0 Kudos
Former Member
0 Kudos

Hi Shreya,

This is how you can handle & in your incoming message:

http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/9420 [original link is broken] [original link is broken] [original link is broken]

Regards, Gaurav.

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

For XML escape characters, they need to be encoded as specified in this link:

http://xmmssc-www.star.le.ac.uk/SAS/xmmsas_20070308_1802/doc/param/node24.html

Now, there are two approaches to your problem:

1. Request to the sending system that they encode the escape characters

or

2. You use Java Mapping to find/replace these characters so that the XML gets displayed correctly in IE.

Hope this helps,

Mark