cobol 中的组变量

发布于 2024-11-27 20:27:25 字数 223 浏览 3 评论 0原文

 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 技术交流群。

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

发布评论

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

评论(2

梦太阳 2024-12-04 20:27:26

s1s2 不保存值。它们是“命名条件”(所谓的 88 级)并与另一个项目(条件变量)相关联。 88级别不定义字段,不占用记录空间;它只是一个价值定义。

命名条件可以在 IF 语句中使用,并测试条件变量是否等于命名条件的 VALUE 子句中给定的任何值。

SET 语句可用于使命名条件为 TRUE(通过将其第一个值分配给条件变量)。

用法:

SET s1 TO TRUE 

h1 将保存值'Y'

您可以使用 测试它的值

IF h1 = 'Y'< /code> 或简单地 IF s1

编辑:正如 Joe Zitzelberger 在他的回答中提到的,测试条件变量的正确方法是使用命名条件。

IF s1 THEN

   //do something
ELSE 

   //do somethingElse
END-IF

s1 and s2 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:

SET s1 TO TRUE 

h1 will hold the value 'Y'

You could test it's value with

IF h1 = 'Y' or simply IF s1

EDIT: As Joe Zitzelberger mentioned in his answer, the correct way to test the conditional variable is to use the named conditions.

IF s1 THEN

   //do something
ELSE 

   //do somethingElse
END-IF
禾厶谷欠 2024-12-04 20:27:25

S1和S1被命名为条件。它们的真假取决于 H1(或本例中的 G1)的值。

代码:

Set S1 to true

将导致 H1(如果是您的特定组,则为 G1)的值为“Y”。如果执行:

Set S2 to true

H1(以及 G1)的值将是字符“N”。

这些可以使用标准关系条件进行测试。例如:

Evaluate true
  when S1
    Display "S1 is true"
  when S2
    Display "S2 is true"
End-Evaluate

If S1
  Display "S1 is true"
Else
  Display "S1 is false"
End-If

Bruno 涵盖了 88 级或命名条件的大部分重要功能,但我认为有必要提及它们被 Cobol 程序严重滥用的方式,这些程序就是无法放弃 1974 年的技能。

您经常会看到人们做这样的事情:

Move 'Y' to H1

由于以下几个原因,这是一个非常糟糕的主意:
- 有一天,有人会“将‘x’移至 H1”并真正搞乱你的一天
- 有人会编写类似“if H1 = 'Y'”的代码,并使其无法扫描您的命名条件的使用

有一种方法可以避免这种情况,即在您的命名条件中使用未命名的字节。如果您的数据项如下所示:

01 G1
  02 ...
  02 Filler Pic X value 'N'.
    03 S1         value 'Y'.
    03 S2         value 'N'. 

通过跳过 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:

Set S1 to true

will cause the value of H1 (and G1 in the case of your specific group) to be 'Y'. If you execute:

Set S2 to true

the value of H1 (and G1 again) will be a character 'N'.

These can be tested using standard relational conditions. For example:

Evaluate true
  when S1
    Display "S1 is true"
  when S2
    Display "S2 is true"
End-Evaluate

If S1
  Display "S1 is true"
Else
  Display "S1 is false"
End-If

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:

Move 'Y' to H1

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:

01 G1
  02 ...
  02 Filler Pic X value 'N'.
    03 S1         value 'Y'.
    03 S2         value 'N'. 

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.

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