Hey developers! π Today I want to share something useful about Uniface development that I've been working with recently. With some help from AI, I've put together this guide about the remocc
statement in Uniface 10.4 - a powerful function for managing database entity occurrences.
This post is based on the official Uniface documentation 10.4.
What is remocc? π€
The remocc
statement in Uniface marks an occurrence of a specified entity for deletion at the next store operation. Think of it as marking a database record for removal - it doesn't delete immediately, but flags it for deletion when you perform a store command.
Syntax π
remocc Entity, OccurrenceNumber
Example:
remocc "CUSTOMER", 0
Parameters Breakdown π§
- Entity (String): The entity where an occurrence should be removed. This can be a string, field, variable, function, or parameter that evaluates to a string containing the entity name.
- OccurrenceNumber (Number): The sequence number of the occurrence to remove. It's an integer value that gets truncated if necessary.
Understanding OccurrenceNumber Values π―
- < 0: Removes the last occurrence in the component structure
- 0: Removes the current occurrence (this is the default)
- > number of occurrences: Sets $status to -1 and removes nothing
Return Values & Error Handling β οΈ
The $status
variable tells you what happened:
- < 0: An error occurred (check
$procerror
for details) - >= 0: Sequence number of the occurrence that became current after removal
Common Error Codes:
-
-1
: General error - Entity is outer entity of Record component -
-1102
: Invalid entity name or entity not painted on component -
-1203
: Value out of range - OccurrenceNumber exceeds available occurrences
Behavior After remocc π
Here's what happens after you remove an occurrence:
- If removed occurrence isn't the last β next occurrence becomes active
- If removed occurrence is the last β previous occurrence becomes active
- If only one occurrence exists β it's removed and a new empty occurrence becomes current
Practical Example π‘
Here's a real-world example that removes customers with no outstanding debt:
trigger leaveModified
if (INVAMOUNT <= 0)
remocc "CUSTOMER", 0
message "Customer with no debt removed."
endif
end; leaveModified
Important Notes π
- The
remocc
statement sets the current entity, which can change the active path and trigger data validation - For filtering retrieved data you don't want to process, consider using
discard
statement oru_where
clause withread
statement instead - Deleted occurrences can still be found with
retrieve/o
(sets $status to 3) - The actual deletion happens when you execute a
store
command
Conclusion π
The remocc
statement is a powerful tool for managing entity occurrences in Uniface applications. It provides flexible ways to mark records for deletion while maintaining control over the component's state and data flow.
Remember to always handle the return values properly and understand the behavior changes that occur after removing occurrences. This will help you build more robust Uniface applications!
Happy coding! π
Top comments (0)