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.
WRITE : / 'Value before clear : ', lv_num.
CLEAR lv_num.
WRITE : / 'Value after clear : ',lv_num.
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
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.
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[] .
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[] .
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[] .
Thanks a
lot again friends for reading this tutorial. If you find this is useful and
helpful to you, please consider it sharing to your friends using the social
buttons below.
Thank you and I invite everyone to connect with me on my
facebook page ABAP
TOPICS or follow me on goole plus. You can
subscribe also to keep updated with latest posts. Enjoy reading this blog .
Please
mail all your contributions to roushan.c.kumar@gmail.com . We request you to
mention your Name & Organization you are working for. Your posts will be
verified and posted in this site with your name.
This comment has been removed by the author.
ReplyDeleteI really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor led live training in SAP ABAP, kindly Contact GRONYSA
ReplyDeleteClick for SAP ABAP Course details SAP ABAP
GRONYSA Offer World Class Virtual Instructor led training on SAP ABAP. We have industry expert trainer. We provide Training Material and Software Support. GRONYSA has successfully conducted 10,000 + trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
For Demo Contact us.
Nitesh Kumar
GRONYSA
E-mail: nitesh.kumar@gronysa.com
Ph: +91-9632072659/ +1-2142700660
www.GRONYSA.com