Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

conversion...

Former Member
0 Likes
837

hi

can anyone pls brief me up with the concept of 'conversions' .. how it is done and and wht exactly it is..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
795

Hi,

<u><b>Type Conversions</b></u>

Every time you assign a data object to a variable, the data types involved must either be

compatible, that is, their technical attributes (data type, field length, number of

decimal places) must be identical, or the data type of the source field must be convertible into the

data type of the target field.

In ABAP, two non-compatible data types can be converted to each other if a corresponding

conversion rule exists. If data types are compatible, no conversion rule is necessary.

If you use the MOVE statement to transfer values between non-compatible objects, the value of

the source object is always converted into the data type of the target object. With all ABAP

operations that perform value assignments between data objects (for example, arithmetic

operations or filling internal tables), the system handles all the necessary type conversions as for

the MOVE statement. If you try to assign values between two data types for which no conversion

rule exists, a syntax error or runtime error occurs.

<u><b>Conversion Rules for Elementary Data Types</b></u>

There are eight predefined ABAP data types. There are 64 possible type combinations

between these elementary data types. ABAP supports automatic type conversion and length

adjustment for all of them except type D (date) and type T (time) fields which cannot be

converted into each other.

The following conversion tables define the rules for converting elementary data types for all

possible combinations of source and target fields.

<u><b>Conversion Rules for References</b></u>

ABAP currently uses class and interface variables within ABAP Objects. Both are

pointers to objects. You can assign values to them in the following combinations:

If the two class references are incompatible, the class of the target field must be the

predefined empty class OBJECT.

When you assign a class reference to an interface reference, the class of the source field

must implement the interface of the target field.

If two interface references are incompatible, the interface of the target field must contain

the interface of the source field as a component.

When you assign an interface reference to a class reference, the class of the source field

must be the predefined empty class OBJECT.

<u><b>Conversion Rules for Structures</b></u>

ABAP has one rule for converting structures that do not contain internal tables as components.

There are no conversion rules for structures that contain internal tables. You can only make

assignments between structures that are compatible.

You can combine convertible structures in the following combinations:

Converting a structure into a non-compatible structure

Converting elementary fields into structures

Converting structures into elementary fields

In each case, the system first converts all the structures concerned to type C fields and then

performs the conversion between the two resulting elementary fields. The length of the type C

fields is the sum of the lengths of the structure components. This rule applies to all operations

using structures that do not contain internal tables.

If a structure is aligned, the filler fields are also added to the length of the type C field.

If you convert a structure into a shorter structure, the original structure is truncated. If you

convert a structure into a longer one, the parts at the end are not initialized according to their

type, but filled with blanks.

It can make sense to assign a structure to another, incompatible, structure if, for example, the

target structure is shorter than the source, and both structures have the same construction over

the length of the shorter structure. However, numeric components of structures that are filled in

incompatible assignments may contain nonsensical or invalid values that may cause runtime

errors.

<u><b>Conversion Rules for Internal Tables</b></u>

Internal tables can only be converted into other internal tables. You cannot convert them into

structures or elementary fields.

Internal tables are convertible if their line types are convertible. The convertibility of internal

tables does not depend on the number of lines.

Conversion rules for internal tables:

Internal tables which have internal tables as their line type are convertible if the internal

tables which define the line types are convertible.

Internal tables which have line types that are structures with internal tables as

components are convertible according to the conversion rules for structures if

the structures are compatible.

Regards,

Bhaskar

4 REPLIES 4
Read only

Former Member
0 Likes
795

HI,

conversion: converting the data from old format to new format.

Example: if old company code is 20 then newcompany code will change to 20002

conversion is use full when changing the system or upgradation the system

Regards

Suresh.D

Read only

amit_khare
Active Contributor
0 Likes
795

Refer the links -

Regards,

Amit

Reward all helpful replies.

Read only

Former Member
0 Likes
796

Hi,

<u><b>Type Conversions</b></u>

Every time you assign a data object to a variable, the data types involved must either be

compatible, that is, their technical attributes (data type, field length, number of

decimal places) must be identical, or the data type of the source field must be convertible into the

data type of the target field.

In ABAP, two non-compatible data types can be converted to each other if a corresponding

conversion rule exists. If data types are compatible, no conversion rule is necessary.

If you use the MOVE statement to transfer values between non-compatible objects, the value of

the source object is always converted into the data type of the target object. With all ABAP

operations that perform value assignments between data objects (for example, arithmetic

operations or filling internal tables), the system handles all the necessary type conversions as for

the MOVE statement. If you try to assign values between two data types for which no conversion

rule exists, a syntax error or runtime error occurs.

<u><b>Conversion Rules for Elementary Data Types</b></u>

There are eight predefined ABAP data types. There are 64 possible type combinations

between these elementary data types. ABAP supports automatic type conversion and length

adjustment for all of them except type D (date) and type T (time) fields which cannot be

converted into each other.

The following conversion tables define the rules for converting elementary data types for all

possible combinations of source and target fields.

<u><b>Conversion Rules for References</b></u>

ABAP currently uses class and interface variables within ABAP Objects. Both are

pointers to objects. You can assign values to them in the following combinations:

If the two class references are incompatible, the class of the target field must be the

predefined empty class OBJECT.

When you assign a class reference to an interface reference, the class of the source field

must implement the interface of the target field.

If two interface references are incompatible, the interface of the target field must contain

the interface of the source field as a component.

When you assign an interface reference to a class reference, the class of the source field

must be the predefined empty class OBJECT.

<u><b>Conversion Rules for Structures</b></u>

ABAP has one rule for converting structures that do not contain internal tables as components.

There are no conversion rules for structures that contain internal tables. You can only make

assignments between structures that are compatible.

You can combine convertible structures in the following combinations:

Converting a structure into a non-compatible structure

Converting elementary fields into structures

Converting structures into elementary fields

In each case, the system first converts all the structures concerned to type C fields and then

performs the conversion between the two resulting elementary fields. The length of the type C

fields is the sum of the lengths of the structure components. This rule applies to all operations

using structures that do not contain internal tables.

If a structure is aligned, the filler fields are also added to the length of the type C field.

If you convert a structure into a shorter structure, the original structure is truncated. If you

convert a structure into a longer one, the parts at the end are not initialized according to their

type, but filled with blanks.

It can make sense to assign a structure to another, incompatible, structure if, for example, the

target structure is shorter than the source, and both structures have the same construction over

the length of the shorter structure. However, numeric components of structures that are filled in

incompatible assignments may contain nonsensical or invalid values that may cause runtime

errors.

<u><b>Conversion Rules for Internal Tables</b></u>

Internal tables can only be converted into other internal tables. You cannot convert them into

structures or elementary fields.

Internal tables are convertible if their line types are convertible. The convertibility of internal

tables does not depend on the number of lines.

Conversion rules for internal tables:

Internal tables which have internal tables as their line type are convertible if the internal

tables which define the line types are convertible.

Internal tables which have line types that are structures with internal tables as

components are convertible according to the conversion rules for structures if

the structures are compatible.

Regards,

Bhaskar

Read only

Former Member
0 Likes
795

Hi,

Conversions are usually done with the help of Function Modules provided by SAP

These are used to display data in local format, as in if the data is stored in German

language in the database but you click to display all entries,

then it will show it in English or the language of Login, with the help of conversion modules.

These conversions are not limited to Texts but all type of data such as currency, date, time, etc.

p.s. to find conversion routines go to se37 -> and search for 'CONVERSION*'

Regards,

Samson Rodrigues.