在 Cobol 中,要测试“null 或empty”我们使用“NOT = SPACE [ AND/OR ] LOW-VALUE” ?是哪一个?
我现在在大型机上工作, 在某些模块中,测试
不为空或为空
: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
酋长说得对。
COBOL应该读取自然语言之类的东西(事实证明这只是
另一个糟糕的笑话)。
让我们使用以下变量和值:
一个表达式,例如:
相当容易理解。一不等于二,所以我们会这样做
THEN
之后的内容。然而,要遵循却要困难得多。同样,一不等于二并且一也不等于
等于三,所以我们将执行“THEN”之后的任何操作。
COBOL 有一个简写结构,恕我直言,永远不应该使用它。它令人困惑
每个人(有时包括我)。简写表达式可以让您将上述内容简化为:
或者如果您愿意
喜欢应用德摩根规则:
我给你的建议是避免
不 在表达式中并且永远使用 COBOL 简写表达式。
您真正想要的是:
当“X”包含空格或低值(空值)时,上面的内容不会执行任何操作。它
与: 完全相同:
可以转换为:
最后...
我的建议是坚持简单以理解更长且直接的表达式
在 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:
An expression such as:
Is fairly straight forward to understand. One is not equal to two so we will do
whatever follows the
THEN
. However,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:
or if you would
like to apply De Morgans rule:
My advice to you is avoid
NOT
in exprssions and NEVER use COBOL short hand expressions.What you really want is:
The above does nothing when the 'X' contains either spaces or low-values (nulls). It
is exactly the same as:
Which can be transformed into:
And finally...
My advice is to stick to simple to understand longer and straight forward expressions
in COBOL, forget the short hand crap.
在 COBOL 中,不存在 Java null 这样的东西,而且它永远不会“空”。
例如,取一个字段,
该字段总会包含一些东西。
现在它包含十六进制零。 x'0000000000'
现在它包含所有二进制: x'FFFFFFFFFF'
现在每个字节都是一个空格。 x'4040404040'
一旦声明了一个字段,它就指向内存中的某个区域。该内存区域必须设置为某些内容,即使您从未修改它,它仍然会保留程序加载之前的垃圾。除非你初始化它。
In COBOL, there is no such thing as a Java null AND it is never "empty".
For example, take a field
The field will always contain something.
now it contains hexadimal zeros. x'0000000000'
Now it contains all binary ones: x'FFFFFFFFFF'
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.
值得注意的是,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.
我同意 NealB 的观点。保持简单,避免“捷径”,使其易于理解,而不必查阅手册来检查。
但是,为什么不在 X 上放一个 88,并保持它非常简单?:
注意,在大型机 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.
However, why not put an 88 on X, and keep it really simple?:
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?