Read Material Memo using READ_TEXT Function Module in ABAP
Call MD04 transaction code and run the program for a specific material code, MRP area and plant. You will see Material Memo button that will enable SAP users to define text for this material. Material text can be displayed as menu options "Goto > Material Memo (Shift+F4)"
Material text defined could be fetched using ABAP function module READ_TEXT as shown in this ABAP tutorial.
To read material memo, read_text ABAP function module accepts following parameter values:
Id is 'LTXT,
Object is 'MDTXT',
Name parameter value can be formed of material number and plant with a space character between them. (MATNR + SPACE + WERKS)
Here is the ABAP code that can be used to form name parameter value of read_text function module
CONCATENATE lv_matnr space lv_werks INTO lv_tdname RESPECTING BLANKS.
Since I want to read material memo in login language of the SAP user at first, if it does not exist I prefer the material text in English. If I fail to find a text again, I'll use the German language for READ_TEXT function module.
Here is the function module, I used.
DATA lt_textlines TYPE tline_t.
DATA lv_tdname LIKE thead-tdname.
DATA lv_matnr TYPE matnr.
DATA lv_werks TYPE werks_d.
lv_matnr = 'MATERIAL001'.
lv_werks = '1234'.
CONCATENATE lv_matnr space lv_werks INTO lv_tdname RESPECTING BLANKS.
CALL FUNCTION 'Z_READ_MATERIAL_MEMO'
EXPORTING
i_language = sy-langu
i_name = lv_tdname
IMPORTING
et_text = lt_textlines.
Z_READ_MATERIAL_MEMO function module ABAP source code is as follows:
CONSTANTS:
c_eng LIKE sy-langu VALUE 'E',
c_ger LIKE sy-langu VALUE 'D',
c_tdid LIKE thead-tdid VALUE 'LTXT',
c_tdobj LIKE thead-tdobject VALUE 'MDTXT'.
DATA lt_textlines TYPE tline_t.
DATA lv_tdname LIKE thead-tdname.
lv_tdname = i_name.
REFRESH lt_textlines.
CALL FUNCTION 'Z_READ_MATERIAL_MEMO_LANG'
EXPORTING
i_id = c_tdid
i_language = sy-langu
i_name = lv_tdname
i_object = c_tdobj
IMPORTING
et_text = et_text.
IF et_text IS INITIAL.
IF sy-langu <> c_eng.
CALL FUNCTION 'Z_READ_MATERIAL_MEMO_LANG'
EXPORTING
i_id = c_tdid
i_language = c_eng
i_name = lv_tdname
i_object = c_tdobj
IMPORTING
et_text = et_text.
ENDIF.
IF et_text IS INITIAL.
IF sy-langu <> c_ger.
CALL FUNCTION 'Z_READ_MATERIAL_MEMO_LANG'
EXPORTING
i_id = c_tdid
i_language = c_ger
i_name = lv_tdname
i_object = c_tdobj
IMPORTING
et_text = et_text.
ENDIF.
ENDIF.
ENDIF.
And the ABAP code of function module Z_READ_MATERIAL_MEMO_LANG is simple only calling READ_TEXT fm.
data lt_lines type tline_t.
call function 'READ_TEXT'
exporting
client = sy-mandt
id = i_id
language = i_language
name = i_name
object = i_object
archive_handle = 0
* IMPORTING
* HEADER =
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 = 0.
if lt_lines is not initial.
et_text[] = lt_lines[].
endif.
endif.
This sample ABAP code can be used to create function modules that can help SAP programmers to read material memo programmatically.