Hey Uniface developers! 👋 If you're still using the length
statement in your Uniface applications, it's time for an update. With AI assistance helping me dive deep into this topic, let me walk you through why this statement is deprecated and what you should use instead.
📋 What is the length
Statement?
The length
statement in Uniface was used to return the number of characters in a specified string. It was a handy tool for string manipulation and validation tasks.
Basic Syntax:
length String
Example Usage:
vString = "test string"
length vString
vLength = $result
OUTPUT = vLength
⚠️ Why is it Deprecated?
According to the Uniface 10.4 documentation, the length
statement has been superseded by the $length
function, which offers better functionality across all component types.
🔄 Migration Path: From length
to $length
The transition is straightforward. Instead of using the statement format, you now use the function format:
Old (Deprecated) Way:
length vString
vLength = $result
New (Recommended) Way:
vLength = $length(vString)
💡 Key Features and Behavior
- Return Values: Sets
$result
to the number of characters in the string - Status:
$status
remains unaffected - Component Support: Allowed in all component types
- Special Characters: Ignores frame marker, ruler, and character attribute characters
🎯 Practical Example: Finding String Offsets
Here's a real-world example from the documentation showing how the length
statement was used to find the offset to the last two characters in a string:
; Field INVNUM contains: 90021387SH
; (Date: 13-Feb-1990, Number: 87, Initials: SH)
length INVNUM
$1=$result-1
$2=INVNUM[$1]
selectdb (sum(AMOUNT)) %/
from "INVOICES" %/
u_where (SALESCODE = $2) %/
to SALESREPORT.DUMMY
This example extracts the last two characters (salesman's initials) to use in a database query.
🚀 Best Practices Moving Forward
- Update existing code: Replace
length
statements with$length
functions - Code reviews: Watch for deprecated
length
usage in new code - Testing: Ensure functionality remains consistent after migration
- Documentation: Update your internal documentation to reflect the change
🔚 Conclusion
While the length
statement served us well, it's time to embrace the more versatile $length
function. This change aligns with Uniface's evolution toward more consistent and powerful string manipulation capabilities.
Remember: deprecated doesn't mean broken, but it does mean you should plan for migration in your development roadmap! 📅
This article is based on Uniface Documentation 10.4