在其他语言中等效的Cobol 88型是什么? [英] What is a Cobol 88-type equivalent in another languages?

查看:96
本文介绍了在其他语言中等效的Cobol 88型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在学习COBOL,并且真的很喜欢88类型的变量,我想知道在另一种语言(最知名的语言,例如C,Objective-C)中是否有类似的东西,即使使用



我唯一能想到的就是使用

  #define booleanResult(variableName == 95)

但无法设置<$将c $ c> boolenResult 设置为 true ,并使 variableName 假定值为95。

解决方案

  05漂亮数据PICX。
88 a-meangingful-条件值 A。
88另一个有意义的条件
值 A B
X通过 Z
空间零。

如果一个有意义的条件
如果另一个有意义的条件
设置一个有意义的条件为真
设置另一个有意义的条件
要实现

IF测试数据名称(条件变量)所引用的值,即88(条件名称)与单个值或多个值之一相关联,其中可以包括范围(THRU)和图形常量(零,空格,低值等)。



SET(以这种形式,是1985年标准对COBOL的更新),将把数据名的值更改为在88 ,这样,如果您立即在测试中引用了88,则该测试为真。



在解决某些问题的意义上,COBOL没有布尔值



任何支持对象的语言都可以用来模仿行为。也许您甚至还没有真正意识到它就已经做到了。



正如NealB在评论中指出的那样,可以使用函数(或过程,或将控制权转移到另一个模块),但不会使用数据及其引用



COBOL在定义数据结构方面具有很大的灵活性。 88级语言是维护和理解程序以及首先编写程序的有力帮助。



我不知道另一种语言具有直接和自然的元素等效于此,但随后有很多我不知道的语言。



再次提到NealB在有关使用的评论中要指出重要的一点可以通过THRU / THROUGH来指定值的范围。



确实需要注意。尽管作者可能认为他们想要选择的数据可以由范围 010至 090来表示,但他们可能没有意识到编译器所做的就是包含每个可能的值在此范围内,通过生成大于或等于 010且小于或等于 090的代码。



如果使用THRU,请确保您的数据不能包含不期望的范围内的任何内容。如果您的意思是 010, 020, 030 ... 090,那很好,只要在入口点对数据进行了验证即可,因此它永远不会包含任何中间值。



经典示例是大型机上的 A直通 Z。我们都知道作者的意思,但是编译器从字面上理解它。您不能单独使用 A直通 Z进行验证,因为在EBCDIC中,三组字母之间存在空白,而使用 A直通 Z将处理这些间隙



在某些COBOL编译器中88级别确实下降的地方是缺少的 FALSE。



要重新使用上面的示例:

  88 a-meaingingful-condition VALUE一种。 
88 a-有意义的条件-不
值 N。

要测试开关/标志,请使用前88个。要关闭flag.switch,您必须使用第二个。不理想。参见下面的链接之一,了解有关88定义的FALSE的示例。



在过去,标记/开关是通过MOVE语句设置和重置的。一旦涉及到MOVE,就会遇到与尝试使用函数相同的问题。 MOVE和88级的VALUE之间没有绑定关系。



这些天来,SET可用于更改字段的值,转为标记/

  05 FILLER PICX。
88个有意义的条件
值一种。
88 a-有意义的条件-不
值 N。

要测试的字段甚至不需要名称(可以是FILLER或省略(隐含的FILLER ))。



当然,正如NealB在对以下链接之一的评论中所指出的那样,仍然可以通过在MOVE上使用reference-modification来获得该字段。组项目。所以...

  01 FILLER。 
05 FILLER PICX。
88 a有意义条件
值 A。
88 a-有意义的条件-不
值 N。

现在,他们甚至无法使用引用修改,因为没有可命名的字段。该字段的值只能来自定义中的VALUE子句,或来自将88s之一设置为TRUE的SET语句。



在该阶段,该值

  01 FILLER与标记/开关的实际值无关。

  01 FILLER。 
05 FILLER PIC X(7)。
88个有意义的条件
值苹果。
88个有意义的条件-否
值自行车。

因为不能使用任何东西来测试文字/数据名称,并且该字段不能是除了SET以外的任何动词的目标,您不再需要检查所有说它们包含N或Y或0或1的字段,都这样做,并且它们不是错误的大小写,并且不会放置其他任何值这些字段。



我不建议使用APPLE和BICYCLE,只是为了说明这一点。



88也可以具有以十六进制表示的值,就像任何字母数字字段一样:

  88 a-有意义-条件VALUE X 25。 

也可以在组项目上指定88,通常以比喻常数作为值:

  01 a-group-item。 
88不再需要匹配的数据VALUE高价值。
05主键PIC X(10)。
05小键PIC X(5)。

在文件匹配过程中,可以在密钥结尾处将键设置为高值。文件,并且使用密钥仍然会导致其他文件得到正确处理(密钥低于此文件)。



以下是指向SO中直接或与重要方面相关的问题数量,涉及88个级别。



COBOL 88级数据类型



cobol中的组变量





是否在前缀 NO之前在COBOL变量中有特殊含义吗?



大写字母的COBOL数据验证?


I'm learning COBOL now and really liking the 88-type of variables, and I want to know if there are anything like them in another languages (most known languages also, such as C, Objective-C), even using a library.

The only thing I can think being similar is using

#define booleanResult (variableName==95) 

But it isn't possible to set boolenResult to true and make variableName assume 95 as value.

解决方案

05  nicely-named-data             PIC X.
    88  a-meangingful-condition   VALUE "A".
    88  another-meaingingful-condition 
                                  VALUE "A" "B" 
                                     "X" THRU "Z" 
                                      SPACE ZERO.

IF a-meaningful-condition
IF another-meaningful-condition
SET a-meaningful-condition TO TRUE
SET another-meaningful-condition 
                           TO TRUE

The IFs test the value referenced by the data-name (conditional variable) that the 88 (condition name) is associated with, for a single value or one of multiple value, which can included ranges (THRU) and figurative-constants (ZERO, SPACE, LOW-VALUES, etc).

The SET, which in this form is a more recent addition to COBOL from the 1985 Standard, will change the value of the data-name to the first value specified on the 88, such that if you immediately referenced the 88 in a test, the test would be true.

COBOL does not have booleans in the sense of something resolving to 0 or 1, or anything else, being false/true.

Any language which supports Objects could be used to mimic the behaviour. Perhaps you've even done it already without really realising it.

As NealB points out in the comments, functions could be used (or a procedure, or a transfer of control to another module) but the data and references to it would not be together and protected from accidental mischief.

COBOL has great flexibility in defining data-structures. The 88-level is a powerful aid to maintaining and understanding programs, as well as writing them in the first place.

I don't know of another language which has a direct and natural element which is equivalent to this, but then there are lots of languages I don't know.

Again NealB makes an important point in the comments about the use of THRU/THROUGH to specify a range of values.

Care does need to be taken. Although the author may think that the data that they want to select can be represented by the range "010" THRU "090", they may not realise that what the compiler does is to include every single possible value in that range, by generating code for greater than or equal to "010" and less than or equal to "090".

If using THRU, ensure that your data cannot contain anything in the range which is not expected. If you mean "010" "020" "030" ... "090" that is fine, as long as the data is validated at its entry-point, so that it can never include any intervening values.

The classic example is "A" THRU "Z" on the Mainframe. We all know what the author means, but the compiler takes it literally. You cannot use "A" THRU "Z" on its own for validation, because in EBCDIC there are "gaps" between three groups of letters, and using "A" THRU "Z" would treat those gaps as true for a use of the 88.

Where the 88 level in some COBOL compilers does fall down, is in the missing "FALSE".

To re-use from the above example:

    88  a-meaingingful-condition  VALUE "A".
    88  a-meaingingful-condition-NOT 
                                  VALUE "N".

To test the switch/flag, you use the first 88. To turn the flag.switch off, you have to use the second. Not ideal. See one of the links below for an example of FALSE on the 88 definition.

In olden times, flags/switches were set and reset with MOVE statements. As soon as the MOVE is involved, you have the same problem as you have in trying to use functions. There is no bound relationship between the MOVE and the 88-level VALUE.

These days, SET can be used to change the value of a field, to turn a flag/switch on or off.

    05  FILLER PIC X.
        88  a-meaingingful-condition 
                                  VALUE "A".
        88  a-meaingingful-condition-NOT 
                                  VALUE "N".

The field being tested does not even need a name (it can be FILLER or omitted (an implied FILLER)).

Of course, as NealB points out in a comment on one of the links below, someone can still get at the field with a MOVE using reference-modification on a group item. So...

01  FILLER.
    05  FILLER PIC X.
        88  a-meaingingful-condition 
                                  VALUE "A".
        88  a-meaingingful-condition-NOT 
                                  VALUE "N".

Now they can't use reference-modification even, as there is no field to name. The value of the field can only come from a VALUE clause on the definition, or from a SET statement setting one of the 88s to TRUE.

At the stage, the value that a flag/switch has, its actual value, becomes irrelevant.

01  FILLER.
    05  FILLER PIC X(7).
        88  a-meaingingful-condition 
                                  VALUE "APPLE".
        88  a-meaingingful-condition-NOT 
                                  VALUE "BICYCLE".

Because nothing can be used to test against a literal/data-name, and the field cannot be the target of any verb except SET, you no longer have to check that all fields which say they contain N, or Y, or 0, or 1, do so, and they're not the wrong case, and no other values get placed in those fields.

I'm not suggesting the use of APPLE and BICYCLE, just using them to illustrate the point.

An 88 can also have a value expressed in hexadecimal notation, like any alpha-numeric field:

    88  a-meaingingful-condition  VALUE X"25".

An 88 can also be specified on a group item, typically with a figurative-constant as the value:

01  a-group-item.
    88  no-more-data-for-matching VALUE HIGH-VALUES.
    05  major-key                 PIC X(10).
    05  minor-key                 PIC X(5).

In a file-matching process, the keys can be set to high-values at end-of-file, and the use of the keys will still cause the other file(s) to be processed correctly (keys lower than on this file).

Here are links to a number of questions from SO relating directly, or tangentially with important aspects, to 88-levels.

COBOL level 88 data type

Group variable in cobol

In Cobol, to test "null or empty" we use "NOT = SPACE [ AND/OR ] LOW-VALUE" ? Which is it?

Does a prefix of "NO" have any special meaning in a COBOL variable?

COBOL Data Validation for capital letter?

这篇关于在其他语言中等效的Cobol 88型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