How To Use Function Module READ_TEXT

The function module \’READ_TEXT\’ allows us to read standard text.

For example, let say you want to use the FM \’READ_TEXT\’ to retrieve a specific text from a sales order.

Step 1:

The first thing to do is to find the appropriate parameters to pass to the FM to retrieve that specific text.

Thus, modify the sales order in VA02 and enter some text in the field you want to read the text.

Step 2:

Activate debugging mode (/h) and save the sales order. In debug, create a break point on the function module \’SAVE_TEXT\’.

\"\"

Step 3:

All parameters which we will needing to pass to the function module \’READ_TEXT\’ will be available in:

  • <HEADER>-TDOBJECT
  • <HEADER>-TDNAME
  • <HEADER>-TDID
  • <HEADER>-TDSPRAS

\"\"

Step 4:

Once the appropriate parameters have been found, pass them to the FM \’READ_TEXT\’ and read the required returning text.

Please find below a sample code.

REPORT ZREADTEXT.

*&--------------------------------------------------------------------&*
*& Program Description:                                               &*
*& -----------------------                                            &*
*& This demo program demonstrate how to use the function module       &*
*& \'READ_TEXT\' to find standard text.                                 &*
*&                                                                    &*
*& Author:  ABAPCOOKBOOK                                              &*
*& Website: www.abapcookbook.com                                      &*
************************************************************************

DATA:
  lv_output_text TYPE char50.

*Subroutine using the FM \'READ_TEXT\' to return
*the appropriate standard text.

*Please Note: To find the required parameters (for example a text in
*a Sales Order), in VA02, enter some text in the field in question,
*enable debugger(/h) and put a break point on the function module \'SAVE_TEXT\'.
*All appropriate parameters will be available in the field symbol \'<HEADER>\'.
PERFORM f_read_text USING \'ABCD\'            \" Text ID
                          \'E\'               \" Text Language
                          \'12345678\'        \" Text Name
                          \'VBBK\'            \" Text Object 
                 CHANGING lv_output_text.   \" Return Text

*Display the standard text.
WRITE lv_output_text.

*----------------------------------------------------------------------*
* Sub routine to read text from standard transactions using the        *
* function module \'READ_TEXT\'.                                         *
*----------------------------------------------------------------------*
FORM f_read_text USING pi_textid      TYPE thead-tdid
                       pi_language    TYPE thead-tdspras
                       pi_name        TYPE thead-tdname
                       pi_object      TYPE thead-tdobject
              CHANGING pc_output_text TYPE char50.
*----------------------------------------------------------------------*
* Local Data Declarations.
* Internal Tables.
  DATA:
    lt_lines TYPE STANDARD TABLE OF tline.

* Field Symbols.
  FIELD-SYMBOLS:
    <fs_lines> TYPE tline.

* Clearing field to be on the safer side.
  CLEAR pc_output_text.

  CALL FUNCTION \'READ_TEXT\'
    EXPORTING
      id                      = pi_textid
      language                = pi_language
      name                    = pi_name
      object                  = pi_object
    TABLES
      lines                   = lt_lines
    EXCEPTIONS
      id                      = 1
      language                = 2
      name                    = 3
      not_found               = 4
      object                  = 5
      reference_check         = 6
      wrong_access_to_archive = 7
      OTHERS                  = 8.

  IF sy-subrc EQ 0.

*   Getting the text from the FM table.
    READ TABLE lt_lines
    ASSIGNING <fs_lines>
    INDEX 1.

    IF sy-subrc EQ 0.

*     Standard text.
      pc_output_text = <fs_lines>-tdline.

    ENDIF.

  ENDIF.

ENDFORM.

Program Output:

\"\"

Easy! 🙂 Hope it helps.