Expandable If-Else Works like a Switch Statement in MapForce
In response to several user requests, the if-else component in MapForce has been enhanced in MapForce 2011 Release 2 to accommodate any number of variables. This feature, which is equivalent to a switch statement in many programming languages, enables you to easily control the flow of data in a mapping project by matching a value to a selected criterion. For example, the screenshot below shows the if-then component used in combination with other components to analyze temperature data and produce the following results:
- If temp is greater than 20, true is passed on to bool1 and "high" is passed on to value-true1.
- If temp is less than 5, true is passed on to bool2 and "low" is passed on to value-true2.
- Only one of the value-true parameters can be true for any given temperature, and that is the one that is passed on to the desc attribute in the target component.
The screenshot above is taken from the sample file Classify Temperatures.mfd included during the MapForce installation, so you can immediately process the sample data or modify the mapping to see the output for yourself. The new expandable if-else functionality helps developers build data mappings more rapidly, creates a mapping diagram that displays the conditional test more effectively, and facilitates testing and debugging because the expanded if-else function is much easier to read than a cascading structure of individual components. This is even more obvious when you have to evaluate a large number of conditions. The screenshot below shows a conversion from string to number where the string consists of a three-letter abbreviation of the month. (To save space here, this if-else function only processes strings for the first six months of the year.) In a copy-paste oversight we forgot to update the output constant for May from the value 4 to 5. That’s a much easier error to find and fix when you can see all the logic in one view!(UPDATE: We originally created this example to illustrate the advantages of Expanded If-Else over nested or cascading If-Else mappings that can quickly grow too large to view on a single screen. For a better design for solving this and other similar conversions using a look-up table, see the Switch Statement vs. Look-up Table in MapForce blog post.) Find out for yourself how easy it is to use expanded if-else functions in your own data mapping projects. Download a free 30-day trial of MapForce.