Deleting Data Clusters from Memory 

To delete data objects from ABAP memory, use the following statement:

Syntax

FREE MEMORY [ID <key>].

If you omit the addition ID <key>, the system deletes the entire memory, that is, all of the data clusters previously stored in ABAP memory using EXPORT. If you use the addition ID <key>, this statement only deletes the data cluster with the name <key>.

Only use the FREE MEMORY statement with the ID addition, since deleting the entire memory can also delete the memory contents of system routines.

PROGRAM SAPMZTST.

DATA: TEXT(10) VALUE '0123456789',
      IDEN(3)  VALUE 'XYZ'.

EXPORT TEXT TO MEMORY ID IDEN.

TEXT = 'xxxxxxxxxx'.
IMPORT TEXT FROM MEMORY ID IDEN.
WRITE: / SY-SUBRC, TEXT.

FREE MEMORY.

TEXT = 'xxxxxxxxxx'.
IMPORT TEXT FROM MEMORY ID IDEN.
WRITE: / SY-SUBRC, TEXT.

This produces the following output:

0 0123456789
4 xxxxxxxxxx

The FREE MEMORY statement deletes the data cluster "XYZ". Consequently, SY-SUBRC is 4 after the following IMPORT statement, and the target field remains unchanged.