2008 Feb 09 6:01 AM
How does CONSTANTS in a subroutine differs from STATICS variables in a subroutine
2008 Feb 09 6:26 AM
Hi,
in simple words statics is used declare variable inside a sub-routine whose life dosen't end when the subroutine ends..
the foll code will explain more......
data f value 1.
PERFORM hello.
f = 2.
PERFORM hello.
FORM hello.
DATA a(30).
STATICS b(30).
if f = 1.
move : 'local bcoz declared as data' to a,
'global bcoz declared as static' to b.
else.
write /.
endif.
write: / 'call no = ',f,' a = ',a,'b = ',b.
ENDFORM.Cheers,
jose.
Edited by: jose on Feb 9, 2008 7:34 AM
How does CONSTANTS in a subroutine differs from STATICS variables in a subroutine
2008 Feb 09 6:26 AM
Hi,
in simple words statics is used declare variable inside a sub-routine whose life dosen't end when the subroutine ends..
the foll code will explain more......
data f value 1.
PERFORM hello.
f = 2.
PERFORM hello.
FORM hello.
DATA a(30).
STATICS b(30).
if f = 1.
move : 'local bcoz declared as data' to a,
'global bcoz declared as static' to b.
else.
write /.
endif.
write: / 'call no = ',f,' a = ',a,'b = ',b.
ENDFORM.Cheers,
jose.
Edited by: jose on Feb 9, 2008 7:34 AM
2008 Feb 09 6:38 AM
Hi I do not have a system now could you give me the output- pls
2008 Feb 09 6:41 AM
output
call no = 1 a = local bcoz declared as data b = global bcoz declared as static
call no = 2 a = b = global bcoz declared as static.
in the second call variable a(declared as data) got initialized but variable b(declared as statics) has the previous value
Cheers,
jose.
2008 Feb 09 6:45 AM
thanks jose points will follow do not worry I am just waiting for more answers
2008 Feb 09 6:51 AM
Hi,
example given in SAP Keyword hlp.
DO 10 TIMES.
PERFORM add_one.
ENDDO.
FORM add_one.
DATA local TYPE i VALUE 0.
STATICS static TYPE i VALUE 0.
local = local + 1.
static = static + 1.
WRITE: / local, static.
ENDFORM.output
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2008 Feb 09 7:01 AM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |