on 01-01-2006 3:38 AM
hi,everyone
I am trouble in the standard function 'substring'
of Message Mapping. The scenario is that i judge the incoming string ,if the length of the incoming string is
greater than 20 , it is separated and is given to two fields in the Target Message, the question is that i don't forecast the extension lenghth except the 20 characters.
Anyone can help me, thanks a lot
Happy New Year and Best Wishes
Amanda
Hi Amando,
as I am a friend of standard functions, I would propose this simple solution:
source
concat - substring(0,20) - trim - target1
constant(20 spaces)/
source
concat - substring(20,20) - trim - target2
constant(40 spaces)/
This assumes, that the target fields are 20 chars each, the source field 40 chars max.
Adding the spaces to the source prevents the substring function to throw an IndexOutOfBound exception.
Regards
Stefan
Message was edited by: Stefan Grube
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan/experts, I have a similar situation to Amando, but my problem is I have a 3000 char xml source string which I need to split into 3 idoc segment targets. Is there a way of adapting the standard function to do that or do I have to use substrings/udf's?
Hi Amando,
as I am a friend of standard functions, I would propose this simple solution:
source
concat - substring(0,20) - trim - target1
constant(20 spaces)/
source
concat - substring(20,20) - trim - target2
constant(40 spaces)/
This assumes, that the target fields are 20 chars each, the source field 40 chars max.
Adding the spaces to the source prevents the substring function to throw an IndexOutOfBound exception.
I am very new to XI and am really struggling so all help will be greatly appreciated(!) and rewarded.
Amanda,
Yes, you can easily achieve this using a user defined function.
Happy new yr 2006
regards,
Felix
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amanda,
You can write your code similar to this.
/* Input variables
nodeValue = Containes the value of the mapped node
maxLength_s = Max Length of the Source Node
maxLength_t = Max Length of Target Node
if the node content length is less than maxLength of source than
output = the actual length of the content
else
output = content with length of the target node
*/
String output = new String( );
int l_length;
int l_maxLength_s = Integer.parseInt(maxLength_s);
int l_maxLength_t = Integer.parseInt(maxLength_t);
l_length = nodeValue.length( );
if ( l_maxLength_s <= l_maxLength_t )
{
output = nodeValue.substring(0, l_length );
}
else
{
if ( l_length <= l_maxLength_t )
{ output = nodeValue.substring(0, l_length );
}
else
{ output = nodeValue.substring(0, l_maxLength_t );
}
}
return output;
Regards,
VijaY
Message was edited by: Vijay Dadsena
hi,Vijay Dadsena
I have copyed the code as you gave above, but the error
appears like this :
15:48:56 Start of test
Source code has syntax error: D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map4e3da5e07b6411da98e90014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:3: '.' expected import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.;import nodeValue;import maxLength_t;import maxLength_s; ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map4e3da5e07b6411da98e90014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:3: '.' expected import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.;import nodeValue;import maxLength_t;import maxLength_s; ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map4e3da5e07b6411da98e90014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:3: '.' expected import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.;import nodeValue;import maxLength_t;import maxLength_s; ^ 3 errors Source code has syntax error: D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map4e3da5e07b6411da98e90014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:3: '.' expected import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.;import nodeValue;import maxLength_t;import maxLength_s; ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map4e3da5e07b6411da98e90014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:3: '.' expected import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.;import nodeValue;import maxLength_t;import maxLength_s; ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map4e3da5e07b6411da98e90014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:3: '.' expected import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.;import nodeValue;import maxLength_t;import maxLength_s; ^ 3 errors
15:48:57
End of test
Which variables should i import in the subsequent 'Imports' of the user-defined function.
Hi Amanda,
You Need to define 3 importing variables called
nodeValue
maxLength_s
maxLength_t
And copy the code in the editor.
And wherever you are using this User Defined Function
map the inputs for these importing variable as :
Source Node -> nodeValue
Constant(< max length of the source string>) -> maxLength_s
Constant(< max length of the target string>) -> maxLength_s
< max length of the source/target string> can be the max length as 5 or 10, based on the input/output field.
Map the Output variable as
Output of the User Defined function -> Target Node
And try to run the map. It should work.
Regards,
Vijay
hi,Vijay
Thanks a lot. I have defined 3 arguments 'nodeValue maxLength_s maxLength_t', but the error appeared when i try to run the mapping. the error is like this:
Source code has syntax error: D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapfb42da207c1911da9d500014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:154: cannot resolve symbol symbol : method parseInt (java.lang.String[]) location: class java.lang.Integer int l_maxLength_s = Integer.parseInt(maxLength_s); ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapfb42da207c1911da9d500014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:155: cannot resolve symbol symbol : method parseInt (java.lang.String[]) location: class java.lang.Integer int l_maxLength_t = Integer.parseInt(maxLength_t); ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapfb42da207c1911da9d500014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:157: cannot resolve symbol symbol : method length () location: class java.lang.String[] l_length = nodeValue.length( ); ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapfb42da207c1911da9d500014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:161: cannot resolve symbol symbol : method substring (int,int) location: class java.lang.String[] output = nodeValue.substring(0, l_length ); ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapfb42da207c1911da9d500014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:166: cannot resolve symbol symbol : method substring (int,int) location: class java.lang.String[] { output = nodeValue.substring(0, l_length ); ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapfb42da207c1911da9d500014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:169: cannot resolve symbol symbol : variable length location: class com.sap.xi.tf._MM_Me_Favorite_ { output = nodeValue.substring(length, l_maxLength_t ); ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapfb42da207c1911da9d500014221ffde5/source/com/sap/xi/tf/_MM_Me_Favorite_.java:172: cannot return a value from method whose result type is void return output; ^ 7 errors
where do the wrong occur,can you help me?
Happy New Year
Amanda
Hi Amanda,
The code is working fine in my system. I think, In your
system it is not able to execute the standard method like "parseInt" provided by class <b>Integer</b>
or "substring" provided by class <b>String</b>
Reference to java.lang.* should be accessible in the
code, so it should work, but i thnik in this case It is not able to access method.
Let me know how exactly you are creating the User defined function in SAP XI mapping , so that I will be able to understand the reason of the error.
Regards,
Vijay
Hi,
Try to write a user defined function it should be easy for you to manipulate the string as you wish.
Happy New Year
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
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.