Quantcast
Channel: Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 741

Difference between if and ifs

$
0
0

    There is a note http://service.sap.com/sap/support/notes/1090369 which explains difference between if and ifs. Here i will try to explain with the help of  simple mapping example.There are some threads got created for the same topic.


Boolean mapping functions n SAP XI (withS and withoutS)Difference between If and IfS ifS and ifSWithoutElse: What is their functinality?


Recently came across similar thread Difference between Boolean Functions in which example was asked. i replied to that with simple mapping. So I thought of creating blog for the same which will be helpful to others.


Let us consider simple logic.  I have field called A. I am going to check if this A equals to 5. If it is true execute UDFA. Else UDFB.


Make sure that Execution type is either All values of Queue or All Values of Context.

 

UDFA takes A’s value and pass it to output.

 

UDFA.jpg

 

UDFB takes A’s input and pass it to the output. But I have written simple error statement. So that mapping will fail whenever this UDFB is executed.

 

 

UDFB.jpg

 

1. if


Pseudocode for if in the note as follows.

 

if <condition>
value = <expression1>
else
value = <expression2>
end

In this case, one expects that the <condition> expression is evaluated first and then, depending on the value of the condition, one of the branch expressions is evaluated and assigned to variable 'value'.

 

I write this for my mapping like this.

 

If A==5.

Execute UDFA

Else

Execute UDFB.

As per my example first condition is evaluated and then UDFA is executed. Here it never executes UDFB.

 

 

IF mapping.jpg

 

Result:

 

IF Result.jpg

2. ifs


Pseudocode for ifs in the note as follows.

 

Value = if (<condition>, <expression1>, <expression2>)

 

In this case, all three expressions (<condition>, <expression1> and <expression2>) would be evaluated first and the results of this expressions would be passed to function 'if', which in turn, would return one of them, depending on condition value, to be assigned to 'value' variable. This second use-case is also known in some programming languages as function 'iif'

 

Here all conditions will be evaluated first. It tries to execute UDFB and throws an error.

 

IFS mappings.jpg

 

Result:

 

IFS Results.jpg

Hope this helps.


Viewing all articles
Browse latest Browse all 741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>