Skip to Content


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:

  1. 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
  2. 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 using l_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.

To report this post you need to login first.

19 Comments

You must be Logged on to comment or reply to a post.

  1. Matthew Billingham

    It’s going to be the comments flamewar discussion all over again…!

    You make an interesting point. It’s a matter of balance. I don’t think there is one right answer. As you say, there is a risk with ‘doing it like this'(001), that the text won’t match up. It’s almost the same as a misleading comment – you can’t rely on it being true.

    However, on the other hand, it does make the code more readable and the compare button will pick up any discrepencies.

    On balance, I think I’ll ‘stick with this solution'(002). I think the benefits outweigh the text-003.*

    * risk…

    (0) 
    1. Sergiu Popa Post author

      Hi Matthew,

      Thank you for your input!

      When I wrote this, I was thinking mainly to a scenario where a client reports an issue with a text, you implement a quick fix, but you do the modification like it is explained in the first bullet point. You deliver the fix to the client and then you get feedback that your fix is not working. All these to find out that you forgot to double click on the text after the modification :-).

      Cheers,

      Sergiu

      (0) 
  2. Lars Hvam

    In order to avoid a mismatch run ATC/Code Inspector/Extended Program Check, it has a “TEXT 001 is defined differently in program and in text pool” check.


    It is part of Syntax Check/Generation -> Extended Program Check -> Character Strings in code inspector variant setup

    (0) 
  3. Raymond Giuseppi

    Aren’t SLIN or SCI able to detect mismatch between text in program source, and text symbol in the original language of the program. Also they can be triggered to execute at release of transport request, so you should be allowed to keep understandable text in the source. Even if text-004 seems a better answer of cours.

    (0) 
  4. Naimesh Patel

    You mentioned:

    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.

    I don’t agree with this. LV_STR = ‘Unable to get the grid'(002) is much more easy to read and understand than LV_STR = TEXT-002.

    If you make a change, its your responsibility to update the text symbol.

    Regards,
    Naimesh Patel

    (0) 
  5. Jim Tasker

    My approach is to use a comment at end of line to show the literal value, eg:

    l_string = text-002.     ” ‘This is my text symbol text’

    So you get readability by knowing the text value with no possibility of confusion as to which really matters.  Subsequent changes to the text value tend to be minor revisions that don’t really affect the real meaning, so the comment still helps a maintenance programmer understand while reading the code. 

    Jim

    (0) 
    1. Matthew Billingham

      That makes no sense at all! “ Subsequent changes to the text value tend to be minor revisions that don’t really affect the real meaning, so the comment still helps a maintenance programmer understand while reading the code. ” equally applies to

      i_string = ‘this is my text symbol text'(002)

      And as for “no possibility of confusion”

      i_string = text-002. ” Choose the blue pill

      when

      002 = Choose the red pill

      is exactly as confusing as

      ‘choose the blue pill'(002).

      The result of using a comment is that you get all the ‘drawbacks of this solution'(004) with none of the automatic tools for detecting discrepancies.

      (0) 
      1. Jim Tasker

        But the meaning rarely changes so much…. I see text symbols used mainly for UI texts like selection-screen comments and block titles.  So the change isn’t usually from “choose the blue pill” to “choose the red pill”.  The changes tend to be more like the end user/business anaylst thinks “Choose the blue pill” is better than “Select the blue pill”.

        (0) 
        1. Matthew Billingham

          The actual text variation is irrelevant. My example is merely illustrative. It is clear that:

          text-001 ” Comments next to text

          ‘have less utility than literals'(002)

          Therefore your suggestion that using comments instead of literals makes no logical sense at all. It is, in my view, a pathologically perverse approach. Even less sensible than using comments for versioning. πŸ˜‰

          (0) 
  6. Jelena Perfiljeva

    Personally I avoid using text symbols altogether, but when an occasion calls for it I prefer the text-<number> option. One place where we have text symbols is the description for the selection screen blocks and those are usually pretty generic, so using the actual text in the program code would have very little to no benefit.

    We use SE91 for messages and dictionary definitions for ALV, so the text symbols are actually very rarely needed and hardly ever change. It’s a non-issue for us, but if anyone feels passionately one way or another then it’d probably make sense to put it in the development guidelines.

    (0) 
  7. Sergiu Popa Post author

    I have to recognize I like discussions with good arguments and fierce supporters, so thank you all for that.

    With respect to the answers offering solutions to possible issues that might arise from the text-symbols usages described in this blog post, all solutions provided here are meant to either fix or signal possible issues. In all cases there is something extra that you need to do to rest assured there are no inconsistencies in your code (run extended check / ATC / CI or run text-symbols adjusting utility). Also don’t forget about the human factor. We are not machines, we do make mistakes and it is possible that we forget to run the extended check, ignore the CI errors reported when releasing a transport etc.

    If you use a syntax like text-001, you don’t have to care about running the utility that adjusts the text-symbols, run extended check, ATC or CI. You know you can make your text-symbol modification and it will be consistent.

    As for making the code less readable, I agree with you, but, at the end of the day, it’s a matter of preferences: do you prefer to be worry-free when you make a text-symbol modification or do you want to have to remember to run the utility that adjusts the text-symbols or run extended check, ATC, CI and in case of inconsistencies go back to your code and make the necessary adjustments?

    (0) 
    1. Naimesh Patel

      Using the literals would provide you a huge advantage when you use the “search”. If you don’t use the literals, the search will not return anything. you would need to search in the Text-symbols as well to find the text you looking for. From there, do the where used and find the text.

      You mentioned:

      but, at the end of the day, it’s a matter of preferences:

      I think, its how much you want to be organized and want to make the life of support developers life easier πŸ™‚

      You mentioned:

      do you want to have to remember to run the utility that adjusts the text-symbols or run extended check, ATC, CI and in case of inconsistencies go back to your code and make the necessary adjustments?

      How about just double clicking or navigating to the text symbol when you make the change? This popup will come and if you say, yes – the text symbol would be changed.

      Text_Symbols_with_literals.png

      Regards,
      Naimesh Patel

      (0) 
      1. Sergiu Popa Post author

        Hi Naimesh,

        Why use the search functionality when you know all text-symbols are in a certain place in a class / function module / report and you can go and make your modifications there πŸ™‚ ?

        Regarding the double click, the whole premise of the blog is that you might miss the double click.

        Best regards,

        Sergiu

        (0) 
  8. Jelena Perfiljeva

    I’m curious – in what context do ABAPers even use text symbols these days? As I’ve mentioned, in our system they rarely occur in the first place, so I don’t really get what all the brouhaha is about…

    By the way, ‘Hello world'(001) makes sense when ‘Hello world’ is written in English or other language you understand. Change it to ‘Hallo Welt’ or something and suddenly it’s soooo less helpful. πŸ˜‰

    (0) 
    1. Naimesh Patel

      Great question πŸ™‚

      I still see the text elements used in various different developments like ALV, Messages, Exceptions, Cross Applications (Proxy handling etc). I also still use them 😏

      For ALV, sometimes its easy to use the standard DE but would need different label. Also sometimes the custom DE creation is so much lengthy process (mention the purpose, documentation in DE, documentation in Tech spec), developer end up using the generic custom DE and change the labels. Also, ALV header (using top-of-page), where you put Run Date, Run Time, Total Amount, Description, etc.

      I also use them for messages – as most of my messages are raised via Exceptions.

      Once I had an incoming WS call with additional attributes. These attributes were literals and its values. You can say, these were good example for constants, but these literals were different based on the language from user logged in .. so had to create them as text-symbols.

      Regards,
      Naimesh Patel

      (0) 
    2. Sergiu Popa Post author

      Hi Jelena,

      One example could be the use of generic popup functionalities like confirmation popups in dynpro and webdynpro.

      Best regards,

      Sergiu

      (0) 
    3. Matthew Billingham

      ‘Grüüzi Welt'(001) will still be useful to Swiss developers. For everyone else it’s effectively text-001. It doesn’t detract and it does add some value.

      However, yes. I don’t often use text symbols, as I’m mainly concerned with scrunching data. When I do, I use ‘this format'(002), asi it’s easier for me to read.

      |At least there’s no argument about this type of literal|

      (0) 

Leave a Reply