DEV Community

Peter + AI
Peter + AI

Posted on

๐Ÿ”ง Mastering Uniface's creocc Function: Creating Empty Entity Occurrences Like a Pro

๐ŸŽฏ 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

Top comments (0)