05-20-2010 11:46 PM
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.
05-21-2010 1:05 AM
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.
05-21-2010 2:47 AM
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
05-21-2010 4:15 AM
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.