ABAP code for saving Long Text in BDC
Posted by Admin, under ABAP, BDC / LSMW, Function Modules, Quick Reference, Sample CodeThere has been requirements for recording BDC for screens involving Long Text (Free field for text entry). The part that is a bit tricky is, the TextEdit control (Long Text field) does not gets recorded in the BDC.
The following function module is used to save the data with respect to the screen (say, Sales Order Number in case recording ‘Description’ and ‘Created By’ using VA01).

Steps:
1. Create an internal table of type TLINE and structure of type THEAD.
DATA: lines TYPE tline occurs 0 with header line,
header TYPE thead.
2. Fill the data in the internal table.
NOTE: TO get tdobject, tdname, tdid, tdspras; double click in TextArea and the select GOTO- > HEADER.

header-tdobject = 'VBBK'.
header-tdname = 'XXXXXXXXXX'.
header-tdid = 'ZM01'.
header-tdspras = 'EN'.
header-tdlinesize = '072'.
*--- Calling the function and getting the retrieved data
*--- to be dispalyed
call function 'EDIT_TEXT'
exporting
* DISPLAY = ' '
* EDITOR_TITLE = ' '
header = header
* PAGE = ' '
* WINDOW = ' '
save = ''
* LINE_EDITOR = ' '
* CONTROL = ' '
* PROGRAM = ' '
* LOCAL_CAT = ' '
* IMPORTING
* FUNCTION =
* NEWHEADER =
* RESULT =
tables
lines = lines
* EXCEPTIONS
* ID = 1
* LANGUAGE = 2
* LINESIZE = 3
* NAME = 4
* OBJECT = 5
* TEXTFORMAT = 6
* COMMUNICATION = 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.
endif.
3. Now, at the time of saving, Save the data into Database with reference to Sales Document Number(v_vbeln). Note: this code should be written after the Sales Document is saved.
if lines[] is NOT INITIAL.
header-tdobject = 'VBBK'.
header-tdname = v_vbeln.
header-tdid = 'ZM01'.
header-tdspras = 'EN'.
header-tdlinesize = '072'.
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
* CLIENT = SY-MANDT
HEADER = header
INSERT = 'V'
SAVEMODE_DIRECT = 'X'
* OWNER_SPECIFIED = ' '
* LOCAL_CAT = ' '
* IMPORTING
* FUNCTION =
* NEWHEADER =
TABLES
LINES = lines
* 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.
ENDIF.
endif.
You might also be interested in these posts:

Post a Comment