on 05-27-2006 4:13 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
}
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
77 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.