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

Casting type

Former Member
0 Likes
853

Hi,

Need some pointers with example on how "CASTING TYPE" is used in case of field symbols.

Regards

Saurabh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
594

HI

GOOD

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

MRUTYUN

2 REPLIES 2
Read only

Former Member
0 Likes
595

HI

GOOD

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

MRUTYUN

Read only

Former Member
0 Likes
594

tx