‎2012 May 11 6:40 PM
Hi All,
I was having a discussion with someone who wanted me to remove CLEAR statement with local variable. I use to follow the rule that we should always clear a variable before use. But now I couldn't find any reason why we should do this. Expert comments needed. Also, what does official SAP standards say?
Thanks,
Bhaskar
‎2012 May 11 7:13 PM
Hi,
Clearing variable before use is always better. But in this case you are using a local field which will get declared only in that subroutine. Hence even if you dont clear it, field will be initial.
But inside a loop, you will have to clear(depending on circumstances).
Thanks,
Sam.
‎2012 May 11 7:13 PM
Hi,
Clearing variable before use is always better. But in this case you are using a local field which will get declared only in that subroutine. Hence even if you dont clear it, field will be initial.
But inside a loop, you will have to clear(depending on circumstances).
Thanks,
Sam.
‎2012 May 11 7:31 PM
Hi :If you are using subroutines, f.m , methods in a loop its always good to clear local variables since you follow this practice i would advice there is no harm in doing so performance wise etc. only exist for as long as the procedure is running. Here procedure is subroutine,f.m , methods
From official standards:
Global variables:Variables that you declare with the DATA statement live for as long as the context in which they are defined. So variables in an ABAP main program exist for the entire runtime of the program,
local variables: in subroutines, function modules , methods
Hope this helps in explaining the fact that clearing local variable depends on circumstances.
‎2012 May 11 7:33 PM
Clearing a local variable prior to use is almost a replication of the data statement that created it. I can't figure out why one of my ex-colleagues did that in every form...endform. I can't begin to imagine how many of these time-wasters I've removed...
Question: what's the point of:
form....
data: lv_var(1) type c.
clear lv_var.
...
Answer: Just looks like an amateur wrote the code?
‎2012 May 11 8:22 PM
Hi,
local vars do not need to be clear prior to use. They are by definition cleared after the data declaration.
Of course as mentioned before if you are using them in a LOOP then you might need to clear, depending on the situation.
Cheers
Adi
‎2012 May 13 4:06 PM
Hi,
I believe we not need to clear local variables (Of course on circumstances).
As we know the purpose of local variable is just within some scope (FORM...ENDFORM, Function Module, etc), It is no need to clear local variables all the time as global variable.
Regards,
nimz
‎2012 May 29 12:34 PM
HI,
Yes this piece of code is absolutely not required for local variables used inside the sub-routines.Well few things should always be applied depending on LOGIC and may not require to search for so called SAP standards.
Cheers.
Supratim Saha.
‎2012 May 29 1:23 PM
Hello,
All the above statements are correct.
But, I believe that is better to write an extra line of code clearing a local variable that to omit it and under certain circumstances ( loop etc ) have a data error in a report.
I don't think that the code is written by amateurs when I see a clear statement for a local variable as mentioned above.
Regards.