cobol 中的组变量
01 g1.
05 h1 PIC X VALUE 'N'.
88 s1 VALUE 'Y'.
88 s2 VALUE 'N'.
在上面的代码中,s1 和 s2 的值是多少?它是否保存组变量(05)中给定的值,还是有自己的值?
01 g1.
05 h1 PIC X VALUE 'N'.
88 s1 VALUE 'Y'.
88 s2 VALUE 'N'.
In the above code what will be the value of s1 and s2? whether it holds the value given in the group variable(05) or it will have their own values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
s1
和s2
不保存值。它们是“命名条件”(所谓的 88 级)并与另一个项目(条件变量)相关联。 88级别不定义字段,不占用记录空间;它只是一个价值定义。命名条件可以在 IF 语句中使用,并测试条件变量是否等于命名条件的 VALUE 子句中给定的任何值。
SET 语句可用于使命名条件为 TRUE(通过将其第一个值分配给条件变量)。
用法:
h1
将保存值'Y'
您可以使用测试它的值IF h1 = 'Y'< /code> 或简单地
IF s1
编辑:正如 Joe Zitzelberger 在他的回答中提到的,测试条件变量的正确方法是使用命名条件。
s1
ands2
don't hold a value. They are "named conditions" ( so-called 88-levels ) and are associated with another item ( the conditional variable ). The 88 level does not define a field, and does not take space in the record; it is merely a value definition.The named condition can be used in an IF statement, and tests whether the conditional variable is equal to any of the values given in the named condition's VALUE clause.
The SET statement can be used to make a named condition TRUE (by assigning the first of its values to the conditional variable).
Usage:
h1
will hold the value'Y'
You could test it's value withIF h1 = 'Y'
or simplyIF s1
EDIT: As Joe Zitzelberger mentioned in his answer, the correct way to test the conditional variable is to use the named conditions.
S1和S1被命名为条件。它们的真假取决于 H1(或本例中的 G1)的值。
代码:
将导致 H1(如果是您的特定组,则为 G1)的值为“Y”。如果执行:
H1(以及 G1)的值将是字符“N”。
这些可以使用标准关系条件进行测试。例如:
Bruno 涵盖了 88 级或命名条件的大部分重要功能,但我认为有必要提及它们被 Cobol 程序严重滥用的方式,这些程序就是无法放弃 1974 年的技能。
您经常会看到人们做这样的事情:
由于以下几个原因,这是一个非常糟糕的主意:
- 有一天,有人会“将‘x’移至 H1”并真正搞乱你的一天
- 有人会编写类似“if H1 = 'Y'”的代码,并使其无法扫描您的命名条件的使用
有一种方法可以避免这种情况,即在您的命名条件中使用未命名的字节。如果您的数据项如下所示:
通过跳过 H1 上的名称,您将强制使用您的数据布局的其他程序员使用您的命名条件 S1 和 S2。这有很多好处,其中最主要的是您可以随时扫描源存储库中的指定条件,并且可以轻松识别所有更改。
S1 and S1 are named conditions. They will be true or not true depending upon the value of H1 (or G1 in this case).
The code:
will cause the value of H1 (and G1 in the case of your specific group) to be 'Y'. If you execute:
the value of H1 (and G1 again) will be a character 'N'.
These can be tested using standard relational conditions. For example:
Bruno covered most of the important features of 88-levels, or named conditions, but I feel it is important to mention the way they are badly abused by Cobol programs that just can't give up their 1974 skills.
You will often see people doing things like:
This is a really bad idea for several reasons:
- someday, somebody is going to "move 'x' to H1" and really mess up your day
- somebody is going to write code like "if H1 = 'Y'" and make it impossible to scan for uses of your named condition
There is a way to avoid this, use an unnamed byte with your named conditions. If your data item looks like this:
By skipping the name on H1, you FORCE other programmers working with your data layout to use your named conditions S1 and S2. This has many benefits, chief among them is that you can always scan your source repository for the named conditions and you can identify all changes easily.