gpt4 book ai didi

.net - Fujitsu COBOL 中的迭代 Systems.Collections.List

转载 作者:行者123 更新时间:2023-12-02 02:46:06 25 4
gpt4 key购买 nike

如何循环访问集合?

我使用的是 Fujitsu/Alchemy 编译器的试用版,但供应商的支持缓慢且糟糕。

我基本上想将一个列表从 C# 传递到 COBOL,然后让 COBOL 使用它并可能更新它。

在 C# 中,迭代集合的正常方法是使用“foreach”构造。

但是,C#“foreach”构造是以下内容的快捷方式:

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);
}
}

如果你能帮我弄清楚如何声明这个类,我可以用 COBOL 编写这个:

System.Collections.Generic.List<IDMSMapField>.Enumerator

“枚举器”结构是 documented on Microsoft's MSDN site .

它告诉我们“Enumerator”是一个结构,而不是一个类!

据我在手册“CreatingCOBOLfromDotnetFrameworkDox.pdf”中所知,结构被定义为 COBOL 存储库中的类。

手册中的示例:

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.

下面,我重复了一些我尝试过但都无法编译的变体,因为“无法解决”错误。如果你能告诉我如何正确声明这一点,我认为我们可以继续前进。

1.

    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.

  1. 与此完全相同的错误:

        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.

  1. 同样的错误:

    存储库。 CLASS CLASS-LIST AS“System.Collections.Generic.List<>” 类结构枚举器为“System.Collections.Generic.List.Enumerator” .

error JMN1795I-S: The named reference 'System.Collections.Generic.List.Enumerator' cannot be resolved.

另一种选择是将其视为数组,但我也坚持这一点。

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.

我认为编译器可能将 (1) 视为子字符串操作。

最佳答案

这花了一段时间,但这是一个完整的工作示例。还有其他一些获取属性的技巧,并使用正确的 USAGE 子句将属性值(例如 Count)移动到 COBOL 变量。“EXPANDS”关键字(在存储库中)是该解决方案的另一个关键部分。

在我的实际程序中,我将在 LINKAGE 部分收到列表,并且我将有一个更复杂对象的列表...但示例代码是一个更简单的场景,独立运行并“作为是”。

   IDENTIFICATION DIVISION.
PROGRAM-ID. MAIN AS "COBOLEnumerationSample.Main".
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
REPOSITORY.
CLASS List AS "System.Collections.Generic.List<>"
CLASS SysString AS "System.String"
CLASS SysBoolean AS "System.Boolean"
CLASS ListString EXPANDS List USING SysString
CLASS Enumerator AS "System.Collections.Generic.List<>+Enumerator"
CLASS StringEnumerator EXPANDS Enumerator USING SysString
PROPERTY PROP-Count AS "Count"
PROPERTY PROP-Current AS "Current"
.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 myList OBJECT REFERENCE ListString.
01 myEnum OBJECT REFERENCE StringEnumerator.
01 myBooleanEnumResult OBJECT REFERENCE SysBoolean.
01 myDotNetString OBJECT REFERENCE SysString.
01 myLoopCounter PIC 9(4) value zero.
01 myCobolCount PIC S9(9) COMP-5 VALUE ZERO.
01 myCobolString PIC X(30) value spaces.
01 YN-END-LOOP PIC X value "N".
01 WS-ACCEPT-INPUT PIC X(80) value spaces.

PROCEDURE DIVISION.
1000-START.
INVOKE ListString "NEW" returning myList.
INVOKE myList "Add" using "Apples"
INVOKE myList "Add" using "Bananas"
INVOKE myList "Add" using "Orange"


SET myCobolCount to PROP-Count of myList
DISPLAY "Size of MyList = " myCobolCount

INVOKE myList "GetEnumerator" returning myEnum.


PERFORM UNTIL YN-END-LOOP = "Y"
INVOKE myEnum "MoveNext" returning myBooleanEnumResult
* How to test for Boolean, True = B'1' and False = B'0'
IF myBooleanEnumResult = B'0'
MOVE "Y" TO YN-END-LOOP
ELSE
SET myDotNetString TO PROP-Current of myEnum
ADD 1 TO myLoopCounter
SET myCobolString to myDotNetString
DISPLAY myLoopCounter " " myCobolString
END-IF

END-PERFORM

DISPLAY "END OF PROGRAM - PRESS ENTER TO END"
ACCEPT WS-ACCEPT-INPUT
.

END PROGRAM MAIN.

关于.net - Fujitsu COBOL 中的迭代 Systems.Collections.List,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6272349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com