ABAP Long Text

Aditya Aufar
2 min readFeb 5, 2022

--

There are times that you need to store a lot of text with huge number of characters. Sometimes defining it in a custom field and custom domain is not the solution. This is where the Text Table comes in handy. You can use this Table to store your text and “connect” it to another table using some sort of key. This key can be just the combination of multiple field value from another table. Here are the steps to create it:

Configurational Step

  1. Go to Transaction Code SE75: Text Objects and IDs -> Change -> Create New
  2. Fill the field like so, then continue:
    Editor Application = TX
    Line Width = 132
    Text Object = (Anything up to 10 digit characters)
    Save Mode = Update
  3. Double Click on the newly added Text Object -> Create New
  4. Fill the field like so, then Continue:
    Text ID = (Anything up to 4 characters)
    Display in title = (Checked)
  5. Save it

Storing The Text

DATA header_param       TYPE thead.
TYPES longtext_type TYPE TABLE OF tline WITH EMPTY KEY.

CONSTANTS key TYPE tdobname VALUE `abc123`.
CONSTANTS text_object TYPE tdobject VALUE `ZOBJECT`. "Text Object as configured in step 2 above
CONSTANTS text_id TYPE tdid VALUE `ZID`. "Text ID as configured in step 4 above


header_param = VALUE #( tdname = key
tdobject = text_object
tdid = text_id
tdspras = sy-langu ).

DATA(longtexts) = VALUE longtext_type( ( tdformat = '/' tdline = 'This is the first line' )
( tdformat = '/' tdline = 'This is still the first line' )
( tdformat = '*' tdline = 'This will be on the next line' ) ).


CALL FUNCTION 'SAVE_TEXT'
EXPORTING
header = header_param
savemode_direct = 'X'
TABLES
lines = longtexts "The Text
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
WRITE:/ 'Successfully stored'.
ENDIF.

Retrieving The Text

DATA header_param       TYPE thead.
DATA longtexts TYPE STANDARD TABLE OF tline.

CONSTANTS key TYPE tdobname VALUE `abc123`. "This just an example of key
CONSTANTS text_object TYPE tdobject VALUE `ZOBJECT`. "Text Object as configured in step 2 above
CONSTANTS text_id TYPE tdid VALUE `ZID`. "Text ID as configured in step 4 above



CALL FUNCTION 'READ_TEXT'
EXPORTING
id = text_id
language = sy-langu
name = key
object = text_object
TABLES
lines = longtexts "The Text Retrieved
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.
"Proceed with text data from internal table longtext
ENDIF.

I hope you find this useful in any way.

--

--