How do I loop through a collection?
I'm on a trial version of Fujitsu/Alchemy compiler, and getting slow and poor support from the vendor.
I basically want to pass a List from C# to COBOL, and then let the COBOL use it and potentially update it.
In C#, the normal way of iterating through a collection is to use the "foreach" construct.
However, the C# "foreach" construct is a shortcut for the following:
private static void test1()
{
List<IDMSMapField> list1 = new List<IDMSMapField>();
int listSize = list1.Count;
// was just checking exact variablename and case here to copy into COBOL code.
int itemNumber = 0;
System.Collections.Generic.List<IDMSMapField>.Enumerator enumerator1 = list1.GetEnumerator();
while (enumerator1.MoveNext())
{
Console.Write("Okay" + enumerator1.Current);
}
}
I can write this in COBOL if you can help me figure out to declare this class:
System.Collections.Generic.List<IDMSMapField>.Enumerator
The "Enumerator" structure is documented on Microsoft's MSDN site.
It tells that "Enumerator" is a Struct, not a Class!
From what I can tell in the manual "CreatingCOBOLfromDotnetFrameworkDox.pdf", structures are defined as classes in the COBOL REPOSITORY.
Example from the manual:
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.
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.
1.
REPOSITORY.
CLASS CLASS-LIST AS "System.Collections.Generic.List<>"
CLASS STRUCT-Enumerator AS "System.Collections.Generic.List<>.Enumerator"
.
Error on second line:
error JMN1795I-S: The named reference 'System.Collections.Generic.List<>.Enumerator' cannot be resolved.
Exact same error for this:
REPOSITORY. CLASS CLASS-LIST AS "System.Collections.Generic.List<>" CLASS STRUCT-Enumerator AS "System.Collections.Generic.List<T>.Enumerator" .
error JMN1795I-S: The named reference 'System.Collections.Generic.List.Enumerator' cannot be resolved.
Same error for this:
REPOSITORY. CLASS CLASS-LIST AS "System.Collections.Generic.List<>" CLASS STRUCT-Enumerator as "System.Collections.Generic.List.Enumerator" .
error JMN1795I-S: The named reference 'System.Collections.Generic.List.Enumerator' cannot be resolved.
The other alternative is to treat it as an array, but I'm stuck on that as well.
REPOSITORY.
CLASS LIST-IDMSMapField AS "System.Collections.Generic.List<>[]"
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).
error JMN2671I-S: ':' must be specified in the reference modifier. ':' is assumed.
I think the compiler sees the (1) as a substring operation perhaps.