on 01-29-2010 6:29 AM
HI sap-xI guru,
I need to write a UDF to remove leading zeros.Can u please help me in writing it.
Please answer my question ASAP.
Thanks & Regards
Ambati
Hi
Please use format number function and use "#" in number format. It will remove the leading zeros.
Regards
Neeraj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi here is uDF for your requirement. Say matno is your source field.
if (matno == null)
{
return null;
}
//Convert matno into character array
char[] chars = matno.toCharArray();
int index = 0;
//Loop through the array
for (; index < matno.length(); index++)
{
// If the character in the array is not '0' then break from the loopp
if (chars[index] != '0')
{
break;
}
}
//If the index is 0 then there is no leading 0 in the matno, return matno. Otherwise return the characters after the index where the 1st non 0 character was encountered
return (index == 0) ? matno : matno.substring(index);
- Deepak.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Subbu
Use standard function round.
Source field->round->target field
Thats it!!!
Why do you want to use UDF?
Regards
Soumen...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You dont require a UDF if the input field is a numeric field. With the graphical mapping, this can be done.
Just using the arithmetic function divide or multiply with the input field.
below will be the mapping
<input field> & <constant:1> -
> multiply -
> <target field>
eg..
000055687 * 1 = 55687.
000055687 / 1 = 55687.
note. This will not work if the input field in alphanumeric i.e. like 000058fg6697.
~SaNv...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then Div or Mul will not work.. Use the below code as mentioned in [this wiki|http://wiki.sdn.sap.com/wiki/display/Java/RemoveLeadingandTrailingZerosfroma+String]
public java.lang.String removeLeadingZeros( java.lang.String str ){
if (str == null){
return null;}
char[] chars = str.toCharArray();
int index = 0;
for (; index < str.length();index++)
{
if (chars[index] != '0'){
break;}
}
return (index == 0) ? str :str.substring(index);
}
~SaNv...
Hi
Use FormatNumber function and pass Number Format Parameter as 0 (zero) and mapped this in between Source and Target Field.
or use following UDF,
String input;
try
{
input =String.valueOf( Integer.parseInt(a[0]));
result.addValue(input);
}
catch(Exception e)
{
try
{
result.addValue(a[0]);
}
catch(Exception ne)
{
}
}
Award the Points if information is useful.
Regards,
Nitin Patil
try to use:
String inp;
Integer x = new Integer(inp);
return x.toString();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
try below code...
("input" is the input parameter)
import java.util.regex*;
Lets say, String input = "00000000000000023202203203827";
String regex = "^0*";
String temp = input.replaceFirst(regex, "");
return temp;
Also check,
http://wiki.sdn.sap.com/wiki/display/Java/RemoveLeadingandTrailingZerosfroma+String
Regards,
Swetha.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Put this code in your UDF:
Name the function as "zerosuppress" and take the
cache as value
and take one argument input.
Then put the code below:
//write your code here
String output = input.replaceFirst("^0+","");
return output;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
24 | |
11 | |
9 | |
7 | |
5 | |
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.