title: Iterating Systems.Collections.List in Fujitsu COBOL
body: <p>How do I loop through a collection?</p>
  
  <p>I'm on a trial version of Fujitsu/Alchemy compiler, and getting slow and poor support from the vendor.</p>
  
  <p>I basically want to pass a List from C# to COBOL, and then let the COBOL use it and potentially update it.</p>
  
  <p>In C#, the normal way of iterating through a collection is to use the "foreach" construct.</p>
  
  <p>However, the C# "foreach" construct is a shortcut for the following:</p>
  
  <pre><code>private static void test1()
  {
      List&lt;IDMSMapField&gt; list1 = new List&lt;IDMSMapField&gt;();
      int listSize = list1.Count;
      // was just checking exact variablename and case here to copy into COBOL code.
      int itemNumber = 0;
  
      System.Collections.Generic.List&lt;IDMSMapField&gt;.Enumerator enumerator1 = list1.GetEnumerator();
  
      while (enumerator1.MoveNext())
      {
          Console.Write("Okay" + enumerator1.Current);
      }
  }
  </code></pre>
  
  <p>I can write this in COBOL if you can help me figure out to declare this class:</p>
  
  <pre><code>System.Collections.Generic.List&lt;IDMSMapField&gt;.Enumerator
  </code></pre>
  
  <p>The "Enumerator" structure is <a href="http://msdn.microsoft.com/en-us/library/x854yt9s.aspx" rel="nofollow">documented on Microsoft's MSDN site</a>.</p>
  
  <p>It tells that "Enumerator" is a Struct, not a Class!</p>
  
  <p>From what I can tell in the manual "CreatingCOBOLfromDotnetFrameworkDox.pdf", structures are defined as classes in the COBOL REPOSITORY.</p>
  
  <p>Example from the manual:</p>
  
  <pre><code>Define specifiers for structure in REPOSITORY, and any struct members:
  CLASS STRUCT-name AS "struct-namespace"
  PROPERTY PROP-struct-member AS "external-property-name"
  Handle structures like classes. E.g. object to store a struct instance:
  01 struct-object OBJECT REFERENCE STRUCT-name.
  </code></pre>
  
  <p>Below, I am repeating some of the variations I tried that have all failed to compile,
  because of "cannot be resolved" error. If you can show me howto to declare this properly,
  I think we can move forward.</p>
  
  <p>1.</p>
  
  <pre><code>    REPOSITORY.
             CLASS  CLASS-LIST         AS "System.Collections.Generic.List&lt;&gt;"
             CLASS  STRUCT-Enumerator  AS "System.Collections.Generic.List&lt;&gt;.Enumerator"
             .
  </code></pre>
  
  <p>Error on second line:</p>
  
  <blockquote>
    <p>error JMN1795I-S: The named reference 'System.Collections.Generic.List&lt;>.Enumerator' cannot be resolved.</p>
  </blockquote>
  
  <ol>
  <li><p>Exact same error for this:</p>
  
  <pre><code>    REPOSITORY.
             CLASS  CLASS-LIST         AS "System.Collections.Generic.List&lt;&gt;"
             CLASS  STRUCT-Enumerator  AS "System.Collections.Generic.List&lt;T&gt;.Enumerator"
             .
  </code></pre></li>
  </ol>
  
  <blockquote>
    <p>error JMN1795I-S: The named reference 'System.Collections.Generic.List.Enumerator' cannot be resolved.</p>
  </blockquote>
  
  <ol>
  <li><p>Same error for this:</p>
  
  <p>REPOSITORY.
       CLASS  CLASS-LIST         AS "System.Collections.Generic.List&lt;>"
       CLASS  STRUCT-Enumerator  as "System.Collections.Generic.List.Enumerator"
       .</p></li>
  </ol>
  
  <blockquote>
    <p>error JMN1795I-S: The named reference 'System.Collections.Generic.List.Enumerator' cannot be resolved.</p>
  </blockquote>
  
  <p>The other alternative is to treat it as an array, but I'm stuck on that as well.</p>
  
  <pre><code>REPOSITORY.
      CLASS LIST-IDMSMapField    AS "System.Collections.Generic.List&lt;&gt;[]"
      CLASS CLASS-IDMSMapField   AS "Lightyear.ERCB.IDMSDC.IDMSMapField"
      CLASS CLASS-LIST-IDMSMapField EXPANDS LIST-IDMSMapField USING CLASS-IDMSMapField.
  
  METHOD-ID. TW1DR4000-PF06 AS "TW1DR4000_PF06".
  DATA DIVISION.
  WORKING-STORAGE SECTION.
  
  01 MapFieldItem USAGE OBJECT REFERENCE CLASS-IDMSMapField.
  
  LINKAGE SECTION.
  
  01 MapFieldList USAGE OBJECT REFERENCE CLASS-LIST-IDMSMapField.
  
  PROCEDURE DIVISION...
  ...
  SET MapFieldItem TO MapFieldList(1).
  </code></pre>
  
  <blockquote>
    <p>error JMN2671I-S: ':' must be specified in the reference modifier. ':' is assumed.</p>
  </blockquote>
  
  <p>I think the compiler sees the (1) as a substring operation perhaps.</p>