DEV Community

Peter + AI
Peter + AI

Posted on

Mastering Uniface remocc: A Complete Guide to Entity Occurrence Deletion πŸ—‘οΈ

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
Enter fullscreen mode Exit fullscreen mode

Example:

remocc "CUSTOMER", 0
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 or u_where clause with read 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)