Most people only use constants in the standard rule, to write out a set value.
Some people will even use them, when setting up key fields for inbound processing.
That’s all fine and dandy, but unlock their true potential and use them in extended rules as well!
Yes, any constant you have defined in the map, can be referenced in an extended rule.
As a reminder, you can see and setup your constants by going to Edit > Constants.
Each constant will have an ID (name), type and value.
You can reference any constant in an extended rule, simply by using the ID, just as you would a variable.
Now, you may be scratching your head, thinking “if something’s a constants, why wouldn’t I just reference the value in the extended rule?”.
That’s a valid point, and for many situations, it would be a lot easier to just type the value.
If #FIELD = “constant value” then
#FIELD = “constant value”;
In those situations, yes, it’s a lot easier to just type the value in-line and be done with it.
But what if you need to reference the same value in multiple extended rules? What if the value changes?
Now you need to go dig thru the rules, and change them all. Sure, you could create a variable in the Pre-session rules, and reference it instead. It’ll accomplish the same idea.
But what if you have a constant value that has special characters in it?
To me, it’s a bit of a burden to go look up the hex values, then replace them within the quotes with ^##. Especially when there are multiple values. Plus, if you look at the map a year from now, you have to “decode” it, to tell what the true value is. Anyone else that looks at your map, won’t know off hand either.
I personally always forget the exact syntax for using the release character too. If your constant has quotes in it, is it /” or \” or //”, it usually takes me a couple tries to get it 100% correct.
Instead, just copy and paste the value into the constant and be done with it.
Tabs? No problem
Quotes? No problem
Unprintable characters? No problem
The constant value takes them all, then you just use the ID in the rule.
I’ve seen some maps where there is a constant called QUOTE, with a value of “.
Then on certain fields where the value of the field needs to be within quotes, they have a rule
#FIELD = QUOTE + #FIELD + QUOTE;
Simple as that, and anyone looking at it, has some idea as to what is going on there.
I ran across a problem recently, where there were certain descriptions being sent in the data.
They were 250+ characters long, and most only differed by a few characters.
Originally, they were trying to type the entire description within the rule.
This caused a few problems…
1. You can only have 256 characters within quotes
2. Those that were under 256, the extended rule box only shows you about 50 characters, then you have to scroll.
3. It was a pain in the rump, trying to see exactly which description we were looking at, since they were all very similar.
Once we created a few constants, and gave them some meaningful names, it was a lot easier to read the extended rule when it looked like:
IF #DESC = const_itemA then
IF #DESC = const_itemB then
IF #DESC = const_itemC then
Which leads me to my final bit of advice for constants.
Since they do look and behave just like variables, I recommend either going with a naming convention that lets you know it’s a constant, like adding const_ to the beginning of the ID (name). Or if your variables are usually lowercase, make constants uppercase.
If nothing else, just add in a quick comment, to say it’s a constant.
IF #DESC = itemA then //itemA is a constant
Sure it all makes sense now, but when you or someone else looks at the rule later on, you don’t want to be searching in the map to see where the “variable” was declared and populated, only to finally remember it was a constant. Save your hair from being pulled out, and do the extra work up front.
Hopefully now that you know you can use constants in extended rules, it can help clean up your map, and make your mapping life that much easier.
As always, any and all comments are welcome. Even a quick “thanks”, to let us know that you found this somewhat useful, is appreciated!
Feel free to request any topics or ideas as well.
Thanks for reading!
Pat Frey – IBM Support