Using Data Types and Type Conversion correctly Flashcards

1
Q

What are complete types in ABAP, and which data types fall under this category?

A

Complete types in ABAP are those whose length cannot be altered. The types STRING, I, D, and T fall under this category.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are incomplete types in ABAP, and which data types belong to this group?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are built-in ABAP data types classified, and what are the main categories?

A

Built-in ABAP data types are classified into four main categories: character-like, numeric, byte-like, and date and time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are some considerations when choosing numeric types in ABAP?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of type F in ABAP, and what should be considered when using it?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does ABAP handle value assignments between variables of different data types, and what determines whether the conversion is successful?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are some examples of successful assignments in ABAP, and why are they successful?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens when an unsuccessful assignment occurs in ABAP, and what are some examples of such assignments?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does ABAP handle truncation and rounding during value assignments?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are some examples of unexpected results that can occur during value assignments between different data types in ABAP?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is it possible to assign values to date fields in ABAP that do not correspond to a valid date?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are some pitfalls of using inline declarations in arithmetic expressions?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can truncation and rounding be prevented?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What class provides methods to obtain current time and date information in ABAP?

A

The class cl_abap_context_info provides methods that can be used to retrieve current time and date information in ABAP.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does ABAP perform date calculations?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can you access individual components of a date field in ABAP?

A

you can access individual components of a date field using offset and length. For example, to access the month from a date stored in the format YYYYMMDD, you can use the expression var_date+4(2), which retrieves the characters representing the month from the date field.

17
Q

What is the format of the utclong data type in ABAP?

A

The utclong data type in ABAP represents a timestamp according to ISO-8601 format. It has an accuracy of 100 nanoseconds and follows the format YYYY-MM-DDTHH:MM:SS.sssssssZ, where T is the delimiter between date and time, and Z denotes the time zone Zulu, which stands for UTC.

18
Q

Which of the following expressions can you use to force a type conversion?

A
COND #( )

B
EXACT #( )

C
CONV #( )

A

C
CONV #( )

19
Q

Which of the following assignments between variables of different data types is guaranteed to be free of rounding, truncation, field overflow, or type mismatches?

A
TYPE C LENGTH 10 to TYPE C LENGTH 3

B
TYPE DECFLOAT16 TO TYPE DECFLOAT34

C
TYPE STRING to TYPE I

D
TYPE P LENGTH 3 DECIMALS 2 to TYPE P LENGTH 6 DECIMALS 3

A

B
TYPE DECFLOAT16 TO TYPE DECFLOAT34

D
TYPE P LENGTH 3 DECIMALS 2 to TYPE P LENGTH 6 DECIMALS 3

20
Q

You have a result field resultwith TYPE P LENGTH 3 DECIMALS 2. Which of the following statements leads to an exception?

A
result = 1 / 16.

B
result = EXACT #( 1 / 2 ).

C
result = EXACT #( 1 / 8 ).

A

C
result = EXACT #( 1 / 8 ).

21
Q

Which of the following data types is complete?

A
P

B
STRING

C
C

D
N

A

B
String

The data types C, N, and P are all incomplete, and require a length (and, for type P , number of decimal places). Type STRING is complete.

22
Q

Which of the following data types is not a numeric type?

A
I

B
P

C
DECFLOAT16

D
N

A

A
I

B
P

C
DECFLOAT16

Type N is classified as a character-like data type.

23
Q

You subtract one field with type D from another field with type D. What is the data type of the result?

A
D

B
I

C
UTCLONG

A

B
I

The result of adding or subtracting date fields is an integer.