在 Cobol 中,要测试“null 或empty”我们使用“NOT = SPACE [ AND/OR ] LOW-VALUE” ?是哪一个?

发布于 2024-10-01 06:23:40 字数 171 浏览 1 评论 0原文

我现在在大型机上工作, 在某些模块中,测试

不为空或为空

NOT = 空格或低值 领导说我们应该这样做: NOT = 空格和低值

是哪一个?

谢谢!

I am now working in mainframe,
in some modules, to test

Not null or Empty

we see :
NOT = SPACE OR LOW-VALUE
The chief says that we should do :
NOT = SPACE AND LOW-VALUE

Which one is it ?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

葬シ愛 2024-10-08 06:23:40

酋长说得对。

COBOL应该读取自然语言之类的东西(事实证明这只是
另一个糟糕的笑话)。

让我们使用以下变量和值:

 A = 1
 B = 2
 C = 3

一个表达式,例如:

IF A NOT EQUAL B THEN...

相当容易理解。一不等于二,所以我们会这样做
THEN 之后的内容。然而,

IF A NOT EQUAL B AND A NOT EQUAL C THEN...

要遵循却要困难得多。同样,一不等于二并且一也不等于
等于三,所以我们将执行“THEN”之后的任何操作。

COBOL 有一个简写结构,恕我直言,永远不应该使用它。它令人困惑
每个人(有时包括我)。简写表达式可以让您将上述内容简化为:

IF A NOT EQUAL B AND C THEN...

或者如果您愿意
喜欢应用德摩根规则:

IF NOT (A EQUAL B OR C) THEN...  

我给你的建议是避免不 在表达式中并且永远使用 COBOL 简写表达式。

您真正想要的是:

 IF X = SPACE OR X = LOW-VALUE THEN...
    CONTINUE
 ELSE
    do whatever...
 END-IF

当“X”包含空格或低值(空值)时,上面的内容不会执行任何操作。它
与: 完全相同:

 IF NOT (X = SPACE OR X = LOW-VALUE) THEN
    do whatever...
 END-IF

可以​​转换为:

 IF X NOT = SPACE AND X NOT = LOW-VALUE THEN...

最后...

 IF X NOT = SPACE AND LOW-VALUE THEN...

我的建议是坚持简单以理解更长且直接的表达式
在 COBOL 中,忘掉那些简短的废话吧。

Chief is correct.

COBOL is supposed to read something like natural language (this turns out to be just
another bad joke).

Lets play with the following variables and values:

 A = 1
 B = 2
 C = 3

An expression such as:

IF A NOT EQUAL B THEN...

Is fairly straight forward to understand. One is not equal to two so we will do
whatever follows the THEN. However,

IF A NOT EQUAL B AND A NOT EQUAL C THEN...

Is a whole lot harder to follow. Again one is not equal to two AND one is not
equal to three so we will do whatever follows the 'THEN'.

COBOL has a short hand construct that IMHO should never be used. It confuses just about
everyone (including me from time to time). Short hand expressions let you reduce the above to:

IF A NOT EQUAL B AND C THEN...

or if you would
like to apply De Morgans rule:

IF NOT (A EQUAL B OR C) THEN...  

My advice to you is avoid NOT in exprssions and NEVER use COBOL short hand expressions.

What you really want is:

 IF X = SPACE OR X = LOW-VALUE THEN...
    CONTINUE
 ELSE
    do whatever...
 END-IF

The above does nothing when the 'X' contains either spaces or low-values (nulls). It
is exactly the same as:

 IF NOT (X = SPACE OR X = LOW-VALUE) THEN
    do whatever...
 END-IF

Which can be transformed into:

 IF X NOT = SPACE AND X NOT = LOW-VALUE THEN...

And finally...

 IF X NOT = SPACE AND LOW-VALUE THEN...

My advice is to stick to simple to understand longer and straight forward expressions
in COBOL, forget the short hand crap.

爱,才寂寞 2024-10-08 06:23:40

在 COBOL 中,不存在 Java null 这样的东西,而且它永远不会“空”。

例如,取一个字段,

 05  FIELD-1  PIC X(5).

该字段总会包含一些东西。

MOVE LOW-VALUES TO FIELD-1.

现在它包含十六进制零。 x'0000000000'

MOVE HIGH-VALUES TO FIELD-1.

现在它包含所有二进制: x'FFFFFFFFFF'

MOVE SPACES TO FIELD-1.

现在每个字节都是一个空格。 x'4040404040'

