如何在cobol中移动表(数组)的多个元素

发布于 2024-12-17 20:28:09 字数 138 浏览 1 评论 0原文

我有一个数组,其中包含 CSV 文件中的记录。例如,我可以使用 move 语句将元素 5 到 10 移出到工作存储中吗?类似于:将 ExampleArray(5:10) 移至 WS-TEST。我被告知这是可能的,而不必循环遍历数组。但我似乎无法以这种方式编译它。

I have an array which holds a record from a CSV file. Can I for example use the move statement to move elements 5 to 10 out into working storage? Something like: MOVE ExampleArray(5:10) TO WS-TEST. I have been told this is possible instead of having to loop through the array. But I can not seem to get it to compile this way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

但可醉心 2024-12-24 20:28:09

您使用的语法称为引用修改。它相当于其他语言中的 substring() 。您的示例代码将尝试从 ExampleArray+5 移动 10 个字节。

支持“ALL”下标概念。它有局限性,但它可能会做你想要的。尝试类似的方法:

Move ExampleArray(ALL) to WS-Test

根据您的编译器,它可能会起作用。我认为规范将其使用限制为整数函数,但并非所有编译器都这样做。

说真的,执行循环非常简单和容易,只需编写以下代码:

Perform varying II from 1 by 1
  until II > (Length of ExampleArray-Area / Length of ExampleArray(1))

  Move ExampleArray(II) to WS-Test(II) 

End-Perform

The syntax you are using is called Reference Modification. It is the equivalent of substring() in other languages. Your example code would try to move 10 bytes from ExampleArray+5.

There is a "ALL" subscript concept that is supported. It has limitations, but it MIGHT do what you want. Try something like:

Move ExampleArray(ALL) to WS-Test

Depending upon your compiler, it MIGHT work. I think the spec limits its use to integer functions, but not all compilers do.

Seriously though, perform loops are very simple and easy, just code this:

Perform varying II from 1 by 1
  until II > (Length of ExampleArray-Area / Length of ExampleArray(1))

  Move ExampleArray(II) to WS-Test(II) 

End-Perform
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文