Switch Statement vs. Look-up Table in MapForce

One of the great things about working with software developers is you not only get to create new things that never existed before, you also get to see how other peoples’ minds work when they discover alternate solutions to any design challenge. We received a comment from a software developer on our recent post titled Expandable If-Else Works like a Switch Statement in MapForce regarding one of the examples we used. The reader suggests that our second example illustrated a problem that would be more elegantly solved in Altova MapForce with Value-Map than by our Expanded If-Else statement. Here was the original example that received the month as a string of characters and needed to generate the corresponding number: Original Expanded If_Else example in MapForce A Value-Map in MapForce is an alternate solution that functions as a look-up table, whereas an Expanded If-Else acts like a switch statement. Here is how our mapping would look with a Value-Map in place of the Expanded If-Else: Value-Map alternative in MapForce Yep, that’s it. Rather than copying, pasting, and modifying sets of elements the way we built our original Expanded If-Else, a Value-Map lets us easily create the entire look-up table in its Properties dialog: Value-Map Properties dialog in MapForce We accept the commenter’s point — Value-Map definitely works better for the problem we chose because it’s much quicker and easier to create! The table from the Value-Map properties is also more concise and easier to interpret in MapForce-generated mapping documentation than our original Expanded If-Else structure. Of course you can’t always replace an Expanded If-Else statement with a Value-Map. Data entering the Value-Map must equal a single value in the input table to generate a specific output, whereas Expanded If-Else lets you set up a series of conditions with different logical tests. Sometimes the exact nature of a data conversion project makes it a judgment call to use a switch element vs. a look-up table. Let’s say your project receives input as a number that represents a wavelength of the electromagnetic spectrum and you want to handle ultraviolet, visible colors, and infrared energy individually. In that case we could use an Expanded If-Else to test for ranges of input values. The Expanded If-Else section of the mapping might look like this: Expanded If-Else mapping in Altova MapForce If the input is an integer, you could also create a solution using Value-Map, but you would need to build a very long look-up table. And then what happens later if the project requirements change and the input becomes a decimal number, or you need to filter each visible color separately by name? Essentially Altova MapForce is a really cool graphical representation of a complete software language toolbox that insulates you from detailed programming language syntax, with a rich collection of components you can assemble creatively to solve your own data mapping, conversion, and integration challenges. Find out for yourself how easy it is to apply MapForce to your own data mapping projects. Download a free 30-day trial of MapForce.

Tags: , , , , , ,
6 replies
  1. Avatar
    Michael says:

    Funny, first thing I thought as well was, why not use a value map! But I have ran across many a time when a switch statement will be very valuable!

  2. Avatar
    John Z says:

    Very handy. We just bought mapforce and we need to do this. However, need to do value mapping via a look up table in a DB instead. Can you suggest the best-practice approach (set of functions) or link to a doc for setting that up?

  3. Avatar
    John Z says:

    Very handy! We just bought Mapforce and need to do this value mapping through an intermediate look up table (~200 values). Can you suggest best-practice (in 2012) functions/approaches to use or point to a doc? I haven't seen quite the exact documentation I'm looking for.

  4. Avatar
    DaveMcG says:

    It’s hard to recommend a best practice in this case without knowing the data types of the sources and outputs. Since your lookup table resides in a database, you could potentially use a database component and a SQL-WHERE component to query the table.

    Feel free to contact Altova Support at http://www.altova.com/support_center.html You’ll be able to upload a copy of your mapping file so the support engineers can see what you are trying to do.

    Another good resource for new MapForce users is the MapForce Online training at http://www.altova.com/aot/online-training.aspx

    Coincidentally, we are planning a new post covering guidelines for selecting patterns for various data mapping requirements. Watch for that to be published soon!

  5. Avatar
    melbourne people says:

    Hi,I have few records in a source file like AUS 193, US 256, CND 100,JPN 110. The requested out put file should be AUSTRALIA 193,USA 256,CANADA 100, JAPAN 110. So, I would like to go for 'value map table'. Could you please show me how to create(navigation) the table in MAP FORCE? Thank you Shoukat

  6. Avatar
    DaveMcG says:

    You can add a value-map to a data mapping via the MapForce Insert menu. Then right-click the value-map to open the properties dialog and edit the inputs and outputs.

    In your example, a value-map would work if the numbers following the country abbreviations are all known in advance. If the data set is very large because each country code might be followed by almost any number, then you will need to apply string functions. You could split the country abbreviation from the digits, replace the country name, then re-concatenate the numeric value.

    A more recent Altova blog post discusses choosing Data Mapping Patterns for data transformation requirements.

    You can also contact Altova Support at: http://www.altova.com/support_center.html

Comments are closed.