Calling a DEFINE FUNCTION in a Master File

How to:

You can reference a DEFINE FUNCTION in an expression in a Master File DEFINE, COMPUTE, or FILTER field. The DEFINE FUNCTION will be loaded into memory when its associated expression is used in a request.

Note: A DEFINE FUNCTION cannot be used in a multi-root Master File.


Top of page

x
Syntax: How to Call a DEFINE FUNCTION in a Master File Expression
DF.[appname/]filename.functionname(parm1, parm2, ...);
  [DESCRIPTION='description',$

where:

appname

Is an optional application name under which the DEFINE FUNCTION FOCEXEC is stored.

filename

Is the name of the FOCEXEC that contains the DEFINE FUNCTION definition. The FOCEXEC can contain multiple DEFINE FUNCTION definitions.

functionname(parm1, parm2, ...)

Is the function name with the parameters to be used in the expression.

'description'

Is an optional description enclosed in single quotation marks.



Example: Using a DEFINE FUNCTION in a Master File

The following DEFINE FUNCTION is stored in the DMFUNCS FOCEXEC. Given a last name and first name, it generates a full name in the format Lastname, Firstname:

DEFINE FUNCTION DMPROPER
DESCRIPTION 'Convert name to proper case and last, first format‘
(LASTNAME/A17, FIRSTNAME/A14) 
DMPROPER/A34V=LCWORD(17, LASTNAME, 'A17') 
             || (', ' | LCWORD(14, FIRSTNAME, 'A14')); 
END

The following is the DEFINE field named WHOLENAME added to the WF_RETAIL_CUSTOMER Master File that calls the DEFINE FUNCTION:

DEFINE WHOLENAME/A40 = DF.DMFUNCS.DMPROPER(LASTNAME, FIRSTNAME); 
     DESCRIPTION = 'Calls DMPROPER to create full name',$

The following request uses the DEFINE field WHOLENAME:

TABLE FILE WF_RETAIL_CUSTOMER
PRINT WHOLENAME AS Whole,Name
BY ID_CUSTOMER
WHERE ID_CUSTOMER LT 600
ON TABLE SET PAGE NOPAGE
END

The output is:

             Whole                       
ID Customer  Name                                   
-----------  -----                                  
         15  Nolan, Tyler                            
         20  Bull, Joshua                            
         78  Wood, Zara                              
        124  Mckenzie, Callum                        
        125  Charlton, Bradley                       
        132  Griffiths, Henry                        
        152  Rowe, Anthony                           
        161  Storey, Max                             
        185  Thomas, Evie                            
        201  Birch, Brandon                          
        213  Parry, Maisie                           
        239  Barrett, Taylor                         
        258  Lord, Harvey                            
        270  Bell, Jay                               
        312  Dunn, Daisy                             
        352  Mckenzie, Callum                        
        379  Fisher, Leo                             
        454  Day, Zak                                
        472  Howarth, Molly                          
        503  Barrett, Daniel                         
        531  Hargreaves, Chloe                       
        566  Fitzgerald, Bethany 

WebFOCUS