Wednesday 10 July 2013

JULY 10


 I learned about data objects, their definition and declaration.

DATA OBJECTS

Defining Data Objects:

The physical units with which ABAP statements work at runtime are called internal program data
objects. The contents of a data object occupy memory space in the program. ABAP statements

access these contents by addressing the name of the data object. For example, statements can

write the contents of data objects in lists or in the database, they can pass them to and receive

them from routines, they can change them by assigning new values, and they can compare them

in logical expressions.

Each ABAP data object has a set of technical attributes, which are fully defined at all times when

an ABAP program is running. The technical attributes of a data object are: Data type, field length,
and number of decimal places.

 Data objects are memory locations that you use to hold data while the program is running. There are two types of data objects: modifiable and non-modifiable. The types of non-modifiable data objects are literals and constants
The modifiable data objects are variables, field strings, and internal tables. 
A field string is the ABAP/4 equivalent of a structure. An internal table is the ABAP/4 equivalent of an array. When the program starts, the memory allocation for each data object occurs in the roll area of the program. While the program is running, we can read the contents of a non-modifiable data object or put data into a modifiable data object and then retrieve it. When the program ends, the system frees the memory for all data objects and their contents are lost.
Data objects have three levels of visibility: local, global, and external. The visibility of a data object indicates from where in the program the data object is accessible.
Locally visible data objects are accessible only from inside the subroutine in which they are defined. Globally visible objects can be accessed from anywhere within the program. Externally visible objects are accessible from outside of the program by another program.

The following figure displays these three levels of visibility pictorially.



The local data objects in subroutine 1A are visible only from within that subroutine. Any statement outside of it cannot access them. Similarly, the local data objects in subroutines 1B and 2A are not accessible from anywhere but within those subroutines.
Any statement in program 1, regardless of where the statement appears, can access the global data objects in program 1. Similarly, any statement in program 2 can access the global data objects in program 2.
The external data objects could be accessed from any statement in program 1 or program 2. In actuality, whether they can be or not depends on the type of external memory area used and the relationship between the two programs.


Declaring Data Objects

Apart from the interface parameters of routines, we declare all of the data objects in an ABAP program or routine in its declaration part. The declarative statements establish the data type of the object, along with any missing technical attributes, such as its length or the number of decimal places. This all takes place before the program is actually executed. The exception to this are internal tables.

Defining Literals (non-modifiable data objects)

literal is a non-modifiable data object. Literals can appear anywhere in a program, and they are defined merely by typing them where needed. There are four types: character string, numeric, floating-point, and hexadecimal.

Character String Literals

Character string literals are case-sensitive character strings of any length enclosed within single quotes. For example, 'JACK' is a character string literal containing only uppercase characters. 'Caesar the cat' is a character string literal containing a mixture of upper- and lowercase characters.
Because a character string literal is enclosed by quotes, we cannot use a single quote by itself in the value of the literal. To represent a single quote, we must use two consecutive single quotes. 
For example, the statement write 'Caesar''s tail'. will write Caesar's tail, but the statement write 'Caesar's tail' will cause a syntax error because it contains a single quote by itself.

Numeric Literals

Numeric literals are hard-coded numeric values with an optional leading sign. They are not usually enclosed in quotes. However, if a numeric literal contains a decimal, it must be coded as a character string enclosed within single quotes. If it is not, the syntax error Statement x is not defined. Please check your spelling. will occur.
For example, 256 is a numeric literal, as is -99'10.5' is a numeric literal that contains a decimal point, so it is enclosed by single quotes. A literal can be used as the default value for a variable, or it can be used to supply a value in a statement.
Examples of invalid literals are: 99- (trailing minus sign), "Confirm" (enclosed in double quotes), and 2.2 (contains a decimal but is not enclosed in quotes).

Floating-Point Literals

Floating-point literals are specified within single quotes as '<mantissa>E<exponent>'. The mantissa can be specified with a leading sign and with or without decimal places, and the exponent can be signed or unsigned, with or without leading zeros.
For example, '9.99E9''-10E-32', and '+1E09' are valid floating-point literals.

Hexadecimal Literals

hexadecimal literal is specified within single quotes as if it were a character string. The permissible values are 0-9 and A-F. There must be an even number of characters in the string, and all characters must be in uppercase.
Examples of valid hexadecimal literals are '00''A2E5', and 'F1F0FF'
Examples of invalid hexadecimal literals are 'a2e5' (contains lowercase characters), '0' (contains an uneven number of characters), "FF"(enclosed in double quotes), and x'00' (should not have a preceding x).

Right and Wrong Ways to Code Literals

Right
Wrong
Explanation
-99
99-
Trailing sign not permitted on a numeric unless it's within quotes.
'-12'

Numerics within quotes can have leading'12-'or trailing sign.
'12.3'
12.3
Numerics containing a decimal point must be enclosed in single quotes.
'Hi'
"Hi"
Double quotes are not permitted.
Right
Wrong
Explanation
'Can''t'
'Can't'
To represent a single quote, use two consecutive single quotes.
'Hi'
'Hi
Trailing quote is missing.
'7E1'
7E1
Floating-point values must be enclosed within quotes.
'7e1'

Lowercase e is allowed for floating-point literals.
'0A00'
'0a00'
Lowercase in hexadecimal literals gives incorrect results.
'0A00'
'A00'
An uneven number of hexadecimal digits gives incorrect results.
'0A00'
X'0A00'
A preceding or following character is not permitted for hexadecimal literals.