Previous Topic Next topic Print topic


READ Collection Statement

Reads an element in the list or in the dictionary from a given key.

read-collection-statement

Note: Other formats of this statement are available. See Statements in the COBOL Language Reference.

Where: identifier is the name of the list or dictionary collection type.

Example

The following reads an element from a list collection:

       declare val as string
       read stringList into val key 0

The following example, shows exception handling and catching an exception on reading an invalid key in a dictionary collection:

       display "reading an invalid key message : " 
       read stringDictionary into val key "RUBBISH"
       invalid key
           display "Caught invalid key"
       not invalid key
           display "Shouldn't see this"
       end-read 

See also the Collections sample, which is available from Start > All Programs > Micro Focus Visual COBOL > Samples , under COBOL for JVM (Windows) or $COBDIR/demo (UNIX).

Previous Topic Next topic Print topic