From time to time the issue of text-symbols usage keeps popping-up in my daily work, so I decided to write a short blog about why I think it is better to avoid using text-symbols as literals in your code.
You have a report / function module / class where you need to use a text that has to be translatable. One way of doing this is to define a text-symbol.
Now the tricky part is that you can define / use a text-symbol in two ways and it will behave differently when you want to change it:
- You can create a text-symbol by using Goto --> Text elements and reference it in your code via text-ccc(E.g.:text-001)OR
- You can create a literal, reference the text-symbol via a 3-characters ID and use forward navigation (double click on it) to create the text-symbol (E.g.:l_string = ‘Hello world!’(001))
When you choose the second option to create and reference a text symbol, keep in mind the followings:
- If you modify the literal, you always need to use forward navigation to transfer the new value into the text-symbol. Otherwise, the value in use will be the old one.
E.g.: You change
l_string = ‘Hello world!’(001) into
l_string = ‘Hello ABAP!’(001) and you forget to use forward navigation to replace the text-symbol's old value with the new one.
If you output l_string’s value you will see it’s actually ‘Hello world!’ instead of what you might have expected, that is ‘Hello ABAP!’. - If you modify the text-symbols via Goto --> Text elements, the text-symbol will have a value which differs from the literal used in your code. The value that is actually in use is the one from the text-symbol.
E.g.: You go to Goto --> Text elements and you change the value of the text-symbol 001 from ‘Hello world!’ to ‘Hello ABAP!’. In your code, you are still usingl_string = ‘Hello world!’(001).
If you output l_string’s value you will see it is ‘Hello ABAP!’ which, at a first glance, might seem awkward because in your code you have ‘Hello world!’.
Therefore, in order to avoid a mismatch between the actual value in use (which is always the text-symbol) and the value of the literal, reference text-symbols as text-ccc in your code.