Commodore
Commodore
421 views

Index and Arrays

Jump to solution

I currently have the following array declared in my Windows Form

class-id TPS000.TPS0010DForm is partial

                inherits type System.Windows.Forms.Form.

       working-storage section.

       01 multi-line string property occurs 12.

 

The index for this array starts as (0) as follows:

     (0) = 1st Element

      (1) = 2nd Element

      (2) = 3rd Element

Etc………

Is there any way of forcing the index to start at 1 so that the elements are stored as follows:

     (1) = 1st Element

     (2) = 2nd Element

     (3)= 3rd Element

Etc…

Initializing the first index to 1 will make my program easier to code and to debug later on.

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Arrays are indexed as zero based in .NET by default while COBOL tables are indexed as 1 based.

In managed COBOL we support both depending on whether you reference the item using square brackets [] (0 based), or parenthesis () (1 based)

Example: 

01 mystring string occurs 10.
01 mysub    pic 9(2) value 0.
procedure division.

    perform varying mysub from 0 by 1 until mysub = 10
        set mystring[mysub] to mysub
    end-perform
    perform varying mysub from 1 by 1 until mysub > 10
        set mystring(mysub) to mysub
    end-perform

 

View solution in original post

4 Replies
Micro Focus Expert
Micro Focus Expert

Arrays are indexed as zero based in .NET by default while COBOL tables are indexed as 1 based.

In managed COBOL we support both depending on whether you reference the item using square brackets [] (0 based), or parenthesis () (1 based)

Example: 

01 mystring string occurs 10.
01 mysub    pic 9(2) value 0.
procedure division.

    perform varying mysub from 0 by 1 until mysub = 10
        set mystring[mysub] to mysub
    end-perform
    perform varying mysub from 1 by 1 until mysub > 10
        set mystring(mysub) to mysub
    end-perform

 

View solution in original post

Commodore
Commodore

Okay, thank you!

0 Likes
Commodore
Commodore
Thanks for the resource!
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.