Working With Basic Data Objects and Data Types Flashcards
Name all the data objects in ABAP
Variables, Constants, and Literals
What is the difference between Variable, Constant, and Literal data objects?
Variables:
>Data object with content that can change during runtime.
>identified by a name.
Constant:
>Value is hard coded in source code.
>identified by name
Literals:
>Value is hard coded in source code.
>Anonymous (no name)
Keyword to declare a variable in an ABAP program?
Give syntax for declaration of variables.
A variable in an ABAP program is declared with keyword DATA.
Syntax:
DATA <variable> TYPE <type> [ VALUE <starting_value> ].</starting_value></type></variable>
Example:
DATA my_var1 TYPE i.
DATA my_var1 TYPE string.
DATA my_var1 TYPE string VALUE ‘Hello World’.
Keyword to declare a constant in an ABAP program?
Give syntax for declaration of constants.
In ABAP, you declare a constant using keyword CONSTANTS.
( A CONSTANT statement consists of the same parts as a DATA statement. The only difference is, that the VALUE addition is mandatory.)
Syntax:
CONSTANTS <variable> TYPE <type> [ VALUE <starting_value> ].</starting_value></type></variable>
Name three types of data objects in ABAP.
Variables, Constants, and Literals
What is the difference between Variables, Constants, Literals?
Variables:
>Value may change during runtime
>Identified by a name
Constants:
>Value hard-coded in source code
>Identified by a name
Literals:
>Value hard-coded in source code
>Anonymous (no name)
Give the keywords to declare Variables and Constants.
Give statement examples of these keywords.
Variables in ABAP are declared with keywords ‘DATA’
i.e:
DATA <variable_name> TYPE <type> [VALUE <starting_value> ].</starting_value></type></variable_name>
Constants in ABAP are declared with keyword ‘CONSTANTS’
i.e:
CONSTANTS <variable_name> TYPE <type> [VALUE <starting_value> ].</starting_value></type></variable_name>
List the sources of ABAP Data Types.
- ABAP Built-in:
ABAP has a set of 13 predefined data types for simple numeric, char-like, and binary data objects. - TYPES Statement:
Statement TYPES allows you to define data types and reuse them in different places, depending on the location of the definition. - ABAP Dictionary:
The ABAP Dictionary is a part of the ABAP Repository. Among other things, it manages global data types which are available throughout the system. ABAP Dictionary types not only define technical properties, they add semantic information, for example, labels. ABAP Dictionary types are particularly useful when implementing user interfaces.
What are literals used for?
Literals are used to define non-initial values for constants and non-initial starting values for variables.
List and describe the different types of literals.
- Number Literals:
Are integer numbers with or without sign. Number literals usually have data type I. Only if the value is too large for data type I, type P is used, with a sufficient length and without decimal places. - Text Literals:
Are character strings in simple quotes. Text literals have type C. The length is derived from the content in quotes. Trailing blanks are ignored. - String Literals:
Are character strings in a pair of back quotes (`). String literals are of type STRING. They should be used to provide values for string typed data objects.
In a value assignment the type of the source expression and the type of the target variable can be different. If that is the case, the runtime attempts in a type conversion.
Why should type conversions be avoid, if possible?
- Additional Runtime consumption:
Values with type conversions require more runtime than value assignments with identical types.
- Potential Runtime Errors:
Some combinations of source type and target type can lead to runtime errors. If, for example, the target variable has a numeric type l and the source expression has a character like type, then the runtime will raise an error if it cannot translate the text into a number.
- Potential Information Loss:
Some combinations of source type and target type do not cause runtime errors but can lead to a loss of data. If, for example, source and target are of both of type C but the type of the target variable is shorter. Then the runtime simply truncates the value of the source.
What is the CLEAR statement used for?
Give syntax example if this statement.
The CLEAR statement is used to reset a variable to its type-specific initial value.
Syntax:
CLEAR <variable_name>.</variable_name>
Examples:
DATA my_var1 TYPE i.
DATA my_var2 TYPE i VALUE 1234.
DATA my_var3 TYPE string.
my_var1 = my_var2.
my_var3 = ‘HELLO WORLD’
CLEAR my_var1. (Value is reset to 0)
CLEAR my_var2. (Value is reset to 0)
CLEAR my_var3. (String is now empty again).
What is an inline declaration?
Give example.
It is declaring a variable where you also fill it with data.
Explicit Declaration:
DATA my_var1 TYPE string.
DATA my_var2 TYPE i.
my_var1 = ‘HELLO WORLD’
my_var2 = 17
Inline Declaration:
DATA(my_var1) = ‘HELLO WORLD’
DATA(my_var2) = 17