Prophet Modelling Technique (1): Enumerations
If you’ve upgraded your Prophet version to Release 2024 Q4, you might have noticed a new and helpful feature: you can now define a variable as an enumeration type—in addition to the usual number and text types. (Prefer video? View the video for this post!)
If you’re not familiar with enumerations, let me briefly explain. In simple terms, an enumeration works like a two-dimensional array. The first dimension is a sequence of integers starting from 0, and the second is the corresponding text value. You can easily move between the two within the same pairing—get the text from an integer, or the integer from a text value.
Let’s say we set up an enumeration for IFRS17 discount rates and call it IFRS_DISC:
- The first pairing is 0 (integer) and “LIR” (text), for locked-in rates.
- The second pairing is 1 (integer) and “VIR” (text), for current rates.
- We can refer to them using object-like notation: IFRS_DISC.LIR and IFRS_DISC.VIR—similar to how it works in object-oriented programming (“OPP”) in VBA.
Prophet provides functions to handle these conversions. For example, you can use ENUM_TO_INT and ENUM_TO_TEXT to get 0 and "LIR" from IFRS_DISC.LIR. You can also convert an integer or a text value to an enumeration using INT_TO_ENUM and TEXT_TO_ENUM.
So when should we use enumerations in our Prophet coding?
In my view, enumerations make variable definitions much more readable. Instead of using raw values like 0, 1, or 2, you can make your conditions clearer. For example:
- Without enumeration: IF CALC_LOOP = 0 THEN
- With enumeration: IF CALC_LOOP = ENUM_TO_INT(DISC_TYP.LIR) THEN
Using enumeration makes the logic more transparent—you don’t have to remember what the numbers stand for. Plus, since enumerations must be defined under Workspace Objects, it also helps reduce manual errors.
With enumeration now supported as a variable type, we can streamline our logic even further. Going back to the earlier example:
- You could create a new variable that automatically converts CALC_LOOP into an enumeration, say CALC_DISC.
- Then, your condition becomes as simple as: IF CALC_DISC = DISC_TYP.LIR THEN, with no need for conversion functions.
There’s another useful application—enumeration variables can help with table suffixes that need to vary by t or CALC_LOOP. As many of you know, text variables in Prophet can't directly depend on t or CALC_LOOP. But with the new CALC_DISC variable, you can derive a suffix like this:
"ifrs_disc_" + ENUM_TO_TEXT(CALC_DISC) + "_pc".
Wrap Up
The addition of enumeration as a variable type in Prophet is a small but meaningful improvement. The use of enumerations makes our code cleaner, easier to understand, and less prone to errors. If you haven’t used it yet, give it a try—you might find it a simple way to bring more structure and clarity into your Prophet coding.
Related Posts:
- Prophet Modelling Technique (1): Enumerations
- Prophet Modelling Technique (2): New Business Processing
- Prophet Modelling Technique (3): Calculation Looping
- Prophet Modelling Technique (4): SPCODE
Comments
Post a Comment