Monday, 18 August 2014

USE OF CLEAR , REFRESH, FREE IN SAP ABAP

In this SAP ABAP tutorial I will show you the use of clear, refresh and free .

Clear:
Syntax : clear <variable_name>.
Use : clear the contents of the variable.
Variables may be internal table , work area , variables declared using
 elementary data types etc. 
E.g.:
Program 1.
DATA lv_num TYPE i VALUE 1000.
WRITE 'Value before clear : 'lv_num.
CLEAR lv_num.
WRITE 'Value after clear : ',lv_num.
Output:
SAP ABAP
SAP ABAP
 
 
 
 
 
 
Program 2.
TYPES BEGIN OF ty_mara,
          matnr 
TYPE matnr," Material Number
          mtart 
TYPE mtart," Material Type
          matkl 
TYPE matkl," Material Group
        
END OF   ty_mara.
DATA lt_mara TYPE STANDARD TABLE OF ty_mara INITIAL SIZE 1" Internal table declaration

DATA lt_mara_header TYPE STANDARD TABLE OF ty_mara WITH HEADER LINE" Internal table with header line
DATA ls_mara TYPE ty_mara." Work area declaration
CLEAR ls_mara lt_mara[]lt_mara, lt_mara_header[] lt_mara_header.

REFRESH :
It is used to clear the contents of only internal table. It will only clear the body of the internal table.
TYPES BEGIN OF ty_mara,
          matnr 
TYPE matnr," Material Number
          mtart 
TYPE mtart," Material Type
          matkl 
TYPE matkl," Material Group
        
END OF   ty_mara.
*-- Internal table declaration
DATA lt_mara TYPE STANDARD TABLE OF ty_mara INITIAL SIZE 1.
*-- Internal table with header line
DATA lt_mara_header TYPE STANDARD TABLE OF ty_mara WITH HEADER LINE
*--  Work area declaration
DATA ls_mara TYPE ty_mara.
*-- Use of refresh
REFRESH lt_mara[]lt_mara lt_mara_header[] .

N.B.: Both clear and refresh are used to clear the contents but they
 never release the memory space.

FREE :
It is used to clear the contents and release the memory of internal table only.
E.g.:
TYPES BEGIN OF ty_mara,
          matnr 
TYPE matnr," Material Number
          mtart 
TYPE mtart," Material Type
          matkl 
TYPE matkl," Material Group
        
END OF   ty_mara.
*-- Internal table declaration
DATA lt_mara TYPE STANDARD TABLE OF ty_mara INITIAL SIZE 1.
*-- Internal table with header line
DATA lt_mara_header TYPE STANDARD TABLE OF ty_mara WITH HEADER LINE.
*--  Work area declaration
DATA ls_mara TYPE ty_mara.
*-- Use of free
FREE lt_mara[]lt_mara_header[] .

No comments:

Post a Comment