在 ILE cobol 程序中获取返回值

obtain returned value in ILE cobol program

我正在尝试从 cobol 程序中的 C 程序获取返回值。但是,他们提到了这一点:

returning phrase

“使用链接类型的程序调用的程序不允许使用 GIVING/RETURNING 短语。”

那么有什么选择呢?如何在cobol程序中获取返回值?找不到。 谢谢。 - 编辑 我找到了这个 https://www.ibm.com/docs/en/rdfi/9.6.0?topic=SSAE4W_9.6.0/com.ibm.etools.iseries.ilecbl.doc/LNC2762.htm 他们指示“更改被调用程序的链接”,但我不知道该怎么做。

简答
IBM i 上的 ILE 程序不支持 return 值。 您需要使用输出参数。

长答案
Retrieve Job Information (QUSRJOBI) API 的 JOBI0600 格式中,在偏移量 108 处有一个 4 字节整数字段“用户 Return 代码”。

不过
文档说:

The user return code field is the most recent return code set by any thread within the job. Many operating system functions run C code and change the value of the user return code. Changes to this field occur at times that cannot be predicted or controlled by user programming, even when the job is single-threaded. To receive a value returned by a called program, it is better to provide a parameter to receive that value than to rely on this job-scoped user return code field.

IBM 的 Barbara Morris,RPG 编译器开发团队成员,mentioned in an online thread

the operating system has to take the program off the call stack, and if it's a *NEW program, the OS has to reclaim the activation group. If part of that work involves a C or C++ program in the OS, it might change the ILE return code.

扩展答案 我怀疑您编辑中提到的“更改链接”是将 C 代码从 *PGM 对象移动到 *SRVPGM 对象(供 bind-by-reference 使用)或 *MODULE 对象(bind-by-copy)。

ILE 过程(又名函数)可以 return 值。

对于 ILE C/C++ 调用 C/C++ PGM
下面提到的是ILE C/C++ Programmer's Guide..

extern "OS" int PGMNAME(void); The value returned on the call is the return code for the dynamic program call. If the program being called is a C++ program, this return code can be accessed using the _LANGUAGE_RETURN_CODE macro defined in the header file <milib.h>. A C++ program returns four bytes in the _LANGUAGE_RETURN_CODE. If the program being called is an EPM or OPM program, this return code can be accessed using the iSeries Retrieve Job Attributes (RTVJOBA) command.

但我认为这对 COBOL 调用没有帮助 C/C++。