COBOL 混乱

发布于 2024-07-15 17:51:53 字数 280 浏览 2 评论 0原文

嘿大家。 我在尝试使用 COBOL 在 zOS 环境中解决的编码项目中遇到了一些麻烦。 我需要读入一个文件并将它们放入索引表中(我知道记录将少于 90 条)。

让我困惑的是,我们受项目参数的约束,必须使用名为“Table-Size”的变量(在声明时设置为零)。

鉴于这一切,我需要做类似“根据表大小出现 1 到 90 次”之类的事情,但我不明白如果表大小必须这样做(据我所知),那么它将如何工作,因为表-大小随着添加到表中的每个条目而增加。 谁能帮我解决这个问题吗?

谢谢!

Hey, everyone. I'm having a bit of trouble in a coding project that I'm trying to tackle in the zOS environment using COBOL. I need to read a file in and put them into an indexed table (I know there will be less than 90 records).

The thing that is throwing me is that we are bound by the parameters of the project to use a variable called "Table-Size" (set to zero at declaration).

Given all that, I need to do something like "Occurs 1 to 90 times Depending on Table-Size", but I don't understand how that will work if table-size has to (as far as I can tell) because table-size is incremented along with each entry that is added to the table. Can anyone please clear this up for me?

Thanks!

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

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

发布评论

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

评论(2

云醉月微眠 2024-07-22 17:51:53

听起来您主要关心的是:如果大小在运行时发生变化,编译器如何知道在数组中分配多少?

答案是它分配最大空间量(足以容纳 90 个条目)。 请注意,这是工作存储中的空间。 当记录写入文件时,仅写入相关部分。

示例:

01  TABLE-SIZE  PIC 9
01  TABLE OCCURS 1 TO 9 TIMES DEPENDING ON TABLE-SIZE
    03 FLD1  PIC X(4)

这将为工作存储中的 TABLE 分配 36 个字符(9 乘以 4)。 如果将记录写入文件时将 TABLE-SIZE 设置为 2,则只会写入 TABLE 的 8 个字符(以上)当然,是为 TABLE-SIZE 编写的字符)。

因此,例如,如果 TABLE 占用的内存为 AaaaBbbbCcccDdddEeeeFfffGgggHhhhIiii,则写入文件的日期可能会缩短(包括大小):2AaaaBbbb

同样,当读回记录时,TABLE-SIZETABLE 的相关位都将从文件中填充(仅设置大小和前两个元素) 。

我不认为发生这种情况时未使用的 TABLE 条目会被初始化为任何东西。 最好假设无论如何都不会,如果您需要向表中添加另一个项目,则显式填充它们。

为了提高效率,您可能需要考虑将 TABLE-SIZE 设置为 USAGE IS COMP

It sounds like your primary concern is: how does the compiler know how much to allocate in the array if the size changes at run-time?

The answer is that it allocates the maximum amount of space (enough for 90 entries). Note that this is for space in working storage. When the record is written to a file, only the relevant portion is written.

An example:

01  TABLE-SIZE  PIC 9
01  TABLE OCCURS 1 TO 9 TIMES DEPENDING ON TABLE-SIZE
    03 FLD1  PIC X(4)

This will allocate 36 characters (9 multiplied by 4) for TABLE in working storage. If TABLE-SIZE is set to 2 when the record is written to a file, only 8 characters of TABLE will be written (over and above the characters written for TABLE-SIZE, of course).

So, for example, if the memory occupied by TABLE was AaaaBbbbCcccDdddEeeeFfffGgggHhhhIiii, the date written to the file may be the shortened (including size): 2AaaaBbbb.

Similarly, when the record is read back in, both TABLE-SIZE and the relevant bits of TABLE will be populated from the file (setting only the size and first two elements).

I don't believe that the unused TABLE entries are initialised to anything when that occurs. It's best to assume not anyway, and populate them explicitly if you need to add another item to the table.

For efficiency, you may want to consider setting the TABLE-SIZE to USAGE IS COMP.

尸血腥色 2024-07-22 17:51:53

我们这里没有足够的信息,但基本的是 DEPENDING ON 子句中命名的变量必须具有变量组数的计数。 所以你需要类似的东西

01   TABLE-SIZE     PIC 99
01   TABLE OCCURS 1 TO 90 TIMES
       DEPENDING ON TABLE-SIZE
    03 FIELD-1
    03 FIELD-2

等等。

请参阅本文这个文章在Publib。

We don't have quite enough information here, but the basic thing is that the variable named in the DEPENDING ON clause has to have a count of the variable number of groups. So you need something like

01   TABLE-SIZE     PIC 99
01   TABLE OCCURS 1 TO 90 TIMES
       DEPENDING ON TABLE-SIZE
    03 FIELD-1
    03 FIELD-2

and so on.

See this article or this article at Publib.

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