CALL 语句中的 BY CONTENT 和 BY VALUE 有什么区别?

What is the difference between BY CONTENT and BY VALUE in a CALL statement?

COBOL 中 CALL 语句中的 BY CONTENTBY VALUE 有什么区别?

按内容传递参数与按引用传递参数相同,只是调用完成后数据不会复制回 COBOL 内存。这意味着原始变量不能被调用单元编辑。

因此 BY CONTENTBY VALUE 之间的区别在于,在 BY VALUE 的情况下,仅传递值,因此并非所有类型的变量都可以通过这种方式传递,而 BY CONTENT 复制变量的指针被传递,这样每一种类型的变量都可以被传递。

参见:http://documentation.microfocus.com/help/index.jsp?topic=%2Fcom.microfocus.eclipse.infocenter.visualcobol.eclipseux%2FGUID-EB09203C-3873-4DBE-9298-0C353BC0701A.html

By Reference:

When a parameter is passed by reference, a copy of the item in the JVM COBOL is passed to the native code. When the call to the native has finished, any changes to the information made in the native code are copied back to the JVM COBOL. However, this does mean that memory is shared between the JVM and native environments. In fact, what is actually passed to the native code is a pointer to the copied data. This is useful if you are calling non-COBOL programs. The implications of this are very important, particularly in multi-threaded environments. Any changes to reference parameters are not visible to the JVM COBOL calling program until the call has completed. Arbitrarily complex group items (within the memory limitations) can be passed by reference. The group definition must be identical in the native and JVM COBOL source code and it must not contain USAGE POINTER items. Strings (java.lang.Strings) and tables (java.lang.byte arrays) can be passed by reference. All other objects (types that inherit from java.lang.Object, including valuetypes) cannot be passed by reference (or by value - see below).

By Content

Passing parameters by content is the same as passing by reference, except that the data is not copied back into the JVM COBOL memory when the call has completed. Any item that can be passed by reference can be passed by content.

By Value

In JVM COBOL, the only items that can be passed by value are as follows: binary-long - the recommended type for passing by value pic x(4) comp-x pic (9)9 comp pic s(9)9 comp pic (9)9 comp-5 pic s(9)9 comp-5

BY CONTENT CALL 会将标识符的内容复制到编译器管理的存储区域,然后隐式传递给 CALLed 程序 "by reference"。

这意味着 CALLed 程序可以更改数据,但 CALLed 程序中所做的更改不会影响 CALLing 程序中的原始数据。

任何对编译器有效的标识符,任何大小,都可以按内容使用(受限于任何限制,如果存在的话,这些限制是为特定编译器记录的——你永远不知道)。

尽管您可以 更改 CALLed 程序中的值,但充其量这样做似乎有点晦涩难懂。

BY VALUE 是一个完全不同的野兽。它非常有限,因为值 "passed" 可以是 "integer" 或单字节字母数字值。也可以是文字。

PROCEDURE DIVISION USING ... 必须知道,在 BY VALUE 的情况下,就是这样,通过以与 CALL 等效的方式指定它。 CALL 上的 BY REFERENCE 和 BY CONTENT 都是 PROCEDURE DIVISION USING 上的 BY REFERENCE。

如何实现取决于特定的编译器。 IBM Enterprise COBOL 将值本身放在 "parameter list".