Application Development and Automation 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: 
Read only

How does CONSTANTS in a subroutine differs from STATICS variables

Former Member
0 Likes
805

How does CONSTANTS in a subroutine differs from STATICS variables in a subroutine

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
786

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

6 REPLIES 6
Read only

Former Member
0 Likes
787

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

Read only

0 Likes
786

Hi I do not have a system now could you give me the output- pls

Read only

0 Likes
786

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.

Read only

0 Likes
786

thanks jose points will follow do not worry I am just waiting for more answers

Read only

0 Likes
786

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

Read only

0 Likes
786

great help indeed

2 eg.,s r good

abaper.learner