Skip to Content
Technical Articles

ABAP tips: Typed inline field symbol declaration

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.

You must be Logged on to comment or reply to a post.
    • Yes I like 'tidy up' techniques to make things more straightforward, sometimes little things like this can have a big impact on readability.

    • I know, I feel like a desperate YouTuber ?

      On a serious note, I did think long and hard whether to write that, but the difference is that we don’t get paid or points or anything. I also took care to word it not about my blog, but as a general comment that people shouldn’t be shy with feedback.

      And lastly, there is a genuine curiosity whether “little nuggets of usefulness” is something people want so see more of, as I tend to stumble across this kind of stuff all the time. I have tons of blogs in my head that I just don’t have the time to write, but a quick one here and there is easier to do if there’s interest for quick tips. And I think that question has been answered ?

  • 34 likes already. No need to ask, even if some people complains about the poor reaction of community. I think it's a correct score. People definitely asks for more blog posts!