Start of Content Area

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 modifiable 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 associated with 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 associated with 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 associating it with a selection screen.

This section explains the DATA and STATICSstatements. For more information about CLASS-DATA; seeClasses. For more information about PARAMETERS, SELECT-OPTIONS and RANGES, see 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 master 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 master 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 STATICS to 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.

 

End of Content Area