目前 Allocation of Memory in Variable-Length Tables NealB提到LE例程在非CICS COBOL程序中分配/释放内存。
我非常想知道如何做到这一点:如何调用LE例程。 (我熟悉LINKAGE SECTION和SET ADDRESS。)
由于我目前无法访问IBM大型机 - 这意味着无法访问在线文档 - 因此一些代码段可以启发我。
答案 0 :(得分:2)
在LE环境中,您可以致电CEEGTST和CEEFRST获取并免费存储。
他们都将12字节的结果标记作为第一个参数 - 如果你传递null,LE会在失败时异常终止。
第二个参数是地址。
对于CEEGTST,您还传递第三个长度参数。
分配示例:
Call 'CEEGTST' using
omitted
address of some-linkage-item
length of some-linkage-item
End-Call
免费示例:
Call 'CEEFRST' using
omitted
address of some-linkage-item
End-Call
答案 1 :(得分:1)
几乎所有IBM产品和技术文档都可以在互联网上找到。 这可能是一件苦差事要梳理,但要看一看 Book Manger
要回答您的具体问题,请 Language Environment Programming Reference告诉你几乎所有的事情 需要了解LE。您可能想要展示的内存管理例程是:CEEGTST (分配内存)和CEEFRST(可用内存)。
以下内容有点长,但它是一个完整的IBM Enterprise COBOL程序,它做的很简单 使用LE的内存管理。
***************************************************
** **
** DEMONSTRATION FOR LINKED LIST HANDLING **
** **
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. LINKLST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RET-CDE PIC 9(3).
01 HEAD-OF-LIST POINTER.
LINKAGE SECTION.
01 LINK GLOBAL.
02 DATA-PART PIC 9(4).
02 NEXT-PTR POINTER.
PROCEDURE DIVISION.
CALL "BULDLST" USING HEAD-OF-LIST,
RET-CDE
IF RET-CDE = ZERO THEN
CALL "SHOWLST" USING HEAD-OF-LIST
CALL "FREELST" USING HEAD-OF-LIST
IF HEAD-OF-LIST = NULL THEN
DISPLAY "LIST HAS BEEN FREED."
END-IF
END-IF
GOBACK
.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID BULDLST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 I PIC 9(4).
LINKAGE SECTION.
01 HEAD-OF-LIST POINTER.
01 RET-CDE PIC 9(3).
PROCEDURE DIVISION USING HEAD-OF-LIST, RET-CDE.
MAINLINE SECTION.
CALL "MEMALOC" USING BY REFERENCE HEAD-OF-LIST,
BY CONTENT LENGTH OF LINK,
BY REFERENCE RET-CDE
IF RET-CDE = ZERO THEN
SET ADDRESS OF LINK TO HEAD-OF-LIST
PERFORM VARYING I FROM 1 BY 1
UNTIL I > 4
OR RET-CDE > ZERO
MOVE I TO DATA-PART OF LINK
CALL "MEMALOC" USING BY REFERENCE NEXT-PTR OF LINK,
BY CONTENT LENGTH OF LINK,
BY REFERENCE RET-CDE
IF RET-CDE = ZERO THEN
SET ADDRESS OF LINK TO NEXT-PTR OF LINK
END-IF
END-PERFORM
IF RET-CDE = ZERO THEN
MOVE I TO DATA-PART OF LINK
SET NEXT-PTR OF LINK TO NULL
END-IF
END-IF
GOBACK
.
END PROGRAM BULDLST.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID SHOWLST.
DATA DIVISION.
LINKAGE SECTION.
01 HEAD-OF-LIST POINTER.
PROCEDURE DIVISION USING HEAD-OF-LIST.
MAINLINE SECTION.
SET ADDRESS OF LINK TO HEAD-OF-LIST
PERFORM UNTIL ADDRESS OF LINK = NULL
DISPLAY DATA-PART
SET ADDRESS OF LINK TO NEXT-PTR OF LINK
END-PERFORM
GOBACK
.
END PROGRAM SHOWLST.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID FREELST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NXT-PTR POINTER.
01 RET-CDE PIC 9(3).
LINKAGE SECTION.
01 HEAD-OF-LIST POINTER.
PROCEDURE DIVISION USING HEAD-OF-LIST.
MAINLINE SECTION.
MOVE ZERO TO RET-CDE
PERFORM UNTIL HEAD-OF-LIST = NULL OR
RET-CDE NOT = ZERO
SET ADDRESS OF LINK TO HEAD-OF-LIST
SET NXT-PTR TO NEXT-PTR OF LINK
CALL "MEMFREE" USING HEAD-OF-LIST, RET-CDE
SET HEAD-OF-LIST TO NXT-PTR
END-PERFORM
GOBACK
.
END PROGRAM FREELST.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID MEMALOC COMMON PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 HEAPID PIC S9(9) BINARY.
01 FC.
02 CONDITION-TOKEN-VALUE.
COPY CEEIGZCT.
03 CASE-1-CONDITION-ID.
04 SEVERITY PIC S9(4) BINARY.
04 MSG-NO PIC S9(4) BINARY.
03 CASE-2-CONDITION-ID
REDEFINES CASE-1-CONDITION-ID.
04 CLASS-CODE PIC S9(4) BINARY.
04 CAUSE-CODE PIC S9(4) BINARY.
03 CASE-SEV-CTL PIC X.
03 FACILITY-ID PIC XXX.
02 I-S-INFO PIC S9(9) BINARY.
LINKAGE SECTION.
01 PTR-TO-MEM POINTER.
01 NBR-OF-BYTES PIC S9(9) BINARY.
01 RET-CDE PIC 9(3).
PROCEDURE DIVISION USING PTR-TO-MEM, NBR-OF-BYTES, RET-CDE.
MOVE 0 TO HEAPID
CALL "CEEGTST" USING HEAPID,
NBR-OF-BYTES,
PTR-TO-MEM,
FC
IF CEE000 OF FC THEN
MOVE ZERO TO RET-CDE
ELSE
DISPLAY "CEEGTST FAILED WITH: " MSG-NO OF FC
MOVE 1 TO RET-CDE
SET PTR-TO-MEM TO NULL
END-IF
GOBACK.
END PROGRAM MEMALOC.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID MEMFREE COMMON PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 HEAPID PIC S9(9) BINARY.
01 FC.
02 CONDITION-TOKEN-VALUE.
COPY CEEIGZCT.
03 CASE-1-CONDITION-ID.
04 SEVERITY PIC S9(4) BINARY.
04 MSG-NO PIC S9(4) BINARY.
03 CASE-2-CONDITION-ID
REDEFINES CASE-1-CONDITION-ID.
04 CLASS-CODE PIC S9(4) BINARY.
04 CAUSE-CODE PIC S9(4) BINARY.
03 CASE-SEV-CTL PIC X.
03 FACILITY-ID PIC XXX.
02 I-S-INFO PIC S9(9) BINARY.
LINKAGE SECTION.
01 PTR-TO-MEM POINTER.
01 RET-CDE PIC 9(3).
PROCEDURE DIVISION USING PTR-TO-MEM, RET-CDE.
MOVE 0 TO HEAPID
CALL "CEEFRST" USING PTR-TO-MEM,
FC
IF CEE000 OF FC THEN
MOVE ZERO TO RET-CDE
ELSE
DISPLAY "CEEFRST FAILED WITH: " MSG-NO OF FC
MOVE 1 TO RET-CDE
END-IF
GOBACK.
END PROGRAM MEMFREE.
END PROGRAM LINKLST.
***************************************************
该程序写道:
***************************************************
** **
** DEMONSTRATION FOR LINKED LIST HANDLING **
** **
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. LINKLST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RET-CDE PIC 9(3).
01 HEAD-OF-LIST POINTER.
LINKAGE SECTION.
01 LINK GLOBAL.
02 DATA-PART PIC 9(4).
02 NEXT-PTR POINTER.
PROCEDURE DIVISION.
CALL "BULDLST" USING HEAD-OF-LIST,
RET-CDE
IF RET-CDE = ZERO THEN
CALL "SHOWLST" USING HEAD-OF-LIST
CALL "FREELST" USING HEAD-OF-LIST
IF HEAD-OF-LIST = NULL THEN
DISPLAY "LIST HAS BEEN FREED."
END-IF
END-IF
GOBACK
.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID BULDLST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 I PIC 9(4).
LINKAGE SECTION.
01 HEAD-OF-LIST POINTER.
01 RET-CDE PIC 9(3).
PROCEDURE DIVISION USING HEAD-OF-LIST, RET-CDE.
MAINLINE SECTION.
CALL "MEMALOC" USING BY REFERENCE HEAD-OF-LIST,
BY CONTENT LENGTH OF LINK,
BY REFERENCE RET-CDE
IF RET-CDE = ZERO THEN
SET ADDRESS OF LINK TO HEAD-OF-LIST
PERFORM VARYING I FROM 1 BY 1
UNTIL I > 4
OR RET-CDE > ZERO
MOVE I TO DATA-PART OF LINK
CALL "MEMALOC" USING BY REFERENCE NEXT-PTR OF LINK,
BY CONTENT LENGTH OF LINK,
BY REFERENCE RET-CDE
IF RET-CDE = ZERO THEN
SET ADDRESS OF LINK TO NEXT-PTR OF LINK
END-IF
END-PERFORM
IF RET-CDE = ZERO THEN
MOVE I TO DATA-PART OF LINK
SET NEXT-PTR OF LINK TO NULL
END-IF
END-IF
GOBACK
.
END PROGRAM BULDLST.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID SHOWLST.
DATA DIVISION.
LINKAGE SECTION.
01 HEAD-OF-LIST POINTER.
PROCEDURE DIVISION USING HEAD-OF-LIST.
MAINLINE SECTION.
SET ADDRESS OF LINK TO HEAD-OF-LIST
PERFORM UNTIL ADDRESS OF LINK = NULL
DISPLAY DATA-PART
SET ADDRESS OF LINK TO NEXT-PTR OF LINK
END-PERFORM
GOBACK
.
END PROGRAM SHOWLST.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID FREELST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NXT-PTR POINTER.
01 RET-CDE PIC 9(3).
LINKAGE SECTION.
01 HEAD-OF-LIST POINTER.
PROCEDURE DIVISION USING HEAD-OF-LIST.
MAINLINE SECTION.
MOVE ZERO TO RET-CDE
PERFORM UNTIL HEAD-OF-LIST = NULL OR
RET-CDE NOT = ZERO
SET ADDRESS OF LINK TO HEAD-OF-LIST
SET NXT-PTR TO NEXT-PTR OF LINK
CALL "MEMFREE" USING HEAD-OF-LIST, RET-CDE
SET HEAD-OF-LIST TO NXT-PTR
END-PERFORM
GOBACK
.
END PROGRAM FREELST.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID MEMALOC COMMON PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 HEAPID PIC S9(9) BINARY.
01 FC.
02 CONDITION-TOKEN-VALUE.
COPY CEEIGZCT.
03 CASE-1-CONDITION-ID.
04 SEVERITY PIC S9(4) BINARY.
04 MSG-NO PIC S9(4) BINARY.
03 CASE-2-CONDITION-ID
REDEFINES CASE-1-CONDITION-ID.
04 CLASS-CODE PIC S9(4) BINARY.
04 CAUSE-CODE PIC S9(4) BINARY.
03 CASE-SEV-CTL PIC X.
03 FACILITY-ID PIC XXX.
02 I-S-INFO PIC S9(9) BINARY.
LINKAGE SECTION.
01 PTR-TO-MEM POINTER.
01 NBR-OF-BYTES PIC S9(9) BINARY.
01 RET-CDE PIC 9(3).
PROCEDURE DIVISION USING PTR-TO-MEM, NBR-OF-BYTES, RET-CDE.
MOVE 0 TO HEAPID
CALL "CEEGTST" USING HEAPID,
NBR-OF-BYTES,
PTR-TO-MEM,
FC
IF CEE000 OF FC THEN
MOVE ZERO TO RET-CDE
ELSE
DISPLAY "CEEGTST FAILED WITH: " MSG-NO OF FC
MOVE 1 TO RET-CDE
SET PTR-TO-MEM TO NULL
END-IF
GOBACK.
END PROGRAM MEMALOC.
***************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID MEMFREE COMMON PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 HEAPID PIC S9(9) BINARY.
01 FC.
02 CONDITION-TOKEN-VALUE.
COPY CEEIGZCT.
03 CASE-1-CONDITION-ID.
04 SEVERITY PIC S9(4) BINARY.
04 MSG-NO PIC S9(4) BINARY.
03 CASE-2-CONDITION-ID
REDEFINES CASE-1-CONDITION-ID.
04 CLASS-CODE PIC S9(4) BINARY.
04 CAUSE-CODE PIC S9(4) BINARY.
03 CASE-SEV-CTL PIC X.
03 FACILITY-ID PIC XXX.
02 I-S-INFO PIC S9(9) BINARY.
LINKAGE SECTION.
01 PTR-TO-MEM POINTER.
01 RET-CDE PIC 9(3).
PROCEDURE DIVISION USING PTR-TO-MEM, RET-CDE.
MOVE 0 TO HEAPID
CALL "CEEFRST" USING PTR-TO-MEM,
FC
IF CEE000 OF FC THEN
MOVE ZERO TO RET-CDE
ELSE
DISPLAY "CEEFRST FAILED WITH: " MSG-NO OF FC
MOVE 1 TO RET-CDE
END-IF
GOBACK.
END PROGRAM MEMFREE.
END PROGRAM LINKLST.
***************************************************
并不是非常令人兴奋,但确实展示了如何将一些事物串联在一起。