Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

USEREXIT_SAVE_DOCUMENT - Text saving is now working

Raxph
Participant
0 Kudos
878

Hi together,

I am trying to save a text in the user exit: USEREXIT_SAVE_DOCUMENT. The requirement is after saving an order, a text should be automatically filled in the text part of the order. Now I am having the issue that with save text, the text is not being saved. The text ID, Object and Name are all correct. Does anyone know, why the text is not being saved or can I do it into another user exit? The standard transaction that I am using is VA41.

 CALL FUNCTION 'SAVE_TEXT'
EXPORTING
* CLIENT = SY-MANDT
header = ls_header
insert = 'X'
* SAVEMODE_DIRECT = ' '
* OWNER_SPECIFIED = ' '
* LOCAL_CAT = ' '
* KEEP_LAST_CHANGED = ' '
* IMPORTING
* FUNCTION =
* NEWHEADER =
TABLES
lines = lt_tline
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

Thank you,

R

11 REPLIES 11

DominikTylczyn
Active Contributor
749

Try with SAVEMODE_DIRECT = 'X'

Raxph
Participant
0 Kudos
749

Hi @3a9e4ce873a94034b33dc62b0ce600ee, I thought about that, but if I am not wrong, we are not allowed to do savemode_direct = 'X' or commit work in a user exit, as it may lead to data inconsistency.

DominikTylczyn
Active Contributor
0 Kudos
749

Hi tk_gerald You are right about COMMIT WORK in the user exit. However I don't see SAVE_TEXT executing COMMIT WORK with SAVEMODE_DIRECT = X

DominikTylczyn
Active Contributor
749

Hi tk_gerald If you don't want ot use SAVEMODE_DIRECT = X, call COMMIT_TEXT after SAVE_TEXT. Despite the name COMMIT_TEXT doesn't issue COMMIT WORK. You can test that with test sequences in SE37. This sequence doesn't really persists text changes:

  1. SAVE_TEXT without SAVEMODE_DIRECT = X
  2. COMMIT_TEXT

However this one does:

  1. SAVE_TEXT without SAVEMODE_DIRECT = X
  2. COMMIT_TEXT
  3. BAPI_TRANSACTION_COMMIT

raymond_giuseppi
Active Contributor
0 Kudos
749

As a rule don't use in SD the USEREXIT_SAVE_DOCUMENT for this kind of purpose, it's too late for the current document. Use USEREXIT_SAVE_DOCUMENT_PREPARE.

0 Kudos
749

Hi @raymond.giuseppi, the issue with USEREXIT_SAVE_DOCUMENT_PREPARE, is that I need the vbeln for the tdname of the text. Thus I cannot use this userexit, as on the prepare user exit, the vbeln number is not yet created.

0 Kudos
749

Debug the transaction in the PREPARE form, look for the in memory text catalog to replicate the way SAP store long text before SAVE (Look at a FM such as GET_TEXT_MEMORY or MEMORY ID 'SAPLSTXD')

Look also at content of table XTHEAD in the exit.

0 Kudos
749

I don't agree. I think that USEREXIT_SAVE_DOCUMENT is the right spot to save additional texts, as we have fully prepared sales order there and the use-exit is called just before COMMIT WORK.

DominikTylczyn
Active Contributor
749

Hi tk_gerald One more comment SAVEMODE_DIRECT = X persists texts with EXPORT TO DATABASE, class CL_RSTX_TABLE_VIEW, method CHANGE_ALL:

              export tline from i_text_lines
                  to database stxl(tx)  "#EC DBACCESS_OK
                     client   l_stxh-mandt
                     id       l_stxl_id.

As per SAP documentation to EXPORT TO DATABASE

If DATABASE is specified, the data cluster with the ID id is stored in the database table dbtab and committed by the next database commit.

EXPORT TO DATABASE doesn't execute commit by itself. So it should be save to use SAVEMODE_DIRECT = X in the user-exit.

raymond_giuseppi
Active Contributor
749

Also could you replace the NOW with NOT, as

Raxph
Participant
749

Hi @3a9e4ce873a94034b33dc62b0ce600ee, thanks for your help, yes, I used the commit_text 🙂