FREEMAIN
FREEMAIN
The CICS FREEMAIN statement is used to release (free) dynamically allocated memory that was previously obtained. FREEMAIN releases the following storages -
- Main storage that was acquired by a GETMAIN command issued by the application program.
- Main storage that was acquired by a LOAD command for a program, map, or table that is defined with RELOAD=YES.
If the task that acquired the storage or loaded the program does not release it, CICS releases the storage at the end of task.
Syntax -
EXEC CICS FREEMAIN
DATA(data-area)
[DATAPOINTER(ptr-value)]
[RESP(response-field)]
[RESP2(response-field2)]
END-EXEC.
- DATA(data-area) - Specifies the data area of main storage to be released.
- DATAPOINTER(ptr-value) - Specifies the address of the main storage to be released, as a pointer reference.
- RESP(response-variable) - Optional. It captures the response code of the FREEMAIN operation and used to check if the command executed successfully or encountered an error.
- RESP2(response2-variable) - Optional. It captures the response2 code of the FREEMAIN operation when the error occured.
Short Examples -
Scenario - Allocating and Freeing Dynamic Storage
...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-STORAGE-LENGTH PIC S9(4) COMP VALUE 100.
01 WS-RESP PIC S9(4) COMP.
PROCEDURE DIVISION.
EXEC CICS GETMAIN
SET(WS-POINTER)
LENGTH(WS-STORAGE-LENGTH)
INITIMG(' ')
RESP(WS-RESP)
END-EXEC.
IF WS-RESP = DFHRESP(NORMAL) THEN
...
ELSE
...
END-IF.
...
...
EXEC CICS FREEMAIN
DATAPOINTER(WS-POINTER)
RESP(WS-RESP)
END-EXEC.
...
GETMAIN allocates 100 bytes of dynamic memory. The memory is used for processing. FREEMAIN is used to release the memory after use. The response code (RESP) is checked to confirm successful release.
Error Conditions -
Eror Condition | RESP | RESP2 | Reason |
---|---|---|---|
INVREQ | 16 | 1 | The storage specified by the DATA or DATAPOINTER parameter is not storage acquired by a GETMAIN command. |
16 | 2 | The storage area specified by the DATA or DATAPOINTER parameter is in key storage and the program issuing the FREEMAIN command is in user-key. |