开发者

Group variable in cobol

 01  g1.
     05  h1           PIC X   VALUE 'N'.
         88 s1   开发者_Python百科                  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?


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