🔧 Mastering Uniface's creocc Function: Creating Empty Entity Occurrences Like a Pro
Peter + AI

Peter + AI @petercode

Joined:
Jul 12, 2025

🔧 Mastering Uniface's creocc Function: Creating Empty Entity Occurrences Like a Pro

Publish Date: Jul 13 '25
0 0

🎯 What is creocc?

The creocc statement in Uniface 10.4 is a powerful tool that creates empty occurrences of specified entities. Think of it as your data structure builder - it prepares empty containers where you can later store your actual data! 📦

📝 Syntax

creocc Entity, OccurrenceNumber
Enter fullscreen mode Exit fullscreen mode

Example:

creocc "P_ORDER", -1
Enter fullscreen mode Exit fullscreen mode

🔍 Parameters Breakdown

Parameter Data Type Description
Entity String Name of the entity where an occurrence will be created
OccurrenceNumber Number Integer value (truncated if decimal) specifying position

📊 Return Values & Error Handling

$status Values:

  • < 0: ❌ Error occurred (check $procerror for details)
  • >= 0: ✅ Statement executed successfully

Common Error Codes:

  • -1102 (UPROCERR_ENTITY): Invalid entity name or entity not painted on component
  • -1203 (UPROCERR_RANGE): Occurrence number out of range

🎮 How OccurrenceNumber Works

The magic happens based on the OccurrenceNumber value:

  • < 0: 📌 Appends occurrence after the last one ($hits+1)
  • = 0: 🔄 Inserts before current occurrence (shifts sequence numbers)
  • 1 to $hits+1: 🎯 Creates occurrence at specified position
  • > $hits+1: ⚠️ Sets $status to -1, no occurrence created

💡 Real-World Example: Video Database Conversion

Here's a practical example showing how creocc converts raw text data into structured occurrences:

operation exec
    retrieve "VIDEO_DONE"          ; get video data (text)
    setocc "VIDEO_DATA", 1         ; position at first occurrence
    $10 = 0                        ; zero counter

    repeat
        message/nobeep "loop counter = %%$10"
        creocc "VIDEO_DONE", -1    ; make an empty occurrence

        if ($status < 0)
            break
        endif

        ; Transfer data from text to structured format
        V_NUM.VIDEO_DONE = TAPE_NUM.VIDEO_DATA

        ; Convert start time
        $1 = START
        call TEXT_TO_TIME
        V_START = $2

        ; Convert end time  
        $1 = end
        call TEXT_TO_TIME
        V_END = $2

        ; Concatenate title fields
        V_TITLE_1.VIDEO_DONE = "%%TITLE_1.VIDEO_DATA%%TITLE_1A.VIDEO_DATA"
        V_TITLE_2.VIDEO_DONE = "%%TITLE_2.VIDEO_DATA%%TITLE_2A.VIDEO_DATA"

        $10 = $10 + 1
        setocc "VIDEO_DATA", ($curocc + 1)

        if ($status < 0)
            break
        endif
    until ($10 = $hits)

    edit
end; exec
Enter fullscreen mode Exit fullscreen mode

🎯 Key Takeaways

  • Versatility: Works in all Uniface component types 🌐
  • Smart Positioning: Flexible occurrence placement with negative, zero, and positive values
  • Error Handling: Built-in status checking for robust applications 🛡️
  • Data Migration: Perfect for converting unstructured data to structured formats

🚀 Pro Tips

Remember: If your entity only has a default empty occurrence, the first creocc won't add an additional one - but subsequent calls will! This behavior helps maintain clean data structures. 🧹

Happy coding with Uniface! 🎉


Based on Uniface Documentation 10.4 | Created with AI assistance

Comments 0 total

    Add comment