Operations in Uniface are the backbone of component-based development, allowing you to create reusable, modular code that can be invoked across different components. In this comprehensive guide, we'll explore everything you need to know about declaring and using operations in Uniface 10.4. π
Note: This article is based on the official Uniface Documentation 10.4, and I had assistance from AI in structuring this content.
π§ What Are Uniface Operations?
An operation is a ProcScript module that encapsulates specific functionality within a component. Think of it as a method or function that can be called internally or externally, depending on how you declare it.
π Basic Operation Syntax
{public | partner} operation OperationName | PredefinedOperationName
{public soap}
{public web | partner web }
{ScopeBlock} ; DSPs only
{ParamsBlock}
{VariablesBlock}
Your ProcScript
{end}
π― Operation Qualifiers Explained
Access Control
- public π - Default qualifier. Makes the operation available in the component signature for external activation
- partner π - Restricts the operation to internal use only within the component
Web Integration
- public soap π - Enables SOAP client access for Service components, DSPs, and USPs
- public web π‘ - Allows web browser, RESTful service, or web client access
- partner web π - DSP-specific qualifier for internal web operations
β‘ Predefined Operations
Uniface provides several predefined operations that handle specific component lifecycle events:
Operation | Purpose | Trigger |
---|---|---|
exec πββοΈ |
Default operation executed when component is activated | Component activation |
init π |
Executed when component instance is created | newinstance/activate |
cleanup π§Ή |
Executed when component is removed | Component removal |
attach π |
Executed when DSP is attached to parent | DSP attachment |
detach π |
Executed when DSP is detached from parent | DSP detachment |
π‘ Practical Example: Discount Calculator
Here's a real-world example of a service operation that calculates customer discounts:
operation DISCOUNT
params
string CUSTID : IN
numeric AMOUNT : INOUT
numeric PERCENTAGE : OUT
endparams
; Initialize discount
PERCENTAGE = 0
; Apply business rules
if ( CUSTID == "ufbv" ) PERCENTAGE = 20
if ( CUSTID == "acme" ) PERCENTAGE = 15
; Calculate final amount
AMOUNT = AMOUNT * ( 100 - PERCENTAGE) / 100
end
To call this operation from another component:
activate "SERV1".DISCOUNT (ID.CUST, TOTAL.INVOICE, $DISCOUNT$)
π Advanced Example: Recursive Operations
Operations can even call themselves recursively. Here's a factorial calculator:
operation FACTORIAL
params
numeric N : IN
numeric F : OUT
endparams
variables
numeric W
endvariables
if ( N > 1 )
W = N - 1
activate "calculator".FACTORIAL (W, F)
F = N * F
else
if ( N = 1 )
F = 1
else
F = 0
endif
endif
end
π Web Operations Best Practices
For DSPs (Dynamic Server Pages):
- Use
public web
for browser-accessible operations π - Use
partner web
for internal operations that still need scope data π§ - Always define scope blocks to control data exchange π
For Service Components:
- Use
public soap
for SOAP web services π§Ό - Use
public web
for RESTful services π‘
β οΈ Important Guidelines
Naming Conventions:
- Maximum 32 bytes length π
- Use letters (A-Z), digits (0-9), and underscores (_) only
- Must begin with a letter
- Avoid reserved names:
accept
,quit
,abort
,complete
β
Declaration Order:
- Scope block (DSPs only) π―
- Parameters block π
- Variables block π
- ProcScript logic π»
π Conclusion
Uniface operations provide a powerful way to structure your application logic into reusable, maintainable modules. Whether you're building traditional desktop applications or modern web services, understanding operation qualifiers and lifecycle events is crucial for effective Uniface development.
Remember to choose the right qualifier based on your access requirements and always follow proper naming conventions for maintainable code! π
Have questions about Uniface operations? Drop them in the comments below! π¬
Top comments (0)