Why not to use ABAP Text Symbols instead of Constants

By | April 15, 2015 | Concepts | 12,141 | 2

Many times I have seen people are using the ABAP Text Elements. You must not use them as constants.

Preface

Don’t get me wrong. Text symbols are good, but don’t overdo them. As part of my QA reviews, many times, I see developers use Text Symbols everywhere. In this short article, I want to let you know when not to use them.

Where are they used

I have seen them used as:

  • For Column descriptions
  • For providing messages
  • Column Names for ALV
  • Column Names for Dynamic Field access
  • Description of the internal text
Text_Symbols_Incorrect_2

Text_Symbols_Incorrect_1

What Is the main Problem?

Since text symbols are specific to language and the main purpose of them is to provide language specific feedback to user, they would need to be translated in all the languages in which program can be executed. If they are not translated, it would provide incorrect result when executed in different language.

When (not) to use Text Symbols

Some guidelines

  • You should only use the text symbols when you think the text would be visible to end-user. Like the text in the message, message log for the jobs, Selection screen, Report output, Column names, etc
  • You must not use the text symbols if the text is for internal purpose. Consider this example, that somebody has designed a table which stores actual description as status instead of the status identifier – This itself is a big NO-NO. In this situation, you should better off creating with constant
  • Column names must be created with constants if they are used as parameter to subroutine, parameter to method, parameter to FM, or dynamic access
  • Text symbols are private to that specific class and not accessible in the inherited classes so, they must not be used if it is not visible to end user

How to avoid them?

Once you are done with your development, take a look at the text pool and identify if any of them are incorrectly maintained. If you find that, don’t hesitate to change unless you are planning to code the logic like that.

Have you seen these type of text symbols?

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

2 Comments

  • Binay

    Hi,

    I have turned a fan of your posts.

    But I may disagree with you on this post in terms of the translation.
    I still doubt if using constants will help in case of the same program used across countries using different languages, the translation won’t happen and the entire program needs to be re-written for each different language.
    Text-symbols serve the translation purpose easily.

    I have already faced such an issue where the program had used constants throughout and due to the translation issue, I had to replace them by text-symbols.
    Since then I am in a practise of preferring text-symbols instead of constants.

    Also in case of table uploads for specific languages, text-symbols can very well be translated and serve the purpose. This makes the text-symbols more advantageous than constants.

    Please correct me if I am wrong.

    However, I completely agree with your last 2 points under the section “When (not) to use Text Symbols”.

    Binay.

  • Hello Binay,

    I’m glad that you like what you read here 🙂

    Regarding your question, if the constant is the name of the field, it would be same across all the Languages. It would not be different if different country. Like MATNR, or MANDT would be still same if program is running in EN or ES or DE.

    If the constant value is language dependent like ‘Enter the Value’, it should be definitely Text Symbol, not the constant. I’m interested in the issue which you had faced. Can you provide more details on that?

    Thanks,
    Naimesh Patel

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.