英文:
Multiple functions in COBOL Linkage
问题
我是一名涉猎COBOL的C++/Python开发者,在Linux上使用open-cobol(cobc)。
我有几个相关的函数,我希望能够将它们保持在一起。通常,在COBOL中,每个链接部分只有一个函数。我目前的做法是:
调用"GEAR-FUNCS",使用DO-SOMETHING参数...
它根据DO-SOMETHING的值执行相关的函数。这减少了文件的数量,但意味着我每次都必须传递相同数量的参数,尽管其中一些参数是无关的。
最终目标是减少编译行上的文件数量。我不想最终只有一个大的主文件和许多小的链接文件需要每次引入。我想只有几个链接文件。目前,我知道的唯一方法要么是使用我的函数查找,要么是创建包含所有链接函数的库。
我想知道是否有更好的方法来做这件事。例如,是否有一种方法允许在单个源文件中使用多个链接部分或过程部分?
英文:
I'm a C++/Python developer dabbling in COBOL, using open-cobol (cobc) on Linux.
I have several related functions which I would like to keep together. Normally, in COBOL, there is only one function per linkage section. What I currently do is
CALL "GEAR-FUNCS" USING DO-SOMETHING PARAMS...
and it executes the relevant function depending on the value of DO-SOMETHING. This reduces the number of files but it means that I have to pass the same number of parameters every time, even though some of them are not relevant.
The ultimate aim is to reduce the number of files on the compile line. I don't want to end up with one big main file and lots of little linkage files which I have to pull in every time. I would like to have just a few linkage files. Currently, the only methods I know of are either my function lookup or to create a library which contains all the linkage functions.
I was wondering whether there is a better way of doing this. For instance, is there something that will allow multiple linkage sections or procedure divisions in a single source?
答案1
得分: 1
这不是一个答案 - 答案在《多个Cobol子程序可以在同一个模块中吗》。这只是一系列示例供参考。有两个函数定义 - LN-FUNC 和 LN-OBJ-FUNC。
- COBOL-85 多程序方法
IDENTIFICATION DIVISION.
PROGRAM-ID. LN-FUNC.
DATA DIVISION.
LINKAGE SECTION.
77 VAR1 PIC 9(2).
77 VAR2 PIC 9(2).
77 RESULT PIC ZZ9.
PROCEDURE DIVISION USING VAR1, VAR2, RESULT.
COMPUTE RESULT = VAR1 + VAR2.
* 这是返回语句
GOBACK.
END PROGRAM LN-FUNC.
********************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. LN-OBJ-FUNC.
DATA DIVISION.
LINKAGE SECTION.
01 VAR-OBJ.
02 OBJ-VAR1 PIC 9(2).
02 OBJ-VAR2 PIC 9(2).
77 RESULT PIC ZZ9.
PROCEDURE DIVISION USING VAR-OBJ, RESULT.
* 另一个函数入口点
COMPUTE RESULT = OBJ-VAR1 + OBJ-VAR2.
* 代替GOBACK。
EXIT PROGRAM.
END PROGRAM LN-OBJ-FUNC.
- 使用嵌套程序。这些需要嵌套如下
(AAA (BBB (CCC)))
而不是
(AAA (BBB) (CCC))
示例:
IDENTIFICATION DIVISION.
PROGRAM-ID. NESTED.
PROCEDURE DIVISION.
DISPLAY "SURPRISE - THIS GOT EXECUTED?".
********************************************
* 第一个嵌套链接
********************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. LN-FUNC.
DATA DIVISION.
LINKAGE SECTION.
77 VAR1 PIC 9(2).
77 VAR2 PIC 9(2).
77 RESULT PIC ZZ9.
PROCEDURE DIVISION USING VAR1, VAR2, RESULT.
COMPUTE RESULT = VAR1 + VAR2.
* 这是返回语句
GOBACK.
********************************************
* 第二个嵌套链接
********************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. LN-OBJ-FUNC.
DATA DIVISION.
LINKAGE SECTION.
01 VAR-OBJ.
02 OBJ-VAR1 PIC 9(2).
02 OBJ-VAR2 PIC 9(2).
77 RESULT PIC ZZ9.
PROCEDURE DIVISION USING VAR-OBJ, RESULT.
* 另一个函数入口点
COMPUTE RESULT = OBJ-VAR1 + OBJ-VAR2.
* 代替GOBACK。
EXIT PROGRAM.
END PROGRAM LN-OBJ-FUNC.
END PROGRAM LN-FUNC.
END PROGRAM NESTED.
- 使用ENTRY
IDENTIFICATION DIVISION.
PROGRAM-ID. USE-ENTRY.
DATA DIVISION.
LINKAGE SECTION.
* 对于LN-FUNC
77 VAR1 PIC 9(2).
77 VAR2 PIC 9(2).
77 RESULT PIC ZZ9.
* 对于LN-OBJ-FUNC
01 VAR-OBJ.
02 OBJ-VAR1 PIC 9(2).
02 OBJ-VAR2 PIC 9(2).
PROCEDURE DIVISION.
* 这从未被显示
DISPLAY "Starting multi".
* 这是一个函数入口点
ENTRY "LN-FUNC" USING VAR1, VAR2, RESULT.
COMPUTE RESULT = VAR1 + VAR2.
* 这是返回语句
GOBACK.
* 另一个函数入口点
ENTRY "LN-OBJ-FUNC" USING VAR-OBJ, RESULT.
COMPUTE RESULT = OBJ-VAR1 + OBJ-VAR2.
* 代替返回语句
EXIT PROGRAM.
END PROGRAM USE-ENTRY.
希望这有所帮助。
英文:
This is not an answer - the answer is in Can multiple Cobol subroutines be in the same modulehttps://stackoverflow.com/a/48949229/2041317. This is just a series of examples for reference. There are two functions defined - LN-FUNC and LN-OBJ-FUNC.
-
The COBOL-85 multiple program method
IDENTIFICATION DIVISION. PROGRAM-ID. LN-FUNC. DATA DIVISION. LINKAGE SECTION. 77 VAR1 PIC 9(2). 77 VAR2 PIC 9(2). 77 RESULT PIC ZZ9. PROCEDURE DIVISION USING VAR1, VAR2, RESULT. COMPUTE RESULT = VAR1 + VAR2. * This is the return statement GOBACK. END PROGRAM LN-FUNC. ******************************************** IDENTIFICATION DIVISION. PROGRAM-ID. LN-OBJ-FUNC. DATA DIVISION. LINKAGE SECTION. 01 VAR-OBJ. 02 OBJ-VAR1 PIC 9(2). 02 OBJ-VAR2 PIC 9(2). 77 RESULT PIC ZZ9. PROCEDURE DIVISION USING VAR-OBJ, RESULT. * Another function entry point COMPUTE RESULT = OBJ-VAR1 + OBJ-VAR2. * Alternative to GOBACK. EXIT PROGRAM. END PROGRAM LN-OBJ-FUNC.
-
Using nested programs. These need to be nested like
(AAA (BBB (CCC)))
not
(AAA (BBB) (CCC))
Example
IDENTIFICATION DIVISION.
PROGRAM-ID. NESTED.
PROCEDURE DIVISION.
DISPLAY "SURPRISE - THIS GOT EXECUTED?".
********************************************
* First nested linkage
********************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. LN-FUNC.
DATA DIVISION.
LINKAGE SECTION.
77 VAR1 PIC 9(2).
77 VAR2 PIC 9(2).
77 RESULT PIC ZZ9.
PROCEDURE DIVISION USING VAR1, VAR2, RESULT.
COMPUTE RESULT = VAR1 + VAR2.
* This is the return statement
GOBACK.
********************************************
* Second nested linkage
********************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. LN-OBJ-FUNC.
DATA DIVISION.
LINKAGE SECTION.
01 VAR-OBJ.
02 OBJ-VAR1 PIC 9(2).
02 OBJ-VAR2 PIC 9(2).
77 RESULT PIC ZZ9.
PROCEDURE DIVISION USING VAR-OBJ, RESULT.
* Another function entry point
COMPUTE RESULT = OBJ-VAR1 + OBJ-VAR2.
* Alternative to GOBACK.
EXIT PROGRAM.
END PROGRAM LN-OBJ-FUNC.
END PROGRAM LN-FUNC.
END PROGRAM NESTED.
-
Using entry
IDENTIFICATION DIVISION. PROGRAM-ID. USE-ENTRY. DATA DIVISION. LINKAGE SECTION. * For LN-FUNC 77 VAR1 PIC 9(2). 77 VAR2 PIC 9(2). 77 RESULT PIC ZZ9. * For LN-OBJ-FUNC 01 VAR-OBJ. 02 OBJ-VAR1 PIC 9(2). 02 OBJ-VAR2 PIC 9(2). PROCEDURE DIVISION. * This never gets displayed DISPLAY "Starting multi". * This is a function entry point ENTRY "LN-FUNC" USING VAR1, VAR2, RESULT. COMPUTE RESULT = VAR1 + VAR2. * This is the return statement GOBACK. * Another function entry point ENTRY "LN-OBJ-FUNC" USING VAR-OBJ, RESULT. COMPUTE RESULT = OBJ-VAR1 + OBJ-VAR2. * Alternative return statement EXIT PROGRAM. END PROGRAM USE-ENTRY.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论