Get Example source ABAP code based on a different SAP table
VERSION 5 IN
Assignment and Conversion Rules When the value of a source object (source>) is assigned to a destination object (destination>), three cases can be distinguished with respect to the data type: source> and destination> are compatible>, which means that all technical type properties> match. The content is transferred from source> to destination> without being converted. For flat data objects and coherent character-like or byte-like structural areas, a copy of the source object is created down to the exact byte. In the case of deep> data objects, a reference is created whose actual byte-like content is not visible externally in the destination object. When entire structures are assigned, the behavior in terms of alignment gaps> is undefined. The binary content of an alignment gap in the destination structure can either be copied from the source structure or keep the original value. source> and destination> are not compatible but can be converted>. The content of source> is converted in accordance with the conversion rules and then transferred to destination>. Two data types are convertible if a conversion rule exists for them. An exception is raised if the content of source> cannot be handled in accordance with the conversion rules. After an exception, the content of destination> depends on the category of the data type. An assignment where a conversion takes place is always slower than an assignment without conversion. If the data objects are neither compatible nor convertible, no assignment can take place. If the syntax check recognizes this state, a syntax error is raised, otherwise an uncatchable exception is raised when the program is executed. The following sections describe the conversion rules. Conversion rules exist for:
Elementary data objects>
Structures>
Internal tables>
Meshes>
Enumerated types> The special assignment rules for reference variables> are listed in a separate section. The conversion rules shown here generally apply to all assignments> and all statements in which the content of data objects is changed. Exceptions to these rules are described in the individual statements. The conversion operator> CONV>> can be used in many operand positions to convert a source value to an explicitly specified target data type in accordance with the rules described here. System classes> are available for special conversions of character sets and numeric formats.
Latest notes:
In the operand positions> of many statements, assignments take place internally according to the assignment rules. Whether the exceptions that occur during an assignment can be handled or not depends on the operands and the operand position. The following are some examples:
If functional method calls> are used in operand positions, exceptions that can be handled when data objects are used directly cannot be handled, and produce runtime errors directly instead.
In comparisons>, some different rules> apply than in assignments. Exceptions that are catchable in assignments are either handled implicitly or lead to runtime errors and cannot be handled explicitly in comparisons.
Using expressions> in operand positions can make uncatchable exceptions catchable in some cases.
The lossless operator> EXACT>> can be used to perform checks before the conversion is executed that ensure that only valid values are assigned and that no values are lost in assignments.
Checks generally are not made on assignments between compatible data objects. If a data object already contains an invalid value, for example an invalid date or time in a date or time field, it is transferred like a valid value if the assignment is being made to a compatible data object.
In order to check if two data types are compatible at runtime, the method APPLIES_TO_DATA> of RTTI class CL_ABAP_DATADESCR>> can be used. This can be helpful to prevent uncatchable exceptions when assigning generically typed data objects that are neither compatible nor convertible. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 Method APPLIES_TO_DATA> of RTTI class CL_ABAP_DATADESCR>> is used to check the compatibility of generically typed field symbols pointing to different data objects. Assigning the content of <(><)> to <(><)> would raise an uncatchable exception. ABEXA 01726 ABAP_EXAMPLE_END