12-10-2007 9:13 AM
Hello Every one,
Please tell me the difference between statics and data whicle declaration with example explanation...
Regards
Martin
12-10-2007 9:22 AM
Hi Martin,
just copy paste this code and set break-points at write statements in FORM SCOPE and in FORM SCOPE2.
data: f1 type I value 1,
f2 type I value 1.
Do 2 times.
Perform scope.
Enddo.
Form scope.
Statics: f1 type I value 2,
f2 type I value 2.
Add: 1 to f1, 1 to f2.
Write: / f1, f2.
Perform scope2.
Endform.
Form scope2.
Write: / f1, f2.
Endform.
10-15-2020 9:41 AM
12-10-2007 9:39 AM
Hi,
The STATICS statement is a variation of the DATA statement. It allows you to define variables in a procedure (CLASS-METHODS, FORM, or FUNCTION) with local visibility, but static validity.
Local visibility means that static variables, like normal local variables created with DATA, can be accessed by their name only within the defining procedure.
Static validity means that, unlike normal local variables, the life of static variables does not depend on the defining procedure, but on the program at runtime. Static variables are thus not redefined on the stack each time the defining procedure is called, but exist independently of this in the program and keep their value, regardless of calls to the defining procedure.
Like all other data objects, static variables always have a particular data type. Data types and data objects are important components of the ABAP type concept.
Data is a statement to declare Local/Global variable.
Declaration of two is as follows :
STATICS L_STATE TYPE I.
DATA L_DATA TYPE I.
Hope this would clarify your doubts to some extent.
Regards,
Lalit