DEV Community

Peter + AI
Peter + AI

Posted on

Mastering Uniface getlistitems: Your Complete Guide to List Operations πŸ“‹

Working with lists in Uniface can be incredibly powerful once you understand the getlistitems statement. This comprehensive guide will walk you through everything you need to know about copying multiple items from lists into fields or variables. πŸš€

Note: This article is based on the official Uniface 10.4 documentation and was created with AI assistance to make complex concepts more accessible.

🎯 What is getlistitems?

The getlistitems statement is your go-to tool for copying multiple items from a list into fields or variables. Whether you're working with indexed lists or associative lists, this powerful statement handles the heavy lifting of data distribution.

πŸ“ Basic Syntax Overview

The getlistitems statement comes in several flavors:

  • Basic indexed list: getlistitems IndexedList, Field
  • Associative list: getlistitems/id AssociativeList, Target
  • Entity-specific: getlistitems/occ AssociativeList, Entity

πŸ”§ Key Qualifiers You Need to Know

Qualifier Description
/id Copies items from an associative list
/field Copies values to corresponding fields
/component Copies values to corresponding component variables
/global Copies values to corresponding global variables
/occ Copies values into fields of specified entity
/init Sets values without locking or changing modification status

πŸ’‘ Practical Examples

πŸ“… Example 1: Filling Successive Occurrences

Perfect for creating calendar entries or similar repetitive data:

$LIST$ = "Monday;Tuesday;Wednesday"
setocc "CALENDAR", 1
getlistitems $LIST$, DAY.CALENDAR
; Result: Creates 3 occurrences with days of the week
Enter fullscreen mode Exit fullscreen mode

🏷️ Example 2: Working with ID-Value Pairs

Great for handling structured data with identifiers:

$LIST$ = "d1=Mon;d2=Tue;d3=Wed"
setocc "CALENDAR", 1
getlistitems/id $LIST$, NUM.CALENDAR, NAME.CALENDAR
; Result: NUM gets "d1", "d2", "d3" and NAME gets "Mon", "Tue", "Wed"
Enter fullscreen mode Exit fullscreen mode

πŸŽͺ Example 3: Dynamic Field Assignment

This is where things get really interesting - dynamic field assignment:

$LIST$ = "NAME=Frodo;$LOC_TOT$=14;$$GLOB_TOT=329;$1=-8"
getlistitems/id $LIST$
; Automatically assigns values to different variable types based on naming
Enter fullscreen mode Exit fullscreen mode

⚑ Pro Tips for Success

🎯 Target Type Recognition

The system automatically recognizes target types based on dollar sign notation:

  • Fields: No dollar signs (e.g., NAME)
  • Component variables: Single dollar signs (e.g., $NAME$)
  • Global variables: Double dollar signs (e.g., $$NAME)
  • General variables: Number with dollar (e.g., $1)

πŸ” Return Values Matter

Always check the $status variable:

  • 0: No items were copied
  • >0: Number of items successfully copied

⚠️ Important Considerations

🚫 Limitations to Remember

  • getlistitems/id/global cannot be used in self-contained Service and Report components
  • Referenced fields cannot be included in Automatic field lists
  • The compiler cannot verify the existence of referenced objects at compile time

πŸ› οΈ Best Practices

  • Always ensure referenced fields are included in the entity's field list
  • Define all component and global variables before use
  • Use meaningful names in your associative lists for better code maintenance
  • Consider using the /init qualifier when you don't want to trigger modification flags

🎭 Advanced Use Cases

πŸ“Š Entity-Specific Operations

When working with multiple entities that might have duplicate field names:

$LIST$ = "day1=Mon;day2=Tue;day3=Wed"
getlistitems/occ $LIST$, "WEEK"
; Specifically targets the WEEK entity
Enter fullscreen mode Exit fullscreen mode

πŸ”„ Flexible Variable Assignment

Use target qualifiers for more control:

; Force all assignments to component variables
getlistitems/id/component $LIST$

; Force all assignments to global variables  
getlistitems/id/global $LIST$

; Force all assignments to fields
getlistitems/id/field $LIST$
Enter fullscreen mode Exit fullscreen mode

πŸŽ‰ Conclusion

The getlistitems statement is a powerhouse for data manipulation in Uniface. Whether you're populating form fields, managing component variables, or handling complex data structures, mastering this statement will significantly improve your development efficiency. πŸš€

Remember to always test your list operations thoroughly and consider the scope and lifecycle of your target variables. With practice, you'll find getlistitems to be an indispensable tool in your Uniface development toolkit! πŸ’ͺ

Happy coding! 🎯

Top comments (0)