on 08-21-2008 6:03 AM
Hi,
I have the following mapping requirement-
If the incomming value is 100.00 , it should be passed as 10000 with leading zeros as per the field length.
ie; if the field length is 8 and we are getting value 100.00 it should be passed as 00010000.Please suggest me how to do this.
first mutiply by 100. u will get 10000.
write UDF.
in UDF, first String Length in our case 5. which is 3 less than 8 Field length...
in loop append 3 zero to the number so u will get 00010000
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yeah..I got the solution.First I removed '.' as said by shri and then used the following UDF
//write your code here
String temp = new String(String.valueOf(Integer.parseInt(a)));
int temp1 = Integer.parseInt(b);
for(int i = 0; (temp1 - a.length()) > i ; i++)
{
temp = "0" + temp;
}
return(temp);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the suggestions.The udf is working fine.But I want to use the same udf for different fields.So instead of 8, I want to pass the second input to UDF as the max length of the field.The second input can be a constant value since I know the max length of the fields.Can anyone change the udf according to this,so that i can used for any field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the suggestions.The udf is working fine.But I want to use the same udf for different fields.So instead of 8, I want to pass the second input to UDF as the max length of the field.The second input can be a constant value since I know the max length of the fields.Can anyone change the udf according to this,so that i can used for any field..
amt is the Input Argument of the UDF.
length1 is the Second Arguement of the UDF.
amt = Integer.parseInt(amt) * 100; " to Convert decimal to Numberic Value.
int len = amt.length();
String result;
result = String.valueOf(amt); " to Convert Amt to String
for(int i = 0; i< ( length1 - len ) ; i++)
{
amt = "0" + amt;
}
return(amt);
Edited by: ragu r on Aug 21, 2008 10:32 AM
Edited by: ragu r on Aug 21, 2008 10:33 AM
Hi,
If you have seen the UDF code I had given, just
add one more input parameter as b
and pass the constant value for every field as per the max length.
In the Java code just instead of Red colored 8 add the below value
Integer.parse(b)
This will make the udf to be re-usable
source field -
> TestUDF -
> target field
Constant(max length) -
>
thanks
Swarup
amt is the Input Argument of the UDF.
amt = Integer.parseInt(amt) * 100; " to Convert decimal to Numberic Value.
int len = amt.length();
String result;
result = String.valueOf(amt); " to Convert Amt to String
for(int i = 0; i< ( 8 - len ) ; i++)
{
amt = "0" + amt;
}
return(amt);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Please use below code
Source field ---> TestUDF ---> Target field
Udf Name -- > TestUDF
Cache Parameter ---> Value
String temp = new String(String.valueOf(Integer.parseInt(a) * 100));
for(int i = 0; (8 - a.length()) > i ; i++)
{
temp = "0" + temp;
}
return(temp);
In the above code just change the value i.e. Marked with red color "8". that will make you the total length and will do the padding accordingly.
Thanks
swarup
Edited by: Swarup Sawant on Aug 21, 2008 8:16 AM
Edited by: Swarup Sawant on Aug 21, 2008 8:16 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sorry raghu , Iam not good at java programming.Can you please suggest the UDF code that you have mentioned
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
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.