cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping error with substring

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (3)

Answers (3)

stefan_grube
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

Amanda,

Yes, you can easily achieve this using a user defined function.

Happy new yr 2006

regards,

Felix

Former Member
0 Kudos

hi,Felix

Thanks a lot and would u like to tell me how to define the function by myself. Can you give me the codings? I am urgent,thanks a lot

Best Wishes and Happy New Year

Amanda

Former Member
0 Kudos

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

Former Member
0 Kudos

hi,Vijay Dadsena

Thanks a lot , It is the best gift for me in the New Year.

I will try. Any questions,keep in touch with me.

Happy New Year

Amanda

Former Member
0 Kudos

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.

Former Member
0 Kudos

hi,Vijay Dadsena

I have imported the three variables as 'nodeValue'A'maxLength_s'A'maxLength_t' , and then appeard the above message.

I don't know how to solve this problem,Can you help me?

Thanks and Best Wishes

Amanda

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

hi,Vijay

The code given by you have syntax error, where do the error occur?

Thanks a lot

Amanda

Former Member
0 Kudos

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

stefan_grube
Active Contributor
0 Kudos

Hi Amando,

you have defined your function with cache type "Context" or "Queue". That is wrong. Choose cache Type "Value". Than it should work.

Regards

Stefan

Former Member
0 Kudos

Hi,

Try to write a user defined function it should be easy for you to manipulate the string as you wish.

Happy New Year

Former Member
0 Kudos

hi,Santhosh

Thanks a lot. I will try.