Tip use constants to keep code readable
Using the Constants
Let's pretend you have to read code that has been edited by another development partner. You may be skilled and know your "fstat" return values very well. Unfortunately, this is not the case for everyone. The following code is a little bit cryptic to read: Read [BPC]BPCNUM=CUST_CODE
If fstat=0
Write [ITM]
If fstat=3
...
- The value 0 means that no error was found.
- The value 3 means that the creation failed due to an attempt of duplicate index creation on an index with no duplicates.
Read [BPC]BPCNUM=CUST_CODE
If fstat=[V]CST_AOK
Write [ITM]
If fstat=[V]CST_ADUPKEY
...
What does fstat=7 mean?
Even if you are skilled in version 6, do you know what fstat=7
means?
With fstat=[V]CST_ARECTICKDEL
, you can remember that this status corresponds to the fact that the record with the right updtick is no longer present when a deletion is required.
If you are not an expert, you can also find the list of the most useful constant in the Developer Guide Constants document.
Summarizing the constants management
In several cases of internal functions, the engine returns a numeric status that is not always simple to remember. When dealing with choices input from a local menu (for example a combo box, an enumeration, a set of radio buttons, and so forth), numeric values starting from 1 are returned again, and can confuse the development partner as well as the code reader.
Using supervisor constants with a name starting with [V]CST_A must become a routine. All these constants are defined in the Developer Guide Constants document and their use provides the following benefits:
- Readability of the code.
- Better resilience of the code. If for any reason a status value must change and the result is not persisted somewhere, the only work to do is to change the constant value.
If you have application parameters that have constant values, do not hesitate creating them. You can create your own constants starting with [V]CST_ followed by any letter other than 'A' it is reserved for the supervisor.
To do this, use the Workbench reference Constants Dictionary document and create your own constants.