Zum Inhalt springen

# 🚀 Uniface call Statement: Executing Functions and ProcScript Modules

This post is based on Uniface 10.4 documentation and was created with AI assistance 🤖

As a Uniface developer, you’ll inevitably encounter the call statement – a powerful tool for executing functions and global ProcScript modules. Here’s a comprehensive explanation of this essential command! 💡

📝 Basic Syntax

call {Library::}LitFunctionName { ( ArgumentList ) }

Example

call myFunction

🔧 Parameters in Detail

Parameter Data Type Description
Library Literal Library containing the global ProcScript module. If not specified, the default library is used 📚
LitFunctionName Literal Name of the module (without quotation marks!)
ArgumentList String Comma-separated list of arguments. Must match the number and type of parameters defined in the function

🔄 Automatic Type Conversion

If the data type of an argument doesn’t match the corresponding parameter type, Uniface automatically attempts to convert the data to the proper type. This makes the call statement quite flexible in handling different data types! 🎯

🎯 Return Values and Status

$status Values

  • -1 ❌ Error occurred (details in $procerror)
  • 0 ⚪ No value assigned or no return statement
  • >0 ✅ Successful return value from the function

🚨 Common Errors in $procerror

  • -1109 (UPROCERR_FUNCTION): Function not found
  • -1113 (UPROCERR_PARAMETER): Invalid parameter name or not defined
  • -1122 (UPROCERR_NARGUMENTS): Wrong number of arguments

Note: When a call succeeds, $procerror is typically cleared or contains no error information.

🔄 Understanding Parameter Directions

IN Parameters

  • Accepts: Constants, fields, indirect field references, variables, functions
  • Behavior: Value is transferred to the module’s parameter at function start 📥

INOUT Parameters

  • Accepts: Fields, indirect field references, variables, assignable functions
  • Behavior: Value is transferred at start AND the function’s end value is returned to the original location 🔄

OUT Parameters

  • Accepts: Fields, indirect field references, variables, assignable functions
  • Behavior: Only the function’s end value is returned to the original location 📤

Important: If an error occurs (status = -1), values of OUT and INOUT parameters must be considered undefined in the calling component.

🎯 Practical Example from Real Usage

function LSTORE
    store
    if ($status < 0)
        message "Store error!"
        rollback
    else
        message "Store done."
        commit
    endif
end ; LSTORE

trigger store
    call LSTORE
    return ($status)
end; store

trigger accept
    if ($formdbmod = 1)
        call LSTORE
    endif
    return ($status)
end; accept

🔍 Understanding Module Resolution

Uniface searches for modules in the following order:

For Local Functions

  1. Local functions in the component’s triggers

For Global ProcScript (when no library specified)

  1. Component library
  2. Library specified in application shell properties
  3. SYSTEM_LIBRARY

For Global ProcScript (when library specified)

If Uniface cannot find the module in the specified library, it stops searching and returns an error – no fallback to other locations! 🚫

For detailed information about the search process, refer to the Compilation Process documentation.

💡 Best Practices and Tips

✅ Do’s

  • Use descriptive function names
  • Always check the $status value after the call
  • Match parameter count and types exactly
  • Handle potential type conversion scenarios

❌ Don’ts

  • Don’t put LitFunctionName in quotation marks
  • Avoid returning -1 from your functions (reserved for system errors)
  • Don’t ignore parameter direction requirements
  • Don’t use call for global ProcScripts in self-contained services/reports

⚠️ Structure Editor Consideration

Important: The $status value can affect how the structure editor behaves when activating trigger sequences. When calling functions in triggers, ensure the returned value doesn’t adversely impact the structure editor’s operation.

🎪 Availability

The call statement is available in all component types!

Exception: Calling global ProcScript modules is not allowed in self-contained services and reports. 🚫

🎉 Conclusion

The call statement is an indispensable tool for modular Uniface development. With proper understanding of parameter directions, automatic type conversion, error handling, and module resolution, you can create robust and maintainable applications!

Understanding these nuances will help you avoid common pitfalls and write more reliable Uniface code.

Do you have questions about Uniface or other development topics? Let me know in the comments! 💬

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert