delitem

Deletes an item from a list.

delitem  List,  N

delitem/id{/case}  List,  Index

Example: delitem/id vList,"ab"

Qualifiers

Qualifiers
Qualifier Description
/id Delete the item with the value Index from an associative list.
/case Match the case specified in Index.

Parameters

Parameters
Parameter Data Type Description
List String Uniface list from which an item is to be deleted.
N Number Number of the item in an indexed list. (Items are numbered starting with 1.)
Index String Value in an associative list; it cannot be an expression.

Return Values

Values returned in $status
Value Description
0 No item was deleted
>0 Item number of the item that was deleted from List

Use

Allowed in all component types.

Description

The delitem statement deletes an item from List. For more information, see Lists and Sublists.

To delete all items from a list, set the list equal to an empty string ("") using an assignment; for example, if the variable $1 contains a list, the following statement creates an empty list:

$1 = ""

Indexed lists

Use the delitem statement without switches to delete the Nth item from List.

If List contains an associative list, the entire ValRep for the Nth item is deleted. If N is -1, the last item in List is deleted. Otherwise, if N does not refer to an existing item, no item is deleted.

Associative lists

Use the /id switch to delete the item whose value is Index from an associative list.

By default, matching Index with item values is not case-sensitive. For example, the following statement deletes from $LIST$ the first item encountered whose value is ab, Ab, aB, or AB:

delitem/id $list$,"ab"

Use the /case switch with /id to cause the matching to be case-sensitive. For example, the following statement only deletes an item whose value is ab:

delitem/id/case $list$,"ab"

Note:  In the examples below, an underlined semicolon (;) represents the Uniface sub-field separator (by default, GOLD ;).

The following example deletes the third item from an indexed list.

$valrep(DBMSFLD) = "mss;ora;syb;db2"
; ValRep is "mss;ora;syb;db2"
delitem $valrep(DBMSFLD), 3
; ValRep is "mss;ora;db2"

The same item could also be deleted by treating the list as an associative list:

$valrep(DBMSFLD) = "mss;ora;syb;db2"
; ValRep is "mss;ora;syb;db2"
delitem/id $valrep(DBMSFLD), "syb"
; ValRep is "mss;ora;db2"

The following example deletes the item with the value 'tue' from an associative list:

$valrep(DATEFLD) = "mon=monday;tue=tuesday;wed=wednesday"
; ValRep is "mon=monday;tue=tuesday;wed=wednesday"
delitem/id $valrep(DATEFLD), "TUE"
; ValRep is "mon=monday;wed=wednesday"

Related Topics