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: 

Static variables

Former Member
0 Kudos
6,093

How to decalre a static variable in SAP apart from OOABAP..In Normal ABAP how we can made it possible

1 ACCEPTED SOLUTION

Former Member
0 Kudos
1,270

Hi Mahesh,

Variables Locate the document in its SAP Library structure

Variables are named data objects that you can declare statically using declarative statements, or dynamically while a program is running. They allow you to store changeable data under a particular name within the memory area of a program.

You can declare variables statically using the following statements:

· DATA: To declare variables whose lifetime is linked to the context of the declaration

· STATICS: To declare variables with static validity in procedures

· CLASS-DATA: To declare static variables within classes

· PARAMETERS: To declare elementary data objects that are also linked to an input field on a selection screen

· SELECT-OPTIONS: To declare an internal table that is also linked to input fields on a selection screen

· RANGES: To declare an internal table with the same structure as in SELECT-OPTIONS, but without linking it to a selection screen.

This section explains the DATA and STATICSstatements. For further information about CLASS-DATA; refer to Classes. For further information about PARAMETERS, SELECT-OPTIONS and RANGES, refer to Selection Screens.

Declaring Variables Dynamically

You can also create data objects dynamically when you call procedures. These data objects are the formal parameters of the interface definition, which only have technical attributes when they inherit them from the actual parameters passed to them.

Static Variables in Procedures

Variables that you declare with the DATA statement live for as long as the context in which they are defined. Therefore variables in an ABAP main program exist for the entire runtime of the program, and local variables in procedures only exist for as long as the procedure is running.

To retain the value of a local variable beyond the runtime of the procedure, you can declare it using the STATICS statement. This declares a variable with the lifetime of the context of the main program, but which is only visible within the procedure.

The first time you call a subroutine or function module, the corresponding main program is always loaded into the internal session of the calling program. It is not deleted when the procedure ends. This enables variables defined using STATICSto retain their values beyond the runtime of the procedure, allowing them to be reused the next time the procedure is called (see the example in the Local Data in Subroutines section).

In methods, variables defined with STATICS are static attributes that are only visible in the corresponding method, but for all instances of a class (see Classes).

The syntax of the STATICS statement is identical to that of the DATA statement.

or u just foloe up dis link:-

if u find it useful den do give points also.

4 REPLIES 4

sreeramkumar_madisetty
Active Contributor
0 Kudos
1,270

Hi

Static Variables concept comes into the picture only in ooabap.

Regards,

Sree

Former Member
0 Kudos
1,271

Hi Mahesh,

Variables Locate the document in its SAP Library structure

Variables are named data objects that you can declare statically using declarative statements, or dynamically while a program is running. They allow you to store changeable data under a particular name within the memory area of a program.

You can declare variables statically using the following statements:

· DATA: To declare variables whose lifetime is linked to the context of the declaration

· STATICS: To declare variables with static validity in procedures

· CLASS-DATA: To declare static variables within classes

· PARAMETERS: To declare elementary data objects that are also linked to an input field on a selection screen

· SELECT-OPTIONS: To declare an internal table that is also linked to input fields on a selection screen

· RANGES: To declare an internal table with the same structure as in SELECT-OPTIONS, but without linking it to a selection screen.

This section explains the DATA and STATICSstatements. For further information about CLASS-DATA; refer to Classes. For further information about PARAMETERS, SELECT-OPTIONS and RANGES, refer to Selection Screens.

Declaring Variables Dynamically

You can also create data objects dynamically when you call procedures. These data objects are the formal parameters of the interface definition, which only have technical attributes when they inherit them from the actual parameters passed to them.

Static Variables in Procedures

Variables that you declare with the DATA statement live for as long as the context in which they are defined. Therefore variables in an ABAP main program exist for the entire runtime of the program, and local variables in procedures only exist for as long as the procedure is running.

To retain the value of a local variable beyond the runtime of the procedure, you can declare it using the STATICS statement. This declares a variable with the lifetime of the context of the main program, but which is only visible within the procedure.

The first time you call a subroutine or function module, the corresponding main program is always loaded into the internal session of the calling program. It is not deleted when the procedure ends. This enables variables defined using STATICSto retain their values beyond the runtime of the procedure, allowing them to be reused the next time the procedure is called (see the example in the Local Data in Subroutines section).

In methods, variables defined with STATICS are static attributes that are only visible in the corresponding method, but for all instances of a class (see Classes).

The syntax of the STATICS statement is identical to that of the DATA statement.

or u just foloe up dis link:-

if u find it useful den do give points also.

Former Member

Former Member
0 Kudos
1,270

hi there,

You can declare variables statically using the following statements:

DATA: To declare variables whose lifetime is linked to the context of the declaration

<b>STATICS: To declare variables with static validity in procedures</b>

CLASS-DATA: To declare static variables within classes

PARAMETERS: To declare elementary data objects that are also linked to an input field

on a selection screen

SELECT-OPTIONS: To declare an internal table that is also linked to input fields on a

selection screen

RANGES: To declare an internal table with the same structure as in SELECT-OPTIONS, but without linking it to a selection screen.

Reward if helpful,

regards,

Guru