on 12-07-2006 11:19 AM
Using a UDF simple or advanced... you can only have input type string and output type string... Is this true?
So if this is true, then how can you make custom calculations...
can you have a string input which is number i.e. 50
and then an output as a string but numeric i.e. 80
and integer calculations inside. So you convert string to integer... do calculations, get the answer then convert the answer to a string?
Basically I am comfortable doing comparisons of strings but I would like to do scennarios which include integers and calculations.... or is this not possible in XI UDF's?
Message was edited by:
Alex Ong
Now I have changed it to this:
int one;
int two;
int result = one+two;
if (a.equals(b))
{one = 20; two = 30;}
else
{one = 50; two = 50;}
return result.toString();
And I get error:
16:04:22 Start of test
Source code has syntax error:
/usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map9bd049d0860c11dbc783000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:43: int cannot be dereferenced
return result.toString();
^
1 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex,
the problem here is in
int result = one+two;
..
return result.toString();
<b>int</b> is a basic type and not an object, so it does not have the method toString(), it has no method.
<b>Integer</b> instead is an Object, defined by Sun to "support" the basic type int
then if you want to convert an int to a String :
return new Integer(intValue).toString();
Hope it solve your doubts!
Sergio
Sergio...
Your solution worked perfctly... (As Usual...)
Are you a Java Programmer who moved into XI or XI who learnt Java?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
int cannot be dereferenced
return result.toString();
^
That doesnt mention my else statement... does it?
it is saying that int cannot be dereferenced... what does that mean?
Can someone please let me know what this is?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Try like this for simple function
int one;
int two;
if (a.equals(b)){
one = 20;
two = 30;
}
else{
one = 50;
two = 50;
}
int result = one+two;
return ""+result;
Regards,
Sai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
int cannot be dereferenced
return result.toString();
^
That doesnt mention my else statement... does it?
it is saying that int cannot be dereferenced... what does that mean?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Michal,
Sorry it returned the above error.
This is why I am confused because I have been trying different variations and most of the time I get that error message?
Why what does it mean?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Michal,
Thanks I tried it and I got the same error as above
16:06:17 Start of test
Source code has syntax error:
/usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mape05ccfb0860c11db9bb7000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:47: int cannot be dereferenced
return result.toString();
^
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I thought something like this would work but it doesn't....
int one;
int two;
int result = one+two;
if (a.equals(b))
one = 20;
two = 30;
else
one = 50;
two = 50;
return result.toString();
This is the error message I get
Source code has syntax error:
/usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map27f663f0860c11db96de000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:42: 'else' without 'if'
else
^
1 error
Message was edited by:
Alex Ong
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK fair enough... What is the difference between what they return?
Also can someone show a basic UDF where you input 2 strings... af they match then you have 2 integers which are equal to 20 and 30.
If the strings do not match then the 2 integers take on different values i.e. 50 and 100.
The result is the 2 integers added together...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is this not possible in a simple UDF? To use Integers is it mandatory to user advanced UDF's?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex,
This is the sample code
public void function(String[] value,ResultList result,Container container){
double sum=0;
for(int i=0;i<value.length;i++) {
double x=Double.parseDouble(value<i>);
sum=sum+x;
}
result.addValue(""+sum);
}
Regards.
Sai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alex,
Yes, all inputs and outputs from the UDF's are always Strings.
Inside the UDF, you would need to convert the Strings into Integers / Numbers using methofs like (Integer.parseInt() ) etc. , do the maniuplations needed and then convert the number to String using .toString()
Even if the output is String, and the element to which it is assigned is an Integrer, it does not matter as the validation against the datatype is not done at the mapping and as long as it is a number, the target system will also not have an issue.
The point of ensuring and checking whther the data is a number or not lies with the UDF coder if needed or with the application system as per project requirements.
><i>Basically I am comfortable doing comparisons of strings but I would like to do scennarios which include integers and calculations.... or is this not possible in XI UDF's?</i>
Just convert the String to Integrer/ Number and do the comparison inside the UDF .
Regards,
Bhavesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thank you guys... could you please let me know how to do this... perhaps give me some sample code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
u can use integer within your UDF and the convert it into string back.
The reason the o/p is string is that at last it is going to be converted as XML
that is STRING within the tags.
Reagrds
Sachin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex,
as inside an XML only strings are allowed and every decimal, date, currency is a string, the same is in input and output parameters of UDF.
But there is no problem to transform the string to any other type like BigDecimal or double to do calculations. The result of the calculations hat to be transformed back to strings.
Regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
you can change the string to any int or any numeric
inside you UDF and work on that
and then change it back (the result)
Regards,
michal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.