• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • Data Requirements
      • CSPro Program Structure
      • Programming Standards
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
        • Compiler Mode
        • Variables
        • Alias Statement
        • User-Defined Functions
        • Array Object
        • Audio Object
        • Case Object
        • Document Object
        • File Object
        • Freq Object
        • Geometry Object
        • HashMap Object
        • Image Object
        • List Object
        • Map Object
        • Pff Object
        • SystemApp Object
        • ValueSet Object
      • Procedural Sections
      • Logic
      • Language Elements
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

User-Defined Functions

User-defined functions are coded in the declaration portion (PROC GLOBAL) of an application. Once defined, they can be used anywhere in an application. Functions are used to perform operations that are used in several different places in an application.
Functions are of the form:
return_value = function_name(parameter_list);
Functions may include a list of parameters, which can vary depending on the function call's requirements. This list may be empty (that is, it contains no parameters between the opening and closing parentheses) or it may contain one or more parameters. Each parameter specifies a variable or object that is used by the statements within the function.
Numeric, string, and alphanumeric variables are local to the function. That is, if a variable is passed as an argument, its value in the rest of the application will not be changed by actions within the function (this is called "pass by value"). On the other hand, objects (such as arrays and file handlers) passed as arguments refer to the source variable and interactions on the variable affect the source variable (this is called "pass by reference"). If you want to pass a numeric or string variable by reference, you can use the ref keyword to signify that changes made in the function should affect the source variable.
A user-defined function:
  • Returns a single value, either numeric or alphanumeric.
  • Can contain CSPro statements and functions, as well as other user-defined functions. If no return value is assigned to the function, the value default (or a blank string) is returned.
The function statement allows the creation of a user-defined function.
You can use the invoke function or Logic.invoke action to call a function with the function name specified only at runtime. Additionally, you can execute user-defined functions while viewing HTML content by using the Action Invoker.
See also: Function Statement, Additional Examples of User-Defined Functions