cancel
Showing results for 
Search instead for 
Did you mean: 

Need to write USER DEFIND FUNCTION for following Business logic in SAP XI.

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member192892
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

former_member192892
Active Contributor
0 Kudos

Joseph,

just let me test the numbers and i'll tell you if the code needs modification

Former Member
0 Kudos

ok. sure

Joseph

former_member192892
Active Contributor
0 Kudos

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;

Former Member
0 Kudos

Hi,

Problem was sloved almost 99%. can you make it dynamic?

Becz u have hardcoded the values.

It will be great if it can takeup the values dynamically.

Thanks in Advance.

Best Regards,

Joseph

Answers (4)

Answers (4)

former_member192892
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Ramesh,

In the place of dot you have to place zero and we should remove comma. I have so many decimal fields. and the same logic may be applied for others(decimals) as well.

I think you got my point.

Joseph

Former Member
0 Kudos

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

Former Member
0 Kudos

Hey Joseph,

you have to use UDF for this.

Regards,

Sarvesh

Message was edited by:

Sarvesh Singh

Former Member
0 Kudos

Hi Sarvesh,

So any suggestions, how to write the jave code in UDF?

Joseph

Former Member
0 Kudos

Hi

You need a complex udf for that..I dont think it can be done by standard functions.

Let me give it a try.

Thanks

Former Member
0 Kudos

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