Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Assignments →  Setting References →  ASSIGN →  ASSIGN - casting_spec →  Casting Examples 

Field Symbols - Casting Decimal Places

This example demonstrates how a casting of decimal places is carried out.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: pack1 TYPE p DECIMALS 2 VALUE '400',
          pack2 TYPE p DECIMALS 2,
          pack3 TYPE p DECIMALS 2.

    FIELD-SYMBOLS: <f1> TYPE ANY ,
                   <f2> TYPE ANY.

    WRITE: / 'PACK1', pack1.

    SKIP.

<span class="blue">* correct --------------------------------------------------------------</span>

    ASSIGN pack1 TO <f1> CASTING TYPE p DECIMALS 1.
    WRITE: / '<F1> ', <f1>.

    pack2 = <f1>.
    WRITE: / 'PACK2', pack2.

    ASSIGN pack2 TO <f2> CASTING TYPE p DECIMALS 4.
    WRITE: / '<F2> ', <f2>.

    pack3 = <f1> + <f2>.
    WRITE: / 'PACK3', pack3.

    <f2> = '1234.56789'.
    WRITE: / '<F2> ', <f2>.
    WRITE: / 'PACK2', pack2.

<span class="blue">* obsolete, not allowed in methods -------------------------------------</span>

    "ASSIGN pack1 TO <f1> DECIMALS 1.
    "WRITE: / '<F1> ', <f1>.

    "pack2 = <f1>.
    "WRITE: / 'PACK2', pack2.

    "ASSIGN pack2 TO <f2> DECIMALS 4.
    "WRITE: / '<F2> ', <f2>.

    "pack3 = <f1> + <f2>.
    "WRITE: / 'PACK3', pack3.

    "<f2> = '1234.56789'.
    "WRITE: / '<F2> ', <f2>.
    "WRITE: / 'PACK2', pack2.

Description

Three fields of type p all have two decimal places. The field symbols <f1> and <f2> contain one and four decimal places respectively. The numerical values are different for the field symbols and the fields assigned to them.

The part of the method that has been turned into a comment also shows the syntax for the relevant obsolete casting.