Technology Blog Posts by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
jrgkraus
Active Contributor
406

Why quit using text elements?

Text elements are really old-school. They are stored with a report or a class and are accessible by other parts of the application only indirectly. There are are approaches to avoid these problems (see this old blog of mine). However, the online text repository (OTR) frame offers a more modern way to handle texts. Here some points that made me switch to OTR:

  • Text elements have meaningless key (text-010). Only using a literal in the coding or leaving a comment will make the coding readable
  • Text elements are stored with a program (or class). As soon as you start refactoring and extracting classes, you have to move the text elements (or store all text elements in a separate class es described in the blog mentioned above)
  • Text elements are of limited length
  • Text elements have an unhandy fixed length type, which makes it necessary to convert the values when passing them to string parameters

With OTR texts, all the above is resolved. However, the coding blows up a bit. Instead of writing

logger->add( 'Something's wrong'(001) ).

You have to code something like this:

logger->add( new CL_BSP_GET_TEXT_BY_ALIAS(
 )->get_text(
      language = sy-langu
      alias = 'ZDV24_TEXT_ACCESS_DEMO/EXAMPLE' ) ).

I created a small framework for this in order to streamline the use. It is available for download on github. With this, the coding turns out to be a bit friendlier:

class text definition inheriting from zcl_otr_util_demo_text_enum.
endclass.

class app definition inheriting from zcl_otr_util_demo_texts.
  public section.
    methods main.
endclass.

CLASS app IMPLEMENTATION.
  method main.
    cl_demo_output=>display( get_text( text=>the_text ) ).
  endmethod.
ENDCLASS.

 

Labels in this area