cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping

Former Member
0 Kudos

Hi friends,

I have a mapping requirement as folows.

Source field : KRATE

Target field : Rate

Mapping requirement is as follows

if source is 15; you need to map it to 000000000001500 ( in other words 11spaces (or zeros ), 15 ( the value ) and then two zeros. )

Can someone tell me how do i do that?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sameer,

Can you please tell me the values you have used for the 2 constants and the number of zeros you have used for the 2 formatnumbers.

Former Member
0 Kudos

The first 2 constants for 'replaceString' values are '.' (without quotes) and single space. The constant for mul function is 100.

And formatNum has 15 zeros in both cases.

Answers (16)

Answers (16)

Former Member
0 Kudos

Hello,

Try this :

Make UDF with 2 inputs a & b (of type value)

Source -


\

-


\UDF----> Target

Source--


\--


/

Constant[.]-/indexOf2--


/

UDF:

int cnt = Integer.parseInt(b);

if(a.length()<15)

{

String str = "";

for(int i=0 ; i<(15-a.length()) ; i++)

str=str+'0';

// String val = a.substring((a.length()-3) , a.length());

if( cnt >= 0 )

return( str + a.substring(0,cnt) + a.substring(cnt+1,a.length()) );

else

return(stra"00");

}

else

return(a);

Thanks,

mahi

Former Member
0 Kudos

Hi patrick,

I am not sure whether input has 2 digits after decimal or 3 digits after decimal.I want the mapping to take care whatever may be the input may be.Thats why i was asking for the requirement as such.Anyway tomorrow i will confirm that with you.

Former Member
0 Kudos

Manikandan

Try my solution as shown in the image.

https://weblogs.sdn.sap.com/weblogs/images/17804/solution.JPG

Replace Name with KRATE and Name1 with the output.

I think the picture is self-explanatory.

Sameer

Former Member
0 Kudos

Hi sameer,

if the source is 105.125 output should be

000000000105125.If we round it off it will become 126.I need not want rounding off.

Former Member
0 Kudos

What is the maximum length of decimal value?? Is it 3 or is it dynamic

Former Member
0 Kudos

Hi,

first question:

if you have as input

105.125

or

1051.25

in both cases your ouput will be

000000000105125

right?

second question:

do you could have an input like:

0.123456789012345

or

12.1234567890123

and what should happen then?

Regards

Patrick

Former Member
0 Kudos

Hi patrick and sameer,

If there are 3 digits after the decimal your concept will not work.

Former Member
0 Kudos

Hi,

that's exactly why it's important to know how your requirements look like.

You only said:

>i.e if it is 1000,the target should be 000000000100000

>if the source is say 1000.50,the target should be

>000000000100050

How should we know that you can have a input like 1.234?

Anyway you could place a round-function between mul and formatNumber and then it shoul work.

Regards

Patrick

Edited by: Patrick Koehnen on Jul 3, 2008 12:17 PM

Former Member
0 Kudos

So r looking at something like this

If it 1000.501,the target should be

000000001000501

Or do you want to round it to the nearest round the same. If that is the case use the round function and then multiply by hundred and do the formatnum, if not then let us know.

Former Member
0 Kudos

Hi Induja,

i.e if it is 1000,the target should be 000000000100000

if the source is say 1000.50,the target should be

000000000100050

Can you understand now?

Former Member
0 Kudos

Hi,

you can do it like this:

standard function mul (multiply):

input1: sourceValue

input2: constant (100)

output goes into formatNumber (000000000000000)

This should work.

But like I mentioned above you have to be sure that your source value is numeric and is not empty. If you are not sure you have to check this first.

Regards

Patrick

Former Member
0 Kudos

Hi Manikandan

Simple solution is first multiple the input by 100 and then use formatnum with the value as 000000000000000

Sameer

former_member190389
Active Contributor
0 Kudos

Do the following:

1. multiply the input num by 100.

2.

long input = num;

int count = -2;

while(input ! = 0)

{

input = input / 10

count ++;

}

String str ="";

for(int i = 0; i<=count;i++)

{

str = str.append("0");

}

result.addValue(str+num);

Former Member
0 Kudos

Hello,

Try this :

**********************************************

if(a.length()<15)

{

String str = "";

for(int i=0 ; i<(15-a.length()) ; i++)

{

str=str+'0';

}

String val = a.substring((a.length()-3) , a.length());

if( val.substring(0,1).equals(".") )

return( str + a.substring(0,a.length()-3) + val.substring(1,3) );

else

return(stra"00");

}

else

