Skip to main content

Hi,

 

How can I do this in COBOL ?

List  testList = new List(){"jack","henry","lisa","sandy"};

 

Best Regards


#COBOL

Hi,

 

How can I do this in COBOL ?

List  testList = new List(){"jack","henry","lisa","sandy"};

 

Best Regards


#COBOL

There are a couple ways of handling generic Lists in Visual COBOL.

Look at the demo program in the samples browser called Generics and also the one called Collections to see the full range of what is available.

Here is the method using the new COBOL syntax for list handling.

      working-storage section.
      01 testList list[string].
      procedure division.

          create testList
     *> writing an element to a list
          write testList from "jack"
          write testList from "henry"
          write testList from "lisa"
          write testList from "sandy"

          perform varying mystring as string thru testList
             display mystring
          end-perform
          goback.


Hi,

 

How can I do this in COBOL ?

List  testList = new List(){"jack","henry","lisa","sandy"};

 

Best Regards


#COBOL

Every language seems to many different ways... so here some other ways to do the same thing...

You can also use "AddRange" to setup the array too..

     $set ilusing"System.Collections.Generic"

      declare testlist-1 as type List[string].

      set testlist-1 to new List[string]

      invoke testlist-1::AddRange("jack,henry,lisa,sandy"::Split(","))

      perform varying mystring as string thru testList-1

        display " 1 : " mystring

      end-perform

Or just a string[] instead...

      declare testlist-2 as string occurs any

      set content of testlist-2 to ("jack", "henry", "lisa", "sandy")

      perform varying mystring as string thru testList-2

        display " 2 : " mystring

      end-perform

Or both together..

      declare testlist-3-content as string occurs any

      declare testlist-3 as type List[string].

      set testlist-3 to new List[string]

      set content of testlist-3-content

          to ("jack", "henry", "lisa", "sandy")

      invoke testlist-3::AddRange(testlist-3-content)

      perform varying mystring as string thru testList-3

        display " 3 : " mystring

      end-perform