Ads

SAP ABAP Variables Types

SAP ABAP Variables Types



In the previous post,we have learned data types in sap abap with examples and difference between data and types in abap and parameters in abap with example along with elementary data types and reference types ,structure types and table types .So now let us learn the variables in SAP and their definition and how to declare them and what is the role of variables in sap abap.

We are using Variables in SAP that are data objects used to store values within the allotted memory area of a program. We can change the content of variables with the help of ABAP statements. Each variable in ABAP has a different type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

We must be declare all types of variables before they can be used. we can declare variable like
DATA <f> TYPE <type> VALUE <val>.

Here <f> specifies the name of a variable. The name of the variable can be up to 30 characters long. <type> specifies the type of variable. Any data type with fully specified technical attributes is known as <type>. The <val> specifies the initial value of the of <f> variable. In case you define an elementary fixed-length variable, the DATA statement automatically populates the value of the variable with the type-specific initial value. Other possible values for <val> can be a literal, constant, or an explicit clause, such as Is INITIAL.

Now let us learn the various variable types available in ABAP. There are three kinds of variables in ABAP:

Static Variables 
Reference Variables 
System Variables 

Static Variables


Static variables are declared in subroutines, function modules, and static methods. The lifetime is linked to the context of the declaration.  With ‘CLASS-DATA’ statement, you can declare variables within the classes. The ‘PARAMETERS’ statement can be used to declare the elementary data objects that are linked to input fields on a selection screen.  You can also declare the internal tables that are linked to input fields on a selection screen by using ‘SELECT-OPTIONS’ statement.
Following are the conventions used while naming a variable:

We cannot use special characters such as "t" and "," to name variables.  The name of the predefined data objects can’t be changed. The name of the variable can’t be the same as any ABAP keyword or clause.  The name of the variables must convey the meaning of the variable without the need for further comments.  Hyphens are reserved to represent the components of structures. Therefore, you are supposed to avoid hyphens in variable names.  The underscore character can be used to separate compound words.

Reference Variables 


The syntax for declaring reference variables is:

DATA <ref> TYPE REF TO <type> VALUE IS INITIAL.

REF TO addition declares a reference variable ref.   The specification after REF TO specifies the static type of the reference variable.  The static type restricts the set of objects to which <ref> can refer.  The dynamic type of reference variable is the data type or class to which it currently refers.   The static type is always more general or the same as the dynamic type.  The TYPE addition is used to create a bound reference type and as a start value, and only IS INITIAL can be specified after the VALUE addition.

System Variables

ABAP system variables are accessible from all ABAP programs.  These fields are actually filled by the run-time environment. The values in these fields indicate the state of the system at any given point of time.   • You can find the complete list of system variables in the SYST table in SAP. Individual fields of the SYST structure can be accessed by using either “SYST-” or “SY-”.

SY-DATUM
SY-DBSYS        
SY-HOST
SY-LANGU
SY-MANDT
SY-OPSYS
SY-SAPRL
SY-SYSID
SY-TCODE
SY-UNAME
SY-UZEIT


Comments

Popular posts from this blog

BADI Interview Questions in SAP ABAP

Sample SAP ABAP Programming Examples for Practice

Module Pool Programming Interview Questions and Answers in SAP ABAP

Step by Step tutorial on BDC Session Method Program in SAP ABAP

SAP ABAP Interview Questions and Answers for 10 Years Experienced