Entering content frame

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.

 

Leaving content frame