(Note: This blog post was drafted with the assistance of an AI to help structure and simplify the official technical documentation.)
Hello, fellow developers! π Today, we're diving into a specific but powerful function in the Uniface 10.4 ProcScript language: $totocc. If you've ever worked with data occurrences in Uniface components, you know how important it is to keep track of what's in memory versus what's in the database. That's exactly where $totocc comes in handy.
Let's break it down in simple terms.
What is $totocc? π€
In short, $totocc returns the total number of occurrences (think of them as records or rows) of an entity that are currently loaded inside a component. This includes records you've retrieved from the database AND new records you've added but haven't saved yet.
The basic syntax is:
$totocc {(Entity)}
The Entity parameter is optional. If you leave it out, Uniface assumes you mean the current entity you're working with.
The Key Difference: $totocc vs. $totdbocc π‘
This is the most important concept to grasp. These two functions might sound similar, but they track different things.
-
$totocc: Counts all occurrences currently in the component's memory. -
$totdbocc: Counts only the occurrences that exist in the database for the current component instance.
Imagine you have a form showing customer data. You retrieve 10 customers from the database and then add 2 new ones on the form.
-
$totdboccwill be 10. -
$totoccwill be 12 (the 10 from the database + 2 new ones).
This difference is crucial for building logic that handles unsaved changes!
Let's See an Example! π
The best way to understand is with code. Let's say you want to show a message telling the user how many new records they've added before saving.
You could write a simple script in a trigger like this:
trigger detail
; Check if there are more occurrences in the component than in the database
if ($totocc > $totdbocc)
; Calculate the difference (which is the number of new records)
$1 = ($totocc - $totdbocc)
message "You have added %%%$1 new customer(s)%%%."
endif
end; detail
In this example, if $totocc is 12 and $totdbocc is 10, the message will be: "You have added 2 new customer(s)." Simple and effective!
What Actions Affect the Value of $totocc?
Several standard ProcScript commands will change the value of $totocc during runtime. Hereβs a quick summary:
- β Increases $totocc:
-
^ADD_OCC: Adds 1. -
^INS_OCC: Adds 1. -
read: Adds 1 for each record read.
-
- β Decreases $totocc:
-
^REM_OCC: Subtracts 1. -
discard: Reduces the count by the number of discarded occurrences.
-
- π Resets $totocc:
-
clear: Resets the count to 1 (for the single empty occurrence).
-
Conclusion
And that's it! The $totocc function is a fundamental tool for managing data state within your Uniface applications. By comparing it with $totdbocc, you can easily determine what data is new, what's been retrieved, and build powerful, user-friendly logic around it.
Happy coding! π»
Top comments (0)