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: 

Difference between statics and data while declaration

Former Member
0 Kudos

Hello Every one,

Please tell me the difference between statics and data whicle declaration with example explanation...

Regards

Martin

3 REPLIES 3

Former Member
0 Kudos

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.

0 Kudos

It was a very quick and helpful example! (Y)

Former Member
0 Kudos

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