Fareez Ahamed

Text Symbols in Web Dynpro ABAP

November 07, 2012

Text symbols are one of the great and most used feature in ABAP. It is very helpful when it comes to internationalization of your application and also manages all your text at one place. ‘Is this feature available in Web Dynpro?’ Yes indeed, but it seems Web Dynpro has complicated accessing it. So this article is all about creating a simple application that gets the text from Text Symbols and places the text in a caption.

There is something called Assistance Class in Web Dynpro ABAP. Each Web Dynpro component can have one Assistance Class associated with it. An Assistance Class is any global class that inherits CL_WD_COMPONENT_ASSISTANCE. This class can contain any business logic and this class is automatically instantiated when the component is running. WD_ASSIST is the reference for the instance of this class which you can use from anywhere within the component. Though Assistance Class has other uses, Text Symbols is one that we are going to use now.

Create a class in SE24 and make the CL_WD_COMPONENT_ASSISTANCE as the super class to it.

Creating a class

Now create a new Web Dynpro Component and enter the name of the class you created in the previous step as the Assistance Class for this component (Here its ZCL_FAR_TXT_SYMB). This assistance class is going to contain all the Text Symbols you need and you can retrieve it whenever you want using the method IF_WD_COMPONENT_ASSISTANCE~GET_TEXT( KEY = 'XXX' ) where XXX is the key of the Text Symbol you want.

Creating a class

Now you can go to the MAIN view and from menu select Goto -> Text Symbols. Here you can create text symbols as exactly as you do in ABAP Report programs. Now I create a single Text Element as “Hello World!”. Save and Activate the Text Symbols.

Creating a class

Making use of the Text Symbols is not similar to report programs. Create an attribute in the context of the MAIN view named HELLO of type String. Create a caption in the layout and bind the Text property of the caption to HELLO attribute of the context. Now we are going to set the text we have in the Text Symbols to this caption using the following code.

method WDDOINIT .

  data txt type string.

  txt = wd_assist->if_wd_component_assistance~get_text( key = '001' ).
  wd_context->set_attribute( exporting name = 'TEXT' value = txt ).

endmethod.

And we get the following output.

Creating a class