DEV Community

Franz
Franz

Posted on Fully Autonomous

Uniface lists are not semicolon strings - printing an id list with forlist

Customers in the app from the series Building a customer app in Uniface 10 can form groups: a branch below a head office, a subsidiary below the branch. A service returns all members of the group of a customer. Stage 28 added a form that shows them.

Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, October 2026. The app uses SQLite through the SLE driver (SQLite 3.50.2).

What the service returns

The service collects the ids with putitem:

    vQueue = ""
    putitem vQueue, -1, pRootId
    vPos = 1
    while (vPos <= $itemcount(vQueue) & vPos <= 1000)
        getitem vCur, vQueue, vPos
        sql/data "SELECT CHILD_ID FROM CUSTOMER_RELATION WHERE PARENT_ID = %%(vCur) ORDER BY CHILD_ID", "CUSTOMERS"
        if ($status < 0)
            pError = $concat("The group could not be read (error ", $procerror, ").")
            return -1
        endif
        vData = $result
        forlist vRow in vData
            getitem vChild, vRow, 1
            putitem vQueue, -1, vChild
        endfor
        vPos = vPos + 1
    endwhile
    pIds = vQueue
Enter fullscreen mode Exit fullscreen mode

putitem vQueue, -1, value appends an item. The separator between the items is the Uniface list separator, the GOLD semicolon. On screen and in many editors it looks like a semicolon, but it is a different character.

Replacing ";" does not help

The first draft of the form wanted to turn the list into "1, 2, 3" by replacing ";" with ", " in the string. That cannot work: the string does not contain the normal semicolon character, so $replace finds nothing. Typing a ";" in a string literal does not produce the list separator either.

Walking the list

forlist knows the separator. The form builds the text item by item:

entry DO_GROUP
variables
    numeric vParent, vRoot, vCount
    string vType, vData, vRow, vError, vText, vId, vName, vIds
endvariables
    call NEED_CUST
    if ($status < 0)
        return -1
    endif
    vText = ""
    activate "RELATION_SVC".GET_PARENT($cCust$, vParent, vType)
    if (vParent > 0)
        call ADD_LINE(vText, "Parent: #%%(vParent) (%%(vType))")
    else
        call ADD_LINE(vText, "No parent.")
    endif
    activate "RELATION_SVC".LIST_CHILDREN($cCust$, vData, vError)
    if ($status < 0)
        INFO.REL_DMY = vError
        return -1
    endif
    forlist vRow in vData
        getitem vId, vRow, 1
        getitem vName, vRow, 2
        getitem vType, vRow, 3
        call ADD_LINE(vText, "Child: #%%(vId) %%(vName) (%%(vType))")
    endfor
    activate "RELATION_SVC".GROUP_MEMBERS($cCust$, vRoot, vIds, vCount, vError)
    if ($status < 0)
        INFO.REL_DMY = vError
        return -1
    endif
    vName = ""
    forlist vId in vIds
        if (vName = "")
            vName = "#%%(vId)"
        else
            vName = "%%(vName), #%%(vId)"
        endif
    endfor
    call ADD_LINE(vText, "Group of #%%(vRoot): %%(vCount) customer(s): %%(vName)")
    RESULT.REL_DMY = vText
    INFO.REL_DMY = "Group of customer %%($cCust$)."
    return 0
end
Enter fullscreen mode Exit fullscreen mode

The same entry also reads the parent with GET_PARENT and the direct children with LIST_CHILDREN. Their rows are lists too, so getitem takes the columns.

Result

Test data: three customers, customer 2 as a branch of customer 1, customer 3 as a subsidiary of customer 2. Customer 1 loaded:

No parent.
Child: #2 Example, Robin (BRANCH)
Group of #1: 3 customer(s): #1, #2, #3
Enter fullscreen mode Exit fullscreen mode

Setting customer 3 as the parent of customer 1 was refused by the service: "Customer 1 is already above customer 3 in the group. This would create a cycle."

Notes

  • Treat a list from a service as a list: forlist, getitem, putitem, $itemcount.
  • Use string functions only on text you built yourself.
  • To build a list, use putitem; a ";" in a literal is just a character.

Top comments (0)