04-06-2006 3:29 PM
Hello, folks!
Can someone explain me what the difference between STATICS and DATA?
My doubts is related to performance: memory allocated, acess in internal tables declared like STATICS, etc.
Thaks a lot!
Rafael Soares
I know how i can use both of them STATIC and DATA.
My doubt is about best practice.
There are some cases that i mustn't use STATIC variables? In some WEBAS configuration this statement can cause a bad performace?
Some OS doesn't work fine with STATIC variables?
Internal tables declared by STATIC have some problem to read data?
Thanks
Rafael
04-06-2006 3:58 PM
Rafael,
A variable declared using STATICS is in memory and the value does not change depending on who is accessing it.
Where as DATA is a normal variable.
Regards,
Ravi
04-06-2006 3:31 PM
F1 Help.
<i>
STATICS
Simple Static Field Definitions
- STATICS f.
- STATICS f(len).
Structured Static Data Object Definitions
- STATICS: BEGIN OF struc,
...
END OF struc.
Structured Static Internal Table Definition
- STATICS itab TYPE tabtype [WITH HEADER LINE].
- STATICS itab TYPE tabkind OF linetype
[WITH [UNIQUE|NON-UNIQUE] keydef]
[INITIAL SIZE n] [WITH HEADER LINE].
- STATICS itab LIKE tabkind OF lineobj
[WITH [UNIQUE|NON-UNIQUE] keydef]
[INITIAL SIZE n] [WITH HEADER LINE].
- STATICS itab TYPE linetype OCCURS n [WITH HEADER LINE].
- STATICS itab LIKE lineobj OCCURS n [WITH HEADER LINE].
- STATICS: BEGIN OF itab OCCURS n,
...
END OF itab [VALID BETWEEN f1 AND f2].
STATICS itab TYPE RANGE OF type.
STATICS itab LIKE RANGE OF f
Effect
The STATICS statement is a variation of the DATA statement. It allows you todefine variables in a procedure (i.e. a FORM or FUNCTION)with local visibility, but static validity.
This statement is not allowed in methods. See STATICS not allowed in instancemethods.
Local visibility means that static variables, like normal local
variables created with DATA, can be accessed by their name only withinthe defining procedure.
Static validity means that, unlike normal local variables, thelife of static variables does not depend on the defining procedure, buton the program at runtime. Static variables are thus not redefined onthe stack each time the defining procedure is called, but existindependently of this in the program and keep their value, regardlessof calls to the defining procedure.
Like all other data objects, static variablesalways have a particular data type. Data types and data objects areimportant components of the ABAP typeconcept.
Example
DATA RESULT TYPE I.
PERFORM RANDOM CHANGING RESULT.
FORM RANDOM CHANGING P_RESULT TYPE I.
STATICS L_STATE TYPE I.
L_STATE = ( L_STATE * 113 + 34 ) MOD 256.
P_RESULT = L_STATE.
ENDFORM.
</i>
Regard,
Rich Heilman
04-06-2006 3:58 PM
Rafael,
A variable declared using STATICS is in memory and the value does not change depending on who is accessing it.
Where as DATA is a normal variable.
Regards,
Ravi
04-06-2006 3:58 PM
Hello Rafael,
Statics means a data definition in a Form-Routine, which is only local visible, but remains when you leave the Form-Routine. I sometimes use it to buffer data, e.g.:
FORM move_dmbtr USING p_bukrs TYPE bukrs
p_shkzg TYPE shkzg
p_dmbtr TYPE dmbtr
CHANGING p_betrg TYPE zg6k_s_iprg1-betrg
p_waers TYPE zg6k_s_iprg1-waers
p_total.
STATICS: BEGIN OF lwa_t001,
bukrs TYPE bukrs,
waers TYPE waers,
END OF lwa_t001.
...
Company Code already known ?
IF lwa_t001-bukrs NE p_bukrs.
CLEAR lwa_t001.
SELECT SINGLE bukrs waers INTO CORRESPONDING FIELDS
OF lwa_t001
FROM t001
WHERE bukrs = p_bukrs.
IF sy-subrc NE 0.
....
ENDIF.
ENDIF.
...
p_waers = lwa_t001-waers.
ENDFORM .
Means, that Table T001 will only be selected, when the company code changes. No problems known so far.
Regards Wolfgang
04-06-2006 4:29 PM
I know how i can use both of them STATIC and DATA.
My doubt is about best practice.
There are some cases that i mustn't use STATIC variables? In some WEBAS configuration this statement can cause a bad performace?
Some OS doesn't work fine with STATIC variables?
Thanks
Rafael