on 10-18-2007 10:28 AM
Hi,
I have Tto write a user definf function in SAP XI. can any once help in doing so.
For the decimals it has to be completed with 0 (zeros) on the right if the value of the field has less than the size of the decimals and also it has not be sent comma (,) or point (.) in the numeric fields. Example: The monthly received quantity (field QTARICM) is 587,57. In the output file it has to be sent 000000000587570 (size 12 + 3 dec).
Thanks in Advance.
Best Regards,
Joseph
Write your UDF like this
the imports are
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.ParsePosition;
DecimalFormat inputDecimalFormat = new DecimalFormat();
DecimalFormatSymbols inputDecimalFormatSymbols = inputDecimalFormat.getDecimalFormatSymbols();
inputDecimalFormatSymbols.setDecimalSeparator(",".charAt(0));
inputDecimalFormat.setDecimalFormatSymbols(inputDecimalFormatSymbols);
inputDecimalFormat.setGroupingUsed(false);
inputDecimalFormat.setMinimumIntegerDigits(12);
inputDecimalFormat.setMinimumFractionDigits(3);
ParsePosition parsePosition = new ParsePosition(0);
Number inputNumberObj = inputDecimalFormat.parse(inputNo,parsePosition);
String <i>[]</i>outputArr = (inputDecimalFormat.format(inputNumberObj.doubleValue()).split(","));
String output = outputArr<i>[0]</i>+outputArr<i>[1]</i>;
return output;
The input to this UDF wud be "inputNo"
Message was edited by:
Varun Mukund
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Varun,
Thank you very much for the code. So I can just creat a UDF with code given by you and start testing it rite.
The input to this UDF wud be "inputNo". I can test with different combinations of the decimals rite for example:
1. 5555.50
2. 34,343.55
3. 3434343.34
and so on
Let me know .
Thanks in advance.
Best Regards,
Joseph
This works: Imports---
java.text.DecimalFormat;
java.text.DecimalFormatSymbols;
java.text.ParsePosition;
DecimalFormat inputDecimalFormat = new DecimalFormat();
DecimalFormatSymbols inputDecimalFormatSymbols = inputDecimalFormat.getDecimalFormatSymbols();
inputDecimalFormatSymbols.setDecimalSeparator(".".charAt(0));
inputDecimalFormatSymbols.setGroupingSeparator(",".charAt(0));
inputDecimalFormat.setDecimalFormatSymbols(inputDecimalFormatSymbols);
ParsePosition parsePosition = new ParsePosition(0);
Number inputNumberObj = inputDecimalFormat.parse(inputNo,parsePosition);
inputDecimalFormat.setGroupingUsed(false);
inputDecimalFormat.setMinimumIntegerDigits(12);
inputDecimalFormat.setMinimumFractionDigits(3);
String noStr = inputDecimalFormat.format(inputNumberObj.doubleValue());
String output = noStr.substring(0, noStr.indexOf('.')) + noStr.substring(noStr.indexOf('.')+1,noStr.length() );
return output;
Pl use the code i've given...
If it is not working, then plz give some test cases for inputs you'll give and output you expect to receive...
Thanks,
Varun
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
can you give me the field structure of your input field QTARICM, because, the formating depends solely on the QTARICM filed, in your example case you have said 587,57 might be the input, what is the exact format of this field ?
Regards
Ramesh P
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
I checked this works
public void func(float sourceNumber)
{
String targetNumber="";
int size1=12;
int size2=3;
int numberOfDigits=0;
int temp=(int)sourceNumber;
int temp2=(int)sourceNumber;
while(temp>0)
{
int digit=(int)temp%10;
numberOfDigits++;
temp=temp/10;
}
String tempString=""+sourceNumber;
String afterDecimal=tempString.substring(tempString.indexOf(".")+1,tempString.length());
//to generate the target
for(int i=0;i<size1-numberOfDigits;i++)
{
targetNumber=targetNumber.concat("0");
}
targetNumber=targetNumber.concat(""+temp2);
targetNumber=targetNumber.concat(afterDecimal);
for(int i=0;i<size2-afterDecimal.length();i++)
{
targetNumber=targetNumber.concat("0");
}
System.out.println(targetNumber);
}
Let me know if you need any modifications.
Thanks
Hey Joseph,
you have to use UDF for this.
Regards,
Sarvesh
Message was edited by:
Sarvesh Singh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you not use the FormatNumber Function using graphical mapping for this?
No you can't!
I just checked. it drops the decimal places!
Message was edited by:
Barry Neaves
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.