| Contents: | Main | See Also: | Getting Started Manual | Advanced User Manual | ||||
As mentioned in the "VA FileMan Functions" section in the VA FileMan Advanced User Manual, as a developer in VA FileMan you can create your own computed-expression functions. In some ways, a function can be thought of as an OUTPUT transform that can work on any field. For example, you may prefer seeing many dates displayed as 20-7-69, rather than the JUL 20,1969 format that VA FileMan typically produces. Since this date is internally stored in the form 2690720 (see the description of %DT), you could write a line of code that took the internally stored format in the variable X and transformed it using:
+$E(X,6,7)_"-"_+$E(X,4,5)_"-"_$E(X,2,3)
This is exactly what you are allowed to do when you edit the FUNCTION (#.5) file using the Enter or Edit File Entries [DIEDIT] option.
To continue the above example, you could create a DASHDATE function, which could then be used by any user to display date-valued fields and expressions in the DAY-MONTH-YEAR format as follows:
Select OPTION: ENTER AND EDIT FILES <Enter>
INPUT TO WHAT FILE: FUNCTION <Enter>
EDIT WHICH ATTRIBUTE: ALL// <Enter>
Select COMPUTED-FIELD FUNCTION: DASHDATE <Enter>
ARE YOU ADDING 'DASHDATE' AS A NEW COMPUTED-FIELD FUNCTION? Y <Enter>
(YES)
MUMPS CODE: S X=+$E(X,6,7)_"-"_+$E(X,4,5)_"-"_$E(X,2,3) <Enter>
EXPLANATION: PRINTS DATE IN "DD-MM-YY" FORMAT <Enter>
DATE-VALUED: NO <Enter>
NUMBER OF ARGUMENTS: 1 <Enter>
WORD-PROCESSING: <Enter>
Notice that the MUMPS CODE field contains code to transform the variable X (the argument of the function) into a different X. If two arguments were required for the function, the first would be found in the variable X1 and the second in X. Although the new function being created here takes a date-valued argument, it is not itself considered to be date-valued since it does not produce values that look like the standard VA FileMan internal representation of a date. If this function was only meaningful in a word-processing context, you would put a W at the "WORD-PROCESSING:" prompt.
NOTE: If there is an OUTPUT transform on a field, the function code is applied to the field after it has been transformed. In most cases, if a field has an OUTPUT transform, you should therefore use the following syntax:
FUNCTION_NAME(INTERNAL(FIELD_NAME))
Rather than:
FUNCTION_NAME(FIELD_NAME).
A function can also be defined as taking no arguments. This is very similar to the special variables in M like $I and $H. For example, you could define a function like BELL as follows:
Figure 419: VA FileMan Functions—Sample Function without Arguments
Select COMPUTED-FIELD FUNCTION: BELL <Enter>
ARE YOU ADDING A NEW COMPUTED-FIELD FUNCTION? Y <Enter> (YES)
MUMPS CODE: SET X=$C(7) <Enter>
EXPLANATION: CAUSES A 'BEEP' TO OCCUR ON OUTPUT <Enter>
DATE-VALUED: NO <Enter>
NUMBER OF ARGUMENTS: 0 <Enter>
WORD-PROCESSING: <Enter>
Users could then embed "beeps" in OUTPUT templates by entering:
FIRST PRINT FIELD: BELL <Enter>
NOTE: No parentheses are shown for a function that has no arguments.
You can delete a function in the usual way by deleting the NAME of the function. Such deletions do not harm any COMPUTED fields that already have been created using the function. However, you cannot edit the COMPUTED field unless you remove reference to the deleted function.
CAUTION: Due to concatenation, do not use IF, FOR, or QUIT statements when defining functions. Also, any variables you introduce within a function's code (but not X, X1, etc.) should be NEWed.
The FUNCTION (#.5) file already contains several functions.
REF: For a description of the functions exported with VA FileMan, see the "VA FileMan Functions" section in the VA FileMan Advanced User Manual.
Reviewed/Updated: May 2026