Using Data Types and Type Conversion correctly Flashcards
What are complete types in ABAP, and which data types fall under this category?
Complete types in ABAP are those whose length cannot be altered. The types STRING, I, D, and T fall under this category.
What are incomplete types in ABAP, and which data types belong to this group?
Incomplete types in ABAP are those for which you must specify the length when declaring a variable. The types C, N, and P are incomplete types. Additionally, for type P, you must specify the number of decimal places.
How are built-in ABAP data types classified, and what are the main categories?
Built-in ABAP data types are classified into four main categories: character-like, numeric, byte-like, and date and time.
What are some considerations when choosing numeric types in ABAP?
When choosing numeric types in ABAP, you should consider using type I for whole numbers and type P for numbers with decimal places.
If the range of type I is insufficient, you can use type INT8.
Additionally, if the range or accuracy of type P is insufficient, you can use one of the DECFLOAT types, such as DECFLOAT34, which supports significantly higher accuracy.
What is the purpose of type F in ABAP, and what should be considered when using it?
Type F in ABAP is used for binary floating point numbers. However, it’s important to note that rounding errors can occur when converting binary numbers back into the decimal system. Therefore, it’s generally recommended to avoid using type F for calculations in programs.
How does ABAP handle value assignments between variables of different data types, and what determines whether the conversion is successful?
value assignments between variables of different data types are allowed. ABAP attempts to convert the value of the source field into the type of the target field. Whether the conversion is successful depends on whether the value of the source field is compatible with the data type of the target field.
What are some examples of successful assignments in ABAP, and why are they successful?
Successful assignments in ABAP occur when the value of the source field is compatible with the data type of the target field. For example, assigning the value of a string containing “12345” to an integer field is successful because “12345” can be represented as a valid integer.
What happens when an unsuccessful assignment occurs in ABAP, and what are some examples of such assignments?
unsuccessful assignments occur when the value of the source field is incompatible with the data type of the target field.
This can lead to exceptions, such as CX_SY_CONVERSION_NO_NUMBER or CX_SY_CONVERSION_OVERFLOW. Examples of unsuccessful assignments include attempting to assign a non-numeric string to an integer field and attempting to assign a value that exceeds the range of a numeric field.
How does ABAP handle truncation and rounding during value assignments?
truncation occurs when a value is assigned to a field with insufficient length, resulting in the loss of data. Rounding occurs when a value is assigned to a numeric field with insufficient decimal places, and the system performs arithmetic rounding
What are some examples of unexpected results that can occur during value assignments between different data types in ABAP?
unexpected results can occur when assigning values between different data types.
For example, assigning a date field to an integer field results in the number of days since 01.01.0001
assigning a time field to an integer results in the number of seconds since midnight.
assigning a character field or string to a variable with type N results in the system discarding non-digit characters, right-justifying the remaining digits, and filling any remaining spaces with leading zeroes.
Why is it possible to assign values to date fields in ABAP that do not correspond to a valid date?
From a technical point of view, a date field in ABAP is treated as a character field. Therefore, it is possible to assign values to date fields that do not correspond to a valid date. However, note that this situation typically does not occur when users enter dates via the UI, as the UI layer validates the date input.
What are some pitfalls of using inline declarations in arithmetic expressions?
When using inline declarations in arithmetic expressions, the system derives the type of the new variable from the right-hand side of the expression. For example, if numeric literals like 5 and 10 are integers, the variables created from inline declarations will also be integers. This can lead to unexpected results, such as rounding up the result of a division operation.
How can truncation and rounding be prevented?
By using EXACT rounding and truncation is not allowed and an exception occurs (cx_sy_conversion_error).
In the same way EXACT can be used to trigger an exception when an invalid value is entered, like ABCDEFGH for a date variable.
What class provides methods to obtain current time and date information in ABAP?
The class cl_abap_context_info provides methods that can be used to retrieve current time and date information in ABAP.
How does ABAP perform date calculations?
In ABAP, date calculations involve converting dates into an integer representing the number of days since 01.01.0001. ABAP then adds or subtracts the relevant number of days to perform the calculation.