return(a);

*********************************************

Just use this UDF

Source-----> UDF -


> target

Thanks,

Mahi

aashish_sinha
Active Contributor
0 Kudos

Hi,

If your requirement is this

>> if source is 15; you need to map it to 000000000001500 ( in other words 11spaces (or zeros ), 15 ( the value ) and then two zeros. )

write an UDF something like this

String before = "00000000000";

String after = "00";

if (source.equals("15"))

{

source = before + source + after;

}

else

{

//your error message

}

return source;

Hope this will help you.

Regards

Aashish Sinha

PS : reward points if helpful

Edited by: Aashish Sinha on Jul 3, 2008 10:06 AM

Former Member
0 Kudos

That UDF is not working.output is same as the source without any zeros

Former Member
0 Kudos

Hi,

Could you tell me if I have understood it right,if the source KRATE is an integer,you want it to be concatenated with 2 zeroes in the end.If it has digits after the decimal point,you want the zeroes to be concatenated after the entire number excluding the decimal points.

i.e if it is 1000,the target should be 000000000100000

if the sorce is say 1000.50,you want the target to be 000000010005000.

Please could you tell me if this your requirement?

Thanks and Regards,

Induja

Former Member
0 Kudos

Hi MANIKANDAN subash chandran ,

write a UDF.

if(x.length()<15)

{

String str = "";

for(int i=0;15<(15-a.length());i++)

{

str=str+'0';

}

return(str+x);

}

else

{

return(x);

}

Regards,

Jayasimha Jangam

Former Member
0 Kudos

Hi Induja,

Your method works fine for integers well.For eg if the input is 15 ouput is 000000000001500.If source is 1000 output is 000000000100000.But if the source is 1000.50 output is 000000000100000 which is not right.Last 2 digits should be 50.I am getting this error because we are concatenating 2 zeros as a constant.Is there any other method?

Former Member
0 Kudos

Hi,

you have to make your requirements clear otherwise it is not so easy to help you

You said your output should have always a length of 15 and the last two digits are the decimals.

How exactly could your input look like?

could this be valid inputs:

123456789012345

12.8

0.22

and if yes what should be the output?

Regards

Patrick

Former Member
0 Kudos

Hi,

You can try this as well and check.Take your source field KRATE and map it to the FormatNumber arithmetic function and specify it as 13 zeroes,then use the concat function to concatenate this with two zeroes and finally map the result to your target field Rate.

Thanks and Regards,

Induja

Former Member
0 Kudos

Hi Guys ,

What should be the procedure if its not a 2 digit number.It can be a number ranging from 1 git to 15 digits.

To Boopalan....

I think your procedure holds good if we dont know the number of digits.Am i right?

Former Member
0 Kudos

Hi,

the solution mentioned by Induja is the easiest and shortest (I guess).

You only have to be sure that your source field has always a value.

If the source value is empty or not a number your mapping will crash, so if you can not be sure you will have to check this first.

Regards

Patrick

Former Member
0 Kudos

Hi guys,

It will be a 2 digit value always at the source side.

We need to pad 11 zeroes and then the 2 digit number and then 2 zeroes

Former Member
0 Kudos

Hey,

better try my above mapping flow and UDF.

Boopathi

former_member194786
Active Contributor
0 Kudos

Hi Manikandan,

Use the FormatNumfunction of the arithmetic functions. Have a look at the help doc to know more about it:

http://help.sap.com/saphelp_nw04/helpdata/en/ef/df564b6aa24fc9ab0d685460747de5/frameset.htm

Regards,

Sanjeev.

Former Member
0 Kudos

hi....

u can do it directly by standard function concate.

for concate function, take 1st argument as constant with 11 zeros, second argument ur source feild.

go for one more concate function take above result as 1st argument,second argument again constant with 2 zeros,and map it to target field.

Sreedhar Goud.

Former Member
0 Kudos

Hey,

Try for this way:

(Source) if exists (eg15) --> Constant (00) (eg1500) then --use this UDF (for filling the Zeros) ---Target

UDF:

if(a.length()<15)

{

String str = "";

for(int i=0;15<(15-a.length());i++)

{

str=str+'0';

}

return(str+a);

}

else

{

return(a);

}

Thanks,

Boopathi

Edited by: Boopathi Thangavel on Jul 2, 2008 10:38 AM

Former Member
0 Kudos

hi.......

that means always u will get 2 digit number only at source side?

Sreedhar Goud

Former Member
0 Kudos

Hi,

what can be other source values and what should happen then?

Regards

Patrick