cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping

Former Member
0 Kudos

Hi

I am getting a field from SAP with 18digits (Alphanumeric). I want to send 8 characters only to a File with the help of XI. So my requirement is if it is numeric then I want the last 8 digits only else if it is character then the first 8 characters only.

I know that with the help of substring function we can take the first or last 8 characters. But how to check the condition whether it is numeric or character? If we want to write a function can you please let me know the code to resolve my issue?

Regards,

---Satish

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Satish,

You do not need import any thing, it just should work as is.

p.s.

you may need to change

int i = Integer.parseInt(a.trim());

line to

double i = Double.parseDouble(a.trim());

just in case your nmber is too large and out of range.

But anyway, it should work as is.

Answers (3)

Answers (3)

moorthy
Active Contributor
0 Kudos

Hi Satish,

Try with Regular Expressions of Java Util Package.

Examples -

http://java.sun.com/developer/technicalArticles/releases/1.4regex/

http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html

Hope this helps,

Regards,

Moorthy

MichalKrawczyk
Active Contributor
0 Kudos

hi,

are the rest of the values white spaces?

if so you can use standard trim function

if not maybe you can just check if the first

value (via substring) belongs to 0-9

(simple user defined function)

and if so <b>then</b> substring first 8

<b>if not</b> then substring last 8 ?

Regards,

michal

-


<a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>

Former Member
0 Kudos

Michal

No the rest of values are not white spaces. So I have to use a user defined function with substring. Can you tell me what I have to specify in the user defined function or what I have to write.

Thanks in advance for your time and help....

Regards,

---Satish

Former Member
0 Kudos

see if this help:

public String SDNHelp(String a,Container container){

boolean isInteger = false;

try{

int i = Integer.parseInt(a.trim());

isInteger = true;

}

catch(NumberFormatException e){

isInteger = false;

}

String ret = "";

if(isInteger){

ret = a.substring(10);

}

else{

ret = a.substring(0,8);

}

return ret;

}

Former Member
0 Kudos

Wgao

Thanks for your reply. I have created a userdefined function "test" and copied the code which was given by you. Also after I created the user defined function in the imports box I have specified java.lang.Object;(suffixed with a semicolon). After this I have saved and used the function. But it throws the below error:

/usr/sap/JXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapfc73c1b0efd811da9e2d001125a6cdc6/source/com/sap/xi/tf/_Test1_.java:517: 'class' or 'interface' expected public static void main(String[] args) throws Exception{/!_$ClNRep_/_Test1_ st = new /!_$ClNRep_/_Test1_(); st.testExecute(); }

Can you help me out in troubleshotting this issue.

Regards,

---Satish

Former Member
0 Kudos

Hi,

I think u can use a user defined function and test with the ascii value of the first character if its a character or numeric.

regards

jithesh