cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle special characters in NWDI

Former Member
0 Kudos

Dear All

I am trying to update the Description from JSP form. Through JCO we are calling the RFC of ABAP. We are passing these description from Java to RFC of ABAP and this RFC update the text in Database.

We have noticed that if there is some special character in description like as : š or ž, complete description is not getting updated in to the SAP database.

Can anyone help me how to handle these special characters in Java. There may be N number of special characters. We want to generalize it. We want to replace these characters by s and z respectively.

For example : We want to update this description.

APPLERR H'4301 H'FA03 H'254C na Zagreb TC4 riješen je cleaning procedurom, te je i kroz CSR odgovoreno da trap korekcija N01TCADG-0052 u bloku UPDC više nije potrebna, te se može izbaciti (AP143).

Uspješno su završene HR17/CN-A3 FOA-e na tranzitnom nivou, te slijedi roll-out u dva termina 12/13.04 i 19/20.04. ETK je na sastanku isporučio SW, te ALEX i mini PLEX za sve objekte.

AP147. Poslati finalnu dokumentaciju za uvođenje paketa (implementacijsku instrukciju i sve popratne datoteke).

WHile updated text is as follows :

APPLERR H'4301 H'FA03 H'254C na Zagreb TC4 rije

N01TCADG-0052 u bloku UPDC vi

Uspje

sastanku isporu

AP147. Poslati finalnu dokumentaciju za uvo

Regards

Bhavishya

Accepted Solutions (0)

Answers (3)

Answers (3)

Sigiswald
Contributor
0 Kudos

Hi Bhavishya,

Apparently your SAP database isn't configured to support Unicode. That would be the first solution to your problem, but I can imagine it's a bit drastic to convert your DB.

A second solution would be to encode the input description to ASCII before storing it in the database. When reading from the database, decode again to Unicode. This way, no information is lost. A suitable encoding would be Base64. e.g.


String description = "šunday žebra";
String descriptionBase64 = new sun.misc.BASE64Encoder().encode(
  description.getBytes("UTF-8")); // ""
// store descriptionBase64 in the DB
// later, when reading descriptionBase64 from the DB
String description2 = new String(
  new sun.misc.BASE64Decoder().decodeBuffer(descriptionBase64), "UTF-8");

Instead of using Sun's implementation, a better alternative is to use the open source implementation

org.apache.commons.codec.binary.Base64

from Commons Codec .

The 3rd approach is indeed to normalize the description by replacing all special characters with their ASCII equivalent. A rather easy solution is as follows:


String description = "šunday žebra";
String descriptionNormalized = sun.text.Normalizer.normalize(
  description, sun.text.Normalizer.DECOMP, 0).replaceAll(
  "[^p{ASCII}]", "");

sun.text.Normalizer

decomposes the string, e.g. "éàî" becomes "e´a`i^", after which non-ASCII characters are being removed using a regular expression.

Again, note that it's usually a bad idea to use sun.* packages, see <a href="http://java.sun.com/products/jdk/faq/faq-sun-packages.html">note about sun.* packages</a>. The above code only works with J2SE 1.4 and J2SE 5.0, but it breaks in J2SE 6.0 (where

java.text.Normalizer

became part of the public API ;-). A good open source implementation can be found here: <a href="http://icu-project.org/">ICU4J</a> (

com.ibm.icu.text.Normalizer

).

Kind regards,

/Sigiswald

Former Member
0 Kudos

HI

good

go through this link,hope this ll help you to solve your problem

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/63f2052e-0c01-0010-b9a2-e1f...

thanks

mrutyun^

Former Member
0 Kudos

Hi,

i have replaced (ž) character like this (z')...

only the character within this means <b>a' to z' or A' to Z'</b> we can make an array and replace it with normal character.

Hope you understood what i am coming to say.

Regards,

Beevin

Former Member
0 Kudos

Hi,

java cade


String s="šunday žebra";
s=s.replace("š","s");
s=s.replace("ž","z");

after this two stmt String s will contain sunday zebra

Regards,

Beevin.

Former Member
0 Kudos

Dear Josheph

Thanks for your reply.

I was already aware of this solution. But in this case we already knew the special characters. But in realtime there may be N numbers of the special characters. I want to handle all of them. I do not feel that it would be possible to handle each and every special character in such a way.

Is there any possibility to handle such cases. Or is there any standard class method which can handle it.

Best Regards

Bhavishya