ABAPASSIGN_CASTING - ASSIGN CASTING
TXBHW - Original Tax Base Amount in Local Currency CPI1466 during BackupThis documentation is copyright by SAP AG.
ASSIGN - casting_spec
Syntax
... { }
| { CASTING { { }
| {TYPE type|(name)}
| {LIKE dobj}
| {[TYPE p] DECIMALS dec}
| {TYPE HANDLE handle} } }
| { obsolete_casting } ... .
Alternatives:
Effect
The casting_spec specification determines with which data type the memory area mem_areaassigned to the field symbol is treated if a statement contains the field symbol at an operand position.You can either make no specification or specify the addition CASTING. Outside of classes, theobsolete variants obsolete_casting are also possible.
Alternative 1
... { }
Effect
If you specify nothing for casting_spec, the field symbol takes on the data type of the dataobject used in mem_area and the assigned memory area is treated accordingly. This data type must be in accordance with thetyping of the field symbol.
Alternative 2
... CASTING ...
Additions
1. ... { }
2. ... TYPE type|(name)
3. ... LIKE dobj
4. ... [TYPE p] DECIMALS dec
5. ... TYPE HANDLE handle
Effect
If you use the addition CASTING in casting_spec, the memory area is treated as if it hadthe type specified by CASTING. When specifying CASTING, the field symbol must not be typedwith the obsolete STRUCTURE addition to the FIELD-SYMBOLS statement.
Casting can either take place implicitly using the typing of the field symbol or explicitly using oneof the additions TYPE, LIKE, or DECIMALS. For explicit casting, you must not specify the field symbol in full, instead specify it generically.
Notes
- If the data type specified by CASTING is deep, the deep components have to appear in the assigned memory area in exactly the same way in terms of type and position. In particular, this means that individualreference variables can be assigned to only one field symbol that is typed as a reference variable by the samestatic type.
- The static check of the ASSIGN statement using the CASTING addition is done is such a way that all errors are identified for Unicode and non-Unicodesystems and for all platforms, regardless of the system and the platform on which the check is run.A runtime check only checks the data against the current system or the current platform. These checkslikewise always take place if the field symbol fs is typed with the obsolete STRUCTURE addition to the FIELD-SYMBOLS statement.
- When the CASTING addition is used, the result of the ASSIGN may differ depending on the platform. For example, the internalbyte sequence ofcharacters in Unicode systems can be platform-dependent. This is evident when a cast is used on a byte-like data type.
Addition 1
... { }
Effect
If the CASTING addition is specified without any further addition, the assigned memory area iscasted to the type of the field symbol. The field symbol must either be fully typed or typed with one of the generic predefined ABAP types c, n, p, or x.
Addition 2
... TYPE type|(name)
Effect
After TYPE, you can specify either a data type type directly, or a character-type dataobject name in brackets, which must contain the label of a data object in uppercase during execution.The assigned memory area is casted to the specified type. The data type specified after TYPE can be generic. However, you cannot specify tables or REF TO.
The field symbol must be typed generically rather than in full. The specified data type mustmatch the generictyping of the field symbol, that is, thecasting can specialize the generic typing, but not generalize it.
If a generic character-type c or n is specified after TYPE, the length of the assignedmemory area must be a multiple of the length of a character in the memory when the statement is executed in Unicode programs.
Addition 3
... LIKE dobj
Effect
After LIKE, you must specify a data object directly. The assigned memory area is casted to the data type of the data object. Within aprocedure, you must not specify a completely generically typed formal parameter for dobj.
The field symbol must be typed generically rather than in full. The specified data type mustmatch the generictyping of the field symbol, that is, thecasting can specialize the generic typing, but not generalize it.
Note
Besides the public attributes of its own program, the public attributes of global classes are also among the data objects that can be referenced using LIKE.
Addition 4
... [TYPE p] DECIMALS dec
Effect
After DECIMALS, you must specify a numeric data object dec. The assigned memory area is casted to the data type p, whereby the number ofdecimal places is determined by the content of dec. The number of decimal places must not exceed thedecimaldigits. TYPE must not be specified at DECIMALS. If you use TYPE, you can specify only the data type p which is used anyway.
The field symbol must be typed generically rather than in full. The specified data type mustmatch the generictyping of the field symbol, that is, thecasting can specialize the generic typing, but not generalize it.
Example
Calculating the quotient from the packed number pack and the field symbol <pack> demonstratesthe effect of casting with the addition DECIMALS. Factors between 10 and 100,000,000 are determined. When using <pack> in operand positions, a different value is used than when using pack.
DATA factor TYPE p LENGTH 8 DECIMALS 0.
DATA pack TYPE p LENGTH 8 DECIMALS 0 VALUE '12345678'.
FIELD-SYMBOLS <pack> TYPE p.
DO 8 TIMES.
ASSIGN pack TO <pack> CASTING DECIMALS sy-index.
factor = pack / <pack>.
WRITE / factor.
ENDDO.
Addition 5
... TYPE HANDLE handle
Effect
After TYPE HANDLE, a reference variable handle of the static type of theCL_ABAP_DATADESCR class or its subclasses is specified and it points to atype object of theRTTS. The assigned memory area is casted to the type described by the type object.
The field symbol must be typed generically rather than in full. The specified data type mustmatch the generictyping of the field symbol, that is, thecasting can specialize the generic typing, but not generalize it.
Note
The type object may have been created from existing data objects or by defining a new data type, using the methods of RTTS.
Addresses (Business Address Services) Fill RESBD Structure from EBP Component Structure
This documentation is copyright by SAP AG.
Length: 12111 Date: 20120518 Time: 191624 triton ( 474 ms )






