This discussion is locked
10 Replies Latest reply: May 23, 2006 2:15 PM by Ganesh Mynampati RSS

diff refresh Vs clear of internal table

BWer BWer
Currently Being Moderated

Hello ABAP Experts,

 

What is the difference between refresh and clear of internal table.

 

Suggestions appreciated.

Thanks,

BWer

  • Re: diff refresh Vs clear of internal table
    Suresh Datti
    Currently Being Moderated

    REFRESH ITAB will delete the contents in the itab whereas CLEAR ITAB will only delete the header. You can simply use CLEAR:ITAB[],ITAB. to clear both the header & table contents in one go.

     

    Regards,

     

    Suresh Datti

  • Re: diff refresh Vs clear of internal table
    Venkatalaxmi Vadlamani
    Currently Being Moderated

    Hi

     

    CLEAR <itab>.

     

    statement. This statement restores an internal table to the state it was in immediately after you declared it. This means that the table contains no lines. However, the memory already occupied by the memory up until you cleared it remains allocated to the table.

     

    If you are using internal tables with header lines, remember that the header line and the body of the table have the same name. If you want to address the body of the table in a comparison, you must place two brackets ([ ]) after the table name.

     

    CLEAR <itab>[].

     

    To ensure that the table itself has been initialized, you can use the

     

    REFRESH <itab>.

     

    statement. This always applies to the body of the table. As with the CLEAR statement, the memory used by the table before you initialized it remains allocated. To release the memory space, use the statement

     

    Regards

     

    Laxmi

  • Re: diff refresh Vs clear of internal table
    Shail India
    Currently Being Moderated

    Hi ,

     

    REFRESH and CLEAR are the various methods for initializing Internal Tables.

     

    examples:

     

    CLEAR <itab>.

    If <itab> is not having header line, this will clear the entire contents.

     

    CLEAR <itab>.

    If <itab> is having header line, this statement will just clear the contents of header line.

     

    CLEAR <itab>[]

    If <itab> has header line, this will clear the body contents ( excluding header line)

     

    REFRESH <itab>.

    This statement will cause the body content to be cleared. But memory allotted to the table will remain as it is.. Then u have to use

    FREE<itab> to free the memory.

     

    Just check this link...

     

    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb384e358411d1829f0000e829fbfe/content.htm

     

    Regards,

    SP.

  • Re: diff refresh Vs clear of internal table
    Ravi Kanth Talagana
    Currently Being Moderated

    clear itab[]. = refresh itab.

    Regards,

    Ravi

  • Re: diff refresh Vs clear of internal table
    Jaya Mohan
    Currently Being Moderated

    HI,

      Replace always clears the body of itab,clear clears the header line when that internal table is declared with header line,if not means that internal table is not defined with header line then it clears body.If you want to clear body then you need to code it like CLEAR ITAB[].

     

     

    Cheers,

    Bujji

  • Re: diff refresh Vs clear of internal table
    Priya J
    Currently Being Moderated

    hi bwer,

     

    refresh itab: The internal table itab is reset to its initial state, i.e. all table entries are deleted.

     

    clear itab: only clears the contents of the internal table.The header entry of a table with a header line remains unchanged. It can be reset to its initial value

     

    hope this helps,

    priya.

  • Re: diff refresh Vs clear of internal table
    Naresh Kumar Amaragani
    Currently Being Moderated

    Hii

     

    clear itab - clears only header line

    refresh itab- clears body of the internal table

    Free itab - clears a internal table from memory

     

    it deletes the internal table from the memory itself

     

    CLEAR ITAB[] does the same thing as REFRESH ITAB.

     

    You can use FREE to initialize an internal table and release its memory space without first using the REFRESH or CLEAR statement.

    Like REFRESH, FREE works on the table body, not on the table work area.

    After a FREE statement, you can address the internal table again. It still occupies the amount of memory required for its header (currently 256 bytes). When you refill the table, the system has to allocate new memory space to the lines.

     

    it is better practice to use the FREE ITAB command whenever possible as it will maximise system resources.

     

    If you free the memory allocated to this internal table, the memory could be allocated to another program or another data object in the same program.

     

    chk this link

     

    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb384e358411d1829f0000e829fbfe/content.htm

     

    also refer to this link for more information..

     

    <b>Re: Difference

     

     

     

    Regards

    Naresh

  • Re: diff refresh Vs clear of internal table
    keerthi kiran varanasi
    Currently Being Moderated

    hi,

    clear itab. clears the header of internal table

    refresh itab clears the body of itab

    clear itab[] clears both the body and header.

     

    Award points if helpful.

    regards,

    keerthi.

  • Re: diff refresh Vs clear of internal table
    Durairaj Athavan Raja
    Currently Being Moderated

    itab with header line.

     

    clear: clears the header line.

    refresh: clears the whole table.

     

    itab without header line.

     

    clear & Refresh : clears the whole table.

     

    Regards

    Raja

  • Re: diff refresh Vs clear of internal table
    Ganesh Mynampati
    Currently Being Moderated

    hi

     

    When CLEAR itab references an internal table itab with a header line, it only resets the subfields in the header entry to their initial values (as mentioned above). The individual table entries remain unchanged.

     

    To delete the entire internal table together with all its entries, you can use <b>CLEAR itab[]</b> or <b>REFRESH itab.</b>

     

     

     

    REFRESH - Delete an internal table

     

     

    Variants:

    1. REFRESH itab.

     

    2. REFRESH itab FROM TABLE dbtab.

     

    3. REFRESH itab FROM SELECT-OPTIONS.

     

     

     

    Variant 1

    REFRESH itab.

     

     

     

     

    Effect

    The internal table itab is reset to its initial state, i.e. all table entries are deleted.

     

    Der Return Code SY-SUBRC is undefined.

     

     

     

    Notes

    The header entry of a table with a header line remains unchanged. It can be reset to its initial value using CLEAR.

     

    FREE itab can be used to free up the memory allocated to the table.

     

     

     

    Note

    Performance:

     

     

     

    The runtime required to reset an internal table depends on the amount of memory previously occupied by that table.

    Resetting a small internal table takes around 15 msn (standard microseconds). Resetting a 200 KB table takes around 400 msn, and a 1 MB table, around 3000 msn.

    If the internal table has an index or a hash table (because it was edited using INSERT, DELETE, SORT or COLLECT), the runtime increases slightly, since the index or hash table has to be released as well as the table itself.

     

     

     

    Variant 2

    REFRESH itab FROM TABLE dbtab.

     

     

     

     

    In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Key Specifications and Unicode.

     

    This variant is not allowed in an ABAP Objects context. See REFRESH FROM not Allowed.

     

    Note

    This variant is no longer maintained and should no longer be used (see also obsolete key words). Please use the SELECT ... INTO TABLE statement instead.

     

     

     

    Effect

    The internal table itab is deleted and it is then filled with the contents of the database table dbtab.

    A generic argument can be used to specify a restriction to a particular part of the database table when filling (LOOP AT dbtab, READ TABLE dbtab).

    The table dbtab must be declared in the program using TABLES.

     

    Der Return Code SY-SUBRC is undefined.

     

     

     

    Example

    Delete an internal table MESSAGES, then fill the table with all messages from the table T100 with language key 'D' and ID 'RF'.

     

     

     

    TABLES T100.

    DATA MESSAGES TYPE TABLE OF T100 WITH HEADER LINE

     

    MESSAGES-TEXT = 'Delete me'.

    APPEND MESSAGES.

    T100-SPRSL = 'E'.

    T100-ARBGB = 'RF'.

    REFRESH MESSAGES FROM TABLE T100.

     

     

     

    Variant 3

    REFRESH itab FROM SELECT-OPTIONS.

     

     

     

     

    Note

    This variant is no longer supported (see also obsolete key words). The equivalent functionality is now available in the function module RS_REFRESH_FROM_SELECTOPTIONS.

     

     

     

    Effect

    Deletes the internal table itab and then transfers the database selections and the selection parameters together with the values entered by the user.

     

     

     

    Exceptions

    Non-Catchable Exceptions

     

     

     

    Cause: No more memory available to create the table

    Runtime Error: REFRESH_NO_SHORT_MEMORY

     

     

    plz reward if useful

Actions