Overview: User-Defined Functions

Monarch Classic allows you to create your own customized functions, called user-defined functions, which you can then use in calculated field, filter and find expressions. User-defined functions can be created from a combination of Monarch Classic's "intrinsic" functions, which are the functions built into Monarch Classic such as LSplit, and constants, such as text strings, dates and numbers and operators. You can then add a list of parameters to pass to the function, and even define different forms of the function, with different sets of parameters. You could, for example, create a user-defined function to format a customer number to your specification, return a drive letter from a file path and anything else that you may find useful.

In Monarch Classic, with its ability to import and link objects, you can easily share your user-defined functions between models and other users. Monarch Classic has the added benefit of having a default user-defined functions model to help you get started.  

This Default model, called UserDefinedFunctions.dmod, is located in the default lesson models folder for a new installation and includes a wealth of sample user-defined functions that are automatically made available when you start creating a new model. You can add your own user-defined functions to this model, and they will be available for you to use whenever you start building a new model. Alternatively, you can simply specify your own default model(s) using the Add External Model Dialog.

Note that the default model exposes user-defined functions with no link, so that any user-defined functions you use from this model will be copied to your model with no linking in place. To change this behavior, go to the External Models dialog in the Table Window (with no model loaded), select and edit the Default model and change the link type to the desired choice.

As with all linked objects, user-defined functions can be copied (no link), weak-linked and strong-linked to other models, and it is this mechanism that is used for the Default model to expose the User-defined Functions.

  • Function names must begin with an alphabetic character or underscore and may contain only alphabetic characters, digits, and underscores.

  • Parameter names must adhere to the same rules as field names (e.g., at most 31 characters, etc.).

  • Parameter types must be "Character", "Numeric", or "Date/time"

  • The formula must be non-empty and must parse properly, using only names listed in the "Parameters" list, intrinsic functions, and user-defined functions that have been previously defined.

  • The return type of the form must match the result type of the formula.

  • The parameter list may not match the signature of any other form in the same function. In other words, the forms of a function must all differ in the number and/or the types of their parameters.

  • There may be at most 12 parameters.

  • The following intrinsic functions may not be used: ID(), Line(), File(), Page(), Rand(), RandEx(), RecNo(), and RowNo().

  • User-defined functions may not be directly or indirectly recursive (i.e., you cannot have the function call itself).

Note: It may be possible that a future version of Monarch Classic will introduce an intrinsic function with the same name as a user-defined function you have created. To avoid this, you can use an underscore character anywhere in the function name. Monarch Classic will never introduce an intrinsic function containing an underscore. If the name of your function is extremely unlikely to be used as an intrinsic function in the future, such as ReformatWidgetStockNumber, then you probably do not need to worry about including an underscore.

User-defined functions are configured via the User-Defined Function Definition window, and appear in the Functions list on the Formula tab of the Formula Based Filter Properties Window and  the Formula tab of the Formula Field Properties Window,.

See Configuring a User-Defined Function for related information.




© 2024 Altair Engineering Inc. All Rights Reserved.

Intellectual Property Rights Notice | Technical Support