cancel
Showing results for 
Search instead for 
Did you mean: 

Need help to calculate content price using UDF

Former Member
0 Kudos

Hi Experts ,

I am looking for a  UDF to write a code so that i can  get the value for the total sales amount   below is the logic

Case 1 :

Total Sales amount  = (Extended Amount)-(Deposit amount)-(Tax Amount) 

Case 2:

and if any discount comes for an Item (Discount against the Price of the item)  then the Sales amount  value should be calculated as below

Sales Amount  = (Extended Amount+Discount )- (Deposit Amount)- (Tax Amount)

How can i achieve this by using UDF .  If i use graphical mapping  I am concerned with the exception that occurs  if  no values are present in the Source Input fields  while calculating using Arithmetic functions in the Graphical mapping .

So i guess Using UDF might resolve this problem ... Please  help me out achieve this above logic using UDF .

Regards,

Khan

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello Aziz,

You can use mapWithDefault[0] to set the value to 0 when the field is not present. So, this is very much possible without UDF. So the mapping would be:

ExtendedAmount -> mapWithDefault [0] -> add logic and so on....

Hope this helps,

Mark

Former Member
0 Kudos

Hi Mark,

Thanks for the quick reply ,

Let me tell you one thing . The field names are of Type decimal ie

Sales Amount = (Extended Amount+Discount )- (Deposit Amount)- (Tax Amount)



Field names           Type

--------------------------------------

Extended amount    String

Discount                 decimal

Tax amount         decimal

deposit amount    decimal

When i try to using  Add function

ExtendedAmount -> mapWithDefault [0] -> add-->  Result

i am getting error

Exception:[com.sap.aii.mappingtool.tf7.FunctionException: Cannot cast '' to decimal number] in class com.sap.aii.mappingtool.flib7.Arithm method add[, 2.40, com.sap.aii.mappingtool.tf7.rt.Context@7ece276f] See error logs for details

Muniyappan
Active Contributor
0 Kudos

Hi Aziz,

you can perform add function with string and decimal. hence the error.

Extended amount should be decimal one.

Regards,

Muniyappan.


gagandeep_batra
Active Contributor
0 Kudos

Or there might be chance of blank  also check that  condition also

Regards

Gagan

Former Member
0 Kudos

Hi Mark,

When i use MapwithDefault[0] as per your suggestion . I am still getting the same error if Source Input field is empty or null . see my mapping below and suggest a solution

case 1 : if all the source field values exist i am able to get the result successfully without any error.

           mapping runs fine

Case 2 : If any of the source fields for example Amount = 0 or does not exist  then  i get the exception even after using MapWithDefault[0] .

Error :

Please help me to resolve this .

Harish
Active Contributor
0 Kudos

Hi Aziz,

The error is because you are giving input string/char to airthmetic function.

Please try to perform below check before input to airthmatic function.

Input --> mapWithDefault (blank) --> equal --> Blank (constant) --> Not (Boolean function)

then perforn the airthmatic operation.

If you do not want to perform this many validation in graphical mapping the use the UDF.

Regards,

Harish

Former Member
0 Kudos

Hi  experts .

Thanks you all for the reply . My problem is solved .

Regards,

Aziz khan .

Answers (0)