COBOL 混乱
嘿大家。 我在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您主要关心的是:如果大小在运行时发生变化,编译器如何知道在数组中分配多少?
答案是它分配最大空间量(足以容纳 90 个条目)。 请注意,这是工作存储中的空间。 当记录写入文件时,仅写入相关部分。
示例:
这将为工作存储中的
TABLE
分配 36 个字符(9 乘以 4)。 如果将记录写入文件时将TABLE-SIZE
设置为 2,则只会写入TABLE
的 8 个字符(以上)当然,是为TABLE-SIZE
编写的字符)。因此,例如,如果
TABLE
占用的内存为AaaaBbbbCcccDdddEeeeFfffGgggHhhhIiii
,则写入文件的日期可能会缩短(包括大小):2AaaaBbbb
。同样,当读回记录时,
TABLE-SIZE
和TABLE
的相关位都将从文件中填充(仅设置大小和前两个元素) 。我不认为发生这种情况时未使用的
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:
This will allocate 36 characters (9 multiplied by 4) for
TABLE
in working storage. IfTABLE-SIZE
is set to 2 when the record is written to a file, only 8 characters ofTABLE
will be written (over and above the characters written forTABLE-SIZE
, of course).So, for example, if the memory occupied by
TABLE
wasAaaaBbbbCcccDdddEeeeFfffGgggHhhhIiii
, 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 ofTABLE
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
toUSAGE IS COMP
.我们这里没有足够的信息,但基本的是 DEPENDING ON 子句中命名的变量必须具有变量组数的计数。 所以你需要类似的东西
等等。
请参阅本文或这个文章在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
and so on.
See this article or this article at Publib.