WebSphere Message Broker, Version 8.0.0.7 Operating Systems: AIX, HP-Itanium, Linux, Solaris, Windows, z/OS

See information about the latest product version

CARDINALITY function

The CARDINALITY function returns the number of elements in a list.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-CARDINALITY--(--ListExpression--)---------------------------><

CARDINALITY returns an integer value giving the number of elements in the list specified by ListExpression.

ListExpression is any expression that returns a list. All the following, for example, return a list:
  • A LIST constructor
  • A field reference with the [] array indicator
  • Some SELECT expressions (not all return a list)

A common use of this function is to determine the number of fields in a list before iterating over them.

Examples

-- Determine the number of F1 fields in the message.
-- Note that the [ ] are required   
DECLARE CountF1 INT CARDINALITY(OutputRoot.XMLNS.Data.Source.F1[]);
-- Determine the number of fields called F1 with the value 'F12' in the message.
-- Again note that the [ ] are required
DECLARE CountF1F12 INT     
  CARDINALITY(SELECT F.* FROM OutputRoot.XMLNS.Data.Source.F1[] AS F 
              where F = 'F12');
-- Use the value returned by CARDINALITY to refer to a specific element 
-- in a list or array:
-- Array indices start at 1, so this example refers to the third-from-last
-- instance of the Item field
Body.Invoice.Item[CARDINALITY(Body.Invoice.Item[]) - 2].Quantity
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2016Copyright IBM Corporation 1999, 2016.

        
        Last updated:
        
        Last updated: 2016-05-23 14:47:12


Reference topicReference topic | Version 8.0.0.7 | ak05530_