July 14, 2015

Text elements in ABAP

When programming in ABAP there are features that are intrinsical to SAP. One of those features are 'Text elements', which purpose is to be used as 'constants' or 'labels' for titles and messages and are defined according to the language of your session.

Text elements are everywhere in SAP, in fact every time you log in, there's a default language which indicates to SAP to load the corresponding titles in all the application. If you choose in your login to use another language then all the screens are translated to that language.

We, as abapers, can make use of those text elements but also can make our own. Tipically when we create a report or a module pool we define text elements to show titles and messages in the screens.

There are three types of text elements;
  1. List headings
  2. Selection texts
  3. Text symbols
Text symbols are out of the scope of this article however this type of text element si used to print a report in the screen when we are not using an ALV.

Selection texts are labels used for input. When we define a parameter, a select-options or checkboxes, etc.

Text symbols are used inside the program to set header for screeens or messages. This kind is the most used in ABAP.

Ok, let's code ABAP;

1. Let's create a report with transaction 'SE38' and paste the following code.

report  ztext_element.

tables mara.

data wa_mara type mara.

selection-screen: begin of block b1 with frame title text-001.
  select-options so_matnr for mara-matnr.
selection-screen: end of block b1.

start-of-selection.

select * into wa_mara from mara up to 10 rows where matnr in so_matnr.
  write / wa_mara-matnr.
endselect.

if sy-subrc ne 0.
  write / 'No data'(002).
endif.

2. Ok, let make a pause here. There are two text symbols in the code above. The first one is in the selection screen and it's name is 'text-001' and the second is inside de if statetement at the bottom and is identified as '(002)'.

We have also a 'SELECT-OPTIONS' which is used for inputs to be used later. However we can set 'Selection texts' to it. This feature also work with 'PARAMETER'.

Activate and run the program.

You'll see the following screen.


3. Return to the source code and go to the menu Goto / Text elements / Text symbols.


4. Type the following data in the grid.


5. In the same screen click on the 'Selection texts' tab. You'll see the following:


6. Click on the 'Dictionary' check and press enter and automatically the word 'Material' is shown because you set the check to extract the text from 'Dictionary'. If you don't want to set that check, you have the freedom to type your own name. At the same time a message at the bottom will show the operation of getting the name from the dictionary.



7. Activate the text elements and then return to source code.

8. Activate the program and then run. Check the image.


Now the box has the name 'Parameters' and instead of 'SO_MATNR' we have the name 'Material' for the SELECT-OPTION.

9. In the same page execute the program or press 'F8' and check the results.

Finally, I want to write about the following code:

write / 'No data'(002).

How does this works? Well, actually that's also a text symbol, however what this means is that unless the text symbol '002' is defined then the program in this case will print 'No data'. If the text symbol '002' is defined then the program will the value of text-002.

This gives you the ability to have a default value in your program and a flexible way to work with different languages in SAP.

Well, that's it for now.

Hope it helps.
Please Share it! :)

2 comments :

  1. Informative article. You have done great explanation and visualization. Keep up the good work.
    BEST SAP ABAP TRAINING IN HYDERABAD

    ReplyDelete
  2. CAN YOU PLEASE USE RADIO BUTTONS ALSO ITS NOT WORKING USING RADIO BUTTONS.

    PLEASE SUGGEST I'M WAITING FOR YOUR REPLAY

    ReplyDelete