Highlighted
Absent Member.
Absent Member.
1723 views

List Initialization

Jump to solution

Hi,

 

How can I do this in COBOL ?

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

 

Best Regards

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: List Initialization

Jump to solution

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

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: List Initialization

Jump to solution

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.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: List Initialization

Jump to solution

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

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.