Skip to Content
Technical Articles
Author's profile photo Mike Pokraka

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.

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Michael Keller
      Michael Keller

      Mike, this is a helpful tip! Thanks for sharing. I spend a lot of time tweaking my code and that definitely helps 🙂

      Author's profile photo Mike Pokraka
      Mike Pokraka
      Blog Post Author

      Yes I like 'tidy up' techniques to make things more straightforward, sometimes little things like this can have a big impact on readability.

      Author's profile photo Matthew Billingham
      Matthew Billingham

      Asking for likes! Tsk tsk. ?

      An excellent tip. I'll definitely be using it. Blog well and truly liked. Although if I like a blog, I usually give some feedback as well.

      Author's profile photo Mike Pokraka
      Mike Pokraka
      Blog Post Author

      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 ?

      Author's profile photo Sandra Rossi
      Sandra Rossi

      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!