Wednesday, 14 October 2020 16:19

ABAP tips: Typed inline field symbol declaration

Written by Mike Pokraka
Rate this item
(0 votes)
“© 2020. SAP SE or an SAP affiliate company. All rights reserved.” “Used with permission of SAP SE”

Just a tiny tip for a little shortcut I discovered today. When working with inline declarations, the type may be wrong, we may be doing dynamic programming, or we want to change the data type such as when reading order numbers from a text field.

ASSIGN sometextfield TO FIELD-SYMBOL(<salesorder>). "<== text/string 

Inline declarations like this need to be changed to an explicit FIELD-SYMBOLS declaration up front.

However I discovered a neat way to do this when using Field Symbols, namely with CASTING TYPE:

ASSIGN sometextfield TO FIELD-SYMBOL(<ordernumber>) CASTING TYPE vbeln.

Some of you may of course already know this. CASTING TYPE has been around since well before 7.4, which is why I never considered using it for inline declarations. But it worked, and I thought it is an elegant and readable way to do an inline field symbol constructor with type conversion.

PS. Please do “Like” or comment on blogs you find useful. It’s the only feedback authors get on whether to write more on similar topics. It only takes one click.

Read 51 times

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.