Search code examples
refreshabapinternals

ABAP free internal table


The answer to the question below is given as 2. Why does refresh delete only the first row? Is it not expected that it deletes all rows of an internal table?

What will be output by the following code?

DATA: BEGIN OF itab OCCURS 0, fval type i, END OF itab. 

itab­-fval = 1. APPEND itab.

itab­-fval = 2. APPEND itab.

REFRESH itab.

WRITE: /1 itab­-fval.

A: 1

B: 2

C: blank

D: 0

Answer: B


Solution

  • If the code did not contain any syntax errors, e.g. the missing '-' when assigning the value 2 and when writing the value, then B is the correct answer but not for the reason you state. It is not that the REFRESH only removes the first line from the table, it is because REFRESH does not clear the header line of the table. So after the REFRESH the header line still has the latest assigned value which is 2. This can be easily ascertained when running the program in the debugger.

    Note that the use of internal table with header lines is obsolete, as mentioned in SAP help.