       $set mfoo
      ************************************************************************
      * Copyright (C) 1996-1999 Micro Focus International Ltd.
      * All rights reserved.
      *  
      * This demonstration program is provided for use by users of 
      * Micro Focus products (the "Software") and may be used, 
      * modified and distributed as part of your application provided 
      * that you properly acknowledge the copyright of Micro Focus in this
      * material.
      *     
      * All conditions, warranties and undertakings, express or implied, 
      * statutory or otherwise, on the part of Micro Focus are excluded, 
      * including without limitation those of merchantability or fitness  
      * for purpose. This shall not, however, purport to exclude or 
      * restrict the liability of Micro Focus to any extent not 
      * permitted by law.
      *
      * IN NO EVENT WILL MICRO FOCUS BE LIABLE FOR ANY INDIRECT, 
      * INCIDENTAL, SPECIAL, CONSEQUENTIAL OR OTHER DAMAGES ARISING OUT 
      * OF THE USE OF THE DEMONSTRATION PROGRAM DISTRIBUTED WITH THE 
      * SOFTWARE, WHETHER OR NOT INFORMED OF THE POSSIBILITIES OF 
      * DAMAGES IN ADVANCE.  THESE LIMITATIONS APPLY TO ALL CAUSES OF 
      * ACTION, INCLUDING BREACH OF CONTRACT, BREACH OF WARRANTY, STRICT
      * LIABILITY, AND ANY ACTIONS IN TORTS.
      ************************************************************************
      * Program to create five different types of collection and
      * initialize with intrinsic values.
      ************************************************************************

       class-control.
           OrderedCollection is class "ordrdcll"
           Array is class "array"
           Bag is class "bag"
           SortedCollection is class "srtdclln"
           CharacterArray is class "chararry"
           ValueSet is class "valueset"
           .

       working-storage section.
      *----Data for initializing the collections
           01  loopCount               pic x(4) comp-5.
           01  element                 pic x(4) comp-5.
           01  element2                pic x(4) comp-5.
           01  i                       pic x(4) comp-5.

      *----Boolean variable to receive results from some collection
      *    methods.
           01  trueOrFalse             pic x comp-5.
               88  isTrue              value 1.
               88  isFalse             value 0.

      *----Object references to hold collection instances and
      *    a class template for COBOL intrinsic data.
           01  aBag                    object reference.
           01  anArray                 object reference.
           01  anOrderedCollection     object reference.
           01  aSortedCollection       object reference.
           01  aString                 object reference.
           01  aValueSet               object reference.
           01  fruitdata.
               03  filler pic x(20) value "Mango".
               03  filler pic x(20) value "Apple".
               03  filler pic x(20) value "Pear".
               03  filler pic x(20) value "Banana".
               03  filler pic x(20) value "Apricot".
               03  filler pic x(20) value "Strawberry".
               03  filler pic x(20) value "Kiwifruit".
               03  filler pic x(20) value "Grape".
               03  filler pic x(20) value "Lemon".
               03  filler pic x(20) value "Orange".

           01  collectionData          pic x(20)
                                       occurs 10 times
                                       redefines fruitData.

       procedure division.
      *----A001. Create an array of 10 elements.
           move 10 to i
           invoke Array "ofReferences" using i
                               returning anArray
      *----A002. Create an ordered collection.
           invoke OrderedCollection "ofReferences"
                                    using i
                                returning anOrderedCollection
      *----A003. Create a sorted collection
           invoke SortedCollection "ofReferences" using i
                                          returning aSortedCollection
      *----A004. Create a bag.
           invoke Bag "ofreferences" using i
                                 returning aBag
      *----A005. Create a ValueSet.
           invoke ValueSet "ofReferences" using i
                                      returning aValueSet
      *----A006. Store CharacterArray instances for the strings declared
      *          in working storage.
           move 20 to i
           perform varying loopCount from 1 by 1
                                     until loopCount > 10
      *--------A007. Create a CharacterArray for each of the data items
      *        in the table. CharacterArrays are used for holding and
      *        manipulating strings.
               invoke CharacterArray "withLengthValue"
                      using i collectionData(loopCount)
                  returning aString
      *--------A008. Store the string in each collection.
               invoke aValueSet "add" using aString
                                  returning aString
               invoke aBag "add" using aString
                             returning aString
               invoke anArray "atPut" using loopcount aString
                                  returning aString
      *--------A009. Although the OrderedCollection and SortedCollection
      *              are indexed, when these collections are empty you
      *              have to "add" the new elements.
               invoke anOrderedCollection "add" using aString
                                            returning aString
               invoke aSortedCollection "add" using aString
                                          returning aString
           end-perform

      *----A010. Get the fourth element from the Array and display it.
           move 4 to loopCount
           invoke anArray "at" using loopCount
                           returning aString
           invoke aString "display"
           display " "

      *----A011. Bags are not indexed, so ask the bag if it includes an
      *    element with the value of aString. You query a ValueSet in
      *    the same way.
           invoke aBag "includes" using aString
                              returning trueOrFalse
           if isTrue
               display  "Bag contains " with no advancing
               invoke aString "display"
           else
               display  "Bag does not contain " with no advancing
               invoke aString "display"
           end-if
           display " "
      *----A012. Bags (unlike ValueSets) allow duplicates. You can
      *          add a second occurrence of the element.
           invoke aBag "add" using aString
                         returning aString
      *----A013. You can ask a bag how many occurrences it
      *    contains of a particular element.
           invoke aBag "occurrencesOf" using aString
                                   returning i
           display "Bag contains " i " occurrences of "
                   with no advancing
           invoke aString "display"
           display " "
      *----A014. You can ask any type of collection how many occurrences
      *    it has of a particular element.
           invoke anArray "occurrencesOf" using aString returning i
           display "Array contains " i " occurrences of "
                   with no advancing
           invoke aString "display"
           display " "
      *----A015. The next statement adds a second occurrence of aString
      *           to the ValueSet. ValueSets do not maintain duplicates,
      *           so when we query the ValueSet it will still return 1.
           invoke aValueSet "add" using aString
                              returning aString
           invoke aValueSet "occurrencesOf" using aString returning i
           display "ValueSet contains " i " occurrences of "
                   with no advancing
           invoke aString "display"
           display " "
      *----A016. Display the entire contents of the sorted and ordered
      *    collections, to show the different order of aStrings.
           perform varying loopCount from 1 by 1 until loopCount > 10
               invoke anOrderedCollection "at" using loopCount
                                           returning aString
               invoke aString "display"
               invoke aSortedCollection "at" using loopcount
                                         returning aString
               invoke aString "display"
               display " "
           end-perform
       .



