DEV Community

Franz
Franz

Posted on

Working with Uniface Lists Using `putitem` and `getitem`

In Uniface ProcScript, putitem adds or replaces list items, while getitem copies an item into a variable. This example uses an indexed list, with positions starting at 1.

Build, read, and update a list

Add this operation to your component’s Script section:

public operation LIST_DEMO
variables
  string vMonths, vMonth
endvariables

vMonths = ""

; Append three items.
putitem vMonths, -1, "January"
putitem vMonths, -1, "February"
putitem vMonths, -1, "March"

; Read the second item: February.
getitem vMonth, vMonths, 2
putmess vMonth

; Replace the second item, then read it again.
putitem vMonths, 2, "April"
getitem vMonth, vMonths, 2
putmess vMonth

return 0
end
Enter fullscreen mode Exit fullscreen mode

Expected message output:

February
April
Enter fullscreen mode Exit fullscreen mode

Remember these rules

  • putitem vList, -1, value appends an item.
  • putitem vList, 2, value replaces the second item. A position beyond the list’s end creates empty intermediate items.
  • getitem vValue, vList, 2 reads the second item without removing it. Index -1 reads the last item.
  • After getitem, $status > 0 indicates the copied item’s position. If no item was copied, $status is 0 and the target is empty. Check the status immediately when handling a potentially missing item.

Use putitem to construct the list instead of typing ordinary semicolons: Uniface uses special list separators.

Top comments (0)