SAP Function Module - READ_TEXT - Sample Program.
READ_TEXT function module can be used to process text modules in application programs, all information about a text module must be transferred to internal work areas.
A text is read from the text file or text memory with this function module. It must be described fully by specifying OBJECT, NAME, ID, and LANGUAGE. Generic entries in these parameters are not valid.
When header information and text lines have been read successfully, they are transferred to the work areas HEADER and LINES.
Sample Program On READ_TEXT Using Subroutines:
DATA : gt_head TYPE TABLE OF thead,
gwa_head TYPE thead,
gt_tlines TYPE TABLE OF tline,
gwa_tlines TYPE tline.
PERFORM read_text USING 'VBBK' lv_vbeln '0001' lv_text.
************Sub Routine*****************
FORM read_text USING p_tdobject p_tdname p_tdid p_tdline.
DATA: lv_name TYPE thead-tdname.
lv_name = p_tdname.
REFRESH: gt_tlines.
CLEAR: gwa_tlines.
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = p_tdid
language = sy-langu
name = lv_name
object = p_tdobject
TABLES
lines = gt_tlines
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 <> 0.
READ TABLE gt_tlines INTO gwa_tlines INDEX 1.
p_tdline = gwa_tlines-tdline.
ENDIF.
lv_name = p_tdname.
REFRESH: gt_tlines.
CLEAR: gwa_tlines.
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = p_tdid
language = sy-langu
name = lv_name
object = p_tdobject
TABLES
lines = gt_tlines
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 <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.READ TABLE gt_tlines INTO gwa_tlines INDEX 1.
p_tdline = gwa_tlines-tdline.
ENDIF.
ENDFORM.