FREEMAIN
Release main storage that was acquired by using a GETMAIN request.
Description
- Main storage that was acquired by a GETMAIN command issued by the application.
- Main storage that was acquired by a LOAD command for a program, map, or table that is defined with RELOAD=YES.
- The GETMAIN command is specified the SHARED option. The storage remains allocated until another task issues a FREEMAIN or FREEMAIN64 request to release it.
- The program is defined with RELOAD=YES. The storage remains allocated until another task issues a FREEMAIN or FREEMAIN64 request to release it.
- The program is defined with RELOAD=NO but was loaded with the HOLD option. The program remains available until it is released by another task.
You can release CICS-key storage from a program only if it is being executed in CICS key. If the previously-acquired storage was obtained from CICS-key storage, and the program that issues the FREEMAIN request is in user-key, an INVREQ condition occurs with a RESP2 value of 2.
To release main storage that was acquired by using a GETMAIN64 request, use the FREEMAIN64 command. See FREEMAIN64.
Options
- DATA(data-area)
- Specifies
the data area of main storage to be released.
In assembler language, data-area must be a relocatable expression that is a data reference; in COBOL or C, it must be a data name; and in PL/I, it must be a data reference.
The length of storage released is the length that was obtained by the GETMAIN request and not necessarily the length of the data area.
- DATAPOINTER(ptr-value)
- Specifies
the address of the main storage to be released, as a pointer reference.
This option is an alternative to the DATA option, and specifies the
pointer reference that was returned by a GETMAIN command using the
SET option.
The length of storage released is the length obtained by the GETMAIN request.
Conditions
- 16 INVREQ
- RESP2
values:
- 1
- The storage specified by the DATA or DATAPOINTER parameter is not storage acquired by a GETMAIN command.
- 2
- The storage area specified by the DATA or DATAPOINTER parameter is in CICS-key storage, and the program issuing the FREEMAIN command is in user-key.
Default action: terminate the task abnormally.
Example: COBOL
DATA DIVISION.
WORKING-STORAGE SECTION.
77 AREA-POINTER USAGE IS POINTER.
LINKAGE SECTION.
01 WORKAREA PIC X(100).
PROCEDURE DIVISION.
EXEC CICS GETMAIN SET(AREA-POINTER)
LENGTH(100)
END-EXEC.
.
SET ADDRESS OF WORKAREA TO AREA-POINTER.
.
.
EXEC CICS FREEMAIN DATA(WORKAREA)
END-EXEC.
EXEC CICS RETURN
END-EXEC.
EXEC CICS FREEMAIN DATAPOINTER(AREA-POINTER)
END-EXEC.
Example: C
#pragma XOPTS(CICS);
#define MAINSIZE 100;
main()
{
char *buffer;
struct eib_record dfheiptr;
EXEC CICS ADDRESS EIB(dfheiptr);
EXEC CICS GETMAIN SET(buffer)
LENGTH(MAINSIZE);
buffer[2] = 'a';
.
.
EXEC CICS FREEMAIN DATA(buffer);
EXEC CICS RETURN;
}
Example: PL/I
DCL AREA_PTR POINTER,
WORKAREA CHAR(100) BASED(AREA_PTR);
.
.
.
EXEC CICS GETMAIN SET(AREA_PTR) LENGTH(100);
.
EXEC CICS FREEMAIN DATA(WORKAREA);
Example: Assembler
WORKAREA DS CL100
.
.
EXEC CICS GETMAIN SET(9) LENGTH(100)
USING WORKAREA,9
EXEC CICS FREEMAIN DATA(WORKAREA)
WORKAREA DS CL100
.
EXEC CICS GETMAIN SET(9) LENGTH(100)
USING WORKAREA,9
.
.
DROP 9
.
EXEC CICS FREEMAIN DATAPOINTER(9)