Skip to Content
author's profile photo Former Member
Former Member

Reagarding field symbols....

Hiii.......

Can anyone specify me the exact role of CASTING in Field Symbols??

Mandeep....

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 29, 2007 at 05:32 AM

    hiii

    Casting allows to assign a data object to a field symbol where type of data object is incompatible with field symbol.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 29, 2007 at 05:33 AM

    Hi Mandeep,

    To set the data type of a field symbol independently of the assigned object type (prior to the introduction of the CASTINGaddition was introduced), it was necessary to use the TYPEaddition directly in the ASSIGN statement:

    ASSIGN ... TO adopt the data type specified in dtype instead of the data type and output length of the data object assigned to it. If the field symbol is used in a program after a statement with the TYPE addition, the content of the data object is interpreted in the same ways as for a field of type dtype. You should now use casting with an explicit type declaration in this situation.

    Hope this helps.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 29, 2007 at 05:33 AM

    hi,

    A cast is performed using the CASTINGaddition of the ASSIGN statement. The CASTINGaddition allows you to assign a data object to a field symbol where the type of the data object is incompatible with that of the field symbol. There are two types of casting: casting with an implicit type declaration and casting with an explicit type declaration.

    The CASTING addition replaces some obsolete additions of the ASSIGN statement that should no longer be used.

    Regards,

    viji

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 29, 2007 at 05:33 AM

    HI

    GOOD QUESTION...

    CHECK THIS OUT

    Casting with an Implicit Type Declaration

    Provided the field symbol is either fully typed or has one of the generic built-in ABAP types – C, N, P, or X – you can use the following statement:

    ASSIGN ... TO <FS> CASTING.

    TYPES: BEGIN OF t_date,

    year(4) TYPE n,

    month(2) TYPE n,

    day(2) TYPE n,

    END OF t_date.

    FIELD-SYMBOLS <fs> TYPE t_date.

    ASSIGN sy-datum TO <fs> CASTING.

    WRITE / sy-datum.

    SKIP.

    WRITE: / <fs>-year , / <fs>-month, / <fs>-day.

    Casting with an Explicit Type Declaration=>

    If the field symbol is neither fully typed nor generically typed, use the following form of the ASSIGN statement:

    ASSIGN ... TO <FS> CASTING TYPE <type>|LIKE <obj> [DECIMALS <d>].

    EXAMPLE->

    TYPES: BEGIN OF t_date,

    year(4) TYPE n,

    month(2) TYPE n,

    day(2) TYPE n,

    END OF t_date.

    FIELD-SYMBOLS: <fs> TYPE ANY,

    <f> TYPE n.

    ASSIGN sy-datum TO <fs> CASTING TYPE t_date.

    WRITE / sy-datum.

    SKIP.

    DO.

    ASSIGN COMPONENT sy-index OF STRUCTURE <fs> TO <f>.

    IF sy-subrc <> 0.

    EXIT.

    ENDIF.

    WRITE / <f>.

    ENDDO.

    THANKS

    Kishi.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 29, 2007 at 05:37 AM

    Casting allows to assign a data object to a field symbol where type of data object is incompatible with field symbol.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 29, 2007 at 05:43 AM

    hi,

    REPORT demo_field_symbols_casting.

    TYPES: BEGIN OF t_date,

    year(4) TYPE n,

    month(2) TYPE n,

    day(2) TYPE n,

    END OF t_date.

    FIELD-SYMBOLS <fs> TYPE t_date.

    ASSIGN sy-datum TO <fs> CASTING.

    WRITE / sy-datum.

    SKIP.

    WRITE: / <fs>-year , / <fs>-month, / <fs>-day.

    The output looks something like this:

    1999/05/19

    1999

    05

    19

    casting takes place in char format from left to right..

    first 4 char in sy-datum => year

    next 2 char => month

    next 2 char => date

    Regards,

    Aparna

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.