on 08-07-2007 11:22 PM
Hi all,
How can I find the number of digits in an element using message mapping
XIer
All input fields are considered as strings.
Thus you can use the Length standard text field to check its length.
Be aware that it will consider even the dot, comma and possible non-significant zeros.
Regards,
Henrique.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Henrique,
I have a scenario wherein I need to check the length of the incoming field,
example
if field1 has a lenght of 5
than if the incoming field does not exist than I should fill 5 spaces in field1
if the incoming field contains 2 chars, i need to fill it with the 2 char followed by 3 spaces.
How do I go about doing this?
XIer
Satish,
Cause I have to write the code for 100 elements, I have decided to have a AUDF with two inputs;
1) for the element
2) for the length of the data type (I am passing length using Constant message mapping func).
Now when I change my UDF and try running it I get the following error:
<b><i>Start of test
Source code has syntax error: /usr/sap/B06/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0999e66045cf11dcc83b4ebcfc11da82/source/com/sap/xi/tf/_MM_Recordcount1_.java:160: operator >= cannot be applied to int,java.lang.String if(Element_Name.length()>=Element_Length) ^ /usr/sap/B06/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0999e66045cf11dcc83b4ebcfc11da82/source/com/sap/xi/tf/_MM_Recordcount1_.java:166: operator <= cannot be applied to int,java.lang.String for(int i=Element_Name.length();i<=Element_Length;i++) ^ 2 errors</i></b>
The code I have used is:
public String Include_Space(String Element_Name,String Element_Length,Container container)
{StringBuffer sb= new StringBuffer();
if(Element_Name.length()>=Element_Length)
{
return""Element_Name"";
}
else
{
for(int i=Element_Name.length();i<=Element_Length;i++)
{
if(i==Element_Name.length())
sb.append(Element_Name);
else
sb.append(" ");
}
return ""sb.toString()"";
}
Pls advice, where I am going wrong...
XIer
Message was edited by:
XIer
public String Include_Space(String Element_Name,String Element_Length,Container container)
{
int len = Integer.parseInt(Element_Length);
StringBuffer sb= new StringBuffer();
if(Element_Name.length()>=len)
{
return""Element_Name"";
}
else
{
for(int i=Element_Name.length();i<=len;i++)
{
if(i==Element_Name.length())
sb.append(Element_Name);
else
sb.append(" ");
}
return ""sb.toString()"";
}
The problem is u have to typecast the Element_Length to int. U Can't compare
Element_Length() >= Element_Length
<b>int</b> >= <b>String</b>
Hope it clears!!
Try the above code and let us know the results.
Best regards,
raj.
oh lol at this, we have this function in use too, mine may or may not be more simple, the pad character would be a space in your case:
input variables, (String inString, Desired length inLength, Pad Character inPadChar)
public String FillLeft(String inString,String inLength,String inPadChar, Container containeer)
int tLength = Integer.parseInt(inLength);//conversion of string to integer
int aLength;
/**
*Returns an exception if the padd character is more than one letter
*/
if(inPadChar.length()>1)
{
return "EXCEPTION 1 IN XI MAPPING, UDF FUNCTION- FILLLEFT";
}
/**
*Returns an exception if the string is longer than the desired return string's length
*/
if(inString.length()>tLength)
{
return "EXCEPTION 2 IN XI MAPPING, UDF FUNCTION- FILLLeft";
}
/**
/* actual padding of the String
*/
aLength = tLength-inString.length();
for(int i=0;i<aLength;i++)
{
inString=inPadChar+ inString;
}
return inString;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you tell me why ..what you want to exact by finding the length ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.