一旦声明了一个字段,它就指向内存中的某个区域。该内存区域必须设置为某些内容,即使您从未修改它,它仍然会保留程序加载之前的垃圾。除非你初始化它。

05  FIELD-1 PIC X(6) VALUE 'BARUCH'.

In COBOL, there is no such thing as a Java null AND it is never "empty".

For example, take a field

 05  FIELD-1  PIC X(5).

The field will always contain something.

MOVE LOW-VALUES TO FIELD-1.

now it contains hexadimal zeros. x'0000000000'

MOVE HIGH-VALUES TO FIELD-1.

Now it contains all binary ones: x'FFFFFFFFFF'

MOVE SPACES TO FIELD-1.

Now each byte is a space. x'4040404040'

Once you declare a field, it points to a certain area in memory. That memory area must be set to something, even if you never modify it, it still will have what ever garbage it had before the program was loaded. Unless you initialize it.

05  FIELD-1 PIC X(6) VALUE 'BARUCH'.
明明#如月 2024-10-08 06:23:40

值得注意的是,null 值并不总是与 low-value 相同,这取决于制造商确定的设备架构及其使用的字符集。与使用 Linux 或 Windows 的设备相比,大型机可以具有完全不同的整理顺序(从低到高的字符代码和符号顺序)和符号集,正如您现在毫无疑问所看到的那样。 Cobol 中用于比较的简写有时用于布尔运算,例如 IF A GOTO PAR-5 和 IF A OR C THEN ....,并且可以与两个变量或变量和文字值的比较结合使用。不同设备上的解析器和编译器应该以标准 (ANSI) 方法处理这些情况,但情况并非总是如此。

It is worth noting that the value null is not always the same as low-value and this depends on the device architecture and its character set in use as determined by the manufacturer. Mainframes can have an entirely different collating sequence (low to high character code and symbol order) and symbol set compared to a device using linux or windows as you have no doubt seen by now. The shorthand used in Cobol for comparisons is sometimes used for boolean operations, like IF A GOTO PAR-5 and IF A OR C THEN .... and can be combined with comparisons of two variables or a variable and a literal value. The parser and compiler on different devices should deal with these situations in a standard (ANSI) method but this is not always the situation.

攒眉千度 2024-10-08 06:23:40

我同意 NealB 的观点。保持简单,避免“捷径”,使其易于理解,而不必查阅手册来检查。

IF ( X EQUAL TO SPACE ) 
OR ( X EQUAL TO LOW-VALUES )
   CONTINUE
ELSE
   do whatever...
END-IF

但是,为什么不在 X 上放一个 88,并保持它非常简单?:

88  X-HAS-A-VALUE-INDICATING-NULL-OR-EMPTY VALUE SPACE, LOW-VALUES.

IF X-HAS-A-VALUE-INDICATING-NULL-OR-EMPTY
    CONTINUE
ELSE
   do whatever...
END-IF

注意,在大型机 Cobol 中,NULL 的含义非常有限,并且不是您赋予它的含义,Tom。 “空”仅意味着特定编码器生成的上下文中的某些内容(就字段而言,对于 Cobol 来说没有任何意义)。

我们没有“绳子”。因此,我们没有“空字符串”(长度为 1 的字符串,包括字符串终止符)。我们没有字符串,因此字段总是有一个值,因此它永远不会是“空”,除非程序员所说的那样。

Oguz,我认为你的文章说明了一些非常简单的东西可以变得多么复杂,以及如何导致错误。请问你能测试一下你的条件吗?

I agree with NealB. Keep it simple, avoid "short cuts", make it easy to understand without having to refer to the manual to check things out.

IF ( X EQUAL TO SPACE ) 
OR ( X EQUAL TO LOW-VALUES )
   CONTINUE
ELSE
   do whatever...
END-IF

However, why not put an 88 on X, and keep it really simple?:

88  X-HAS-A-VALUE-INDICATING-NULL-OR-EMPTY VALUE SPACE, LOW-VALUES.

IF X-HAS-A-VALUE-INDICATING-NULL-OR-EMPTY
    CONTINUE
ELSE
   do whatever...
END-IF

Note, in Mainframe Cobol, NULL is very restricted in meaning, and is not the meaning that you are attributing to it, Tom. "Empty" only means something in a particular coder-generated context (it means nothing to Cobol as far as a field is concerned).

We don't have "strings". Therefore, we don't have "null strings" (a string of length one including string-terminator). We don't have strings, so a field always has a value, so it can never be "empty" other than as termed by the programmer.

Oguz, I think your post illustrates how complex something that is really simple can be made, and how that can lead to errors. Can you test your conditions, please?

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