Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Clear statement is required before read statement and loop .

Former Member
0 Kudos

Hi Friends,

Is it Mondatory to write a Clear statement before Every Read statement nad Loop Statement in internal tables in REPORT.

Please clarify.

Regards,

Vijay.

3 REPLIES 3

Former Member
0 Kudos

Hi Vijay,

Its a good practise to add a Clear statement before every read & Loop statement to make sure work area or varaible is not filled with wrong data. This is beacuse if a WA contains some data already and if the read stmt is not successful then WA will still contain the same old data which is supposed to be empty and may lead to data discrepency at the end.

Regards,

Lavanya.

Former Member
0 Kudos

Hi,

The use of CLEAR is NOT mandatory in this situation (but is not wrong).

I think that test IF SY-SUBRC = 0 after the READ is mandatory, because this is the right way to know if you find a record in the internal table.

Best regards,

Leandro Mengue

Former Member
0 Kudos

No, absolutely not necessary, but a careful approach is to use a lot of CLEAR statements. For instance,

Read table transporting no fields with key.... etc.....who needs a clear? We just need a check on return code.

Loop at tablename assigning <field-symbol>.... no need to clear, but we need to check to see that the field symbol was assigned.

On the other hand, if we do a read table and we might or might not get a result, a simple clear with a check of return code or structure/field we read into is not initial prevents a lot of incorrect results!

And, since REFRESH is officially obsolete (but then so is FORM...ENDFORM)*, we do clear for fields/structures, clear tablename[] for tables...

  • Official ABAP Programming Guidelines, published by SAP Press, copyright 2010.