‎2011 Jul 28 2:39 PM
Hi SAP gurus,
I'm having a problem.
I need to create / change an order VA01/VA02 and change the header/position texts in the mean time.
After allot of debugging and messing around, I've come to the conclusion that I can't SAVE the text. Here is a part of the code positioned in "MV45AFZZ" / "FORM USEREXIT_SAVE_DOCUMENT_PREPARE"
CONCATENATE sy-uname sy-tcode INTO lv_export_id.
IMPORT lt_all_msgs FROM MEMORY ID lv_export_id.
IF lt_all_msgs[] IS INITIAL.
IMPORT t1 TO lt_all_msgs FROM MEMORY ID lv_export_id.
ENDIF.
LOOP AT lt_all_msgs INTO ls_all_msgs.
lv_tabix = sy-tabix.
IF ls_all_msgs-tdline+0(3) <> 'VA0'.
APPEND ls_all_msgs TO lt_text_lines.
ENDIF.
ADD 1 TO lv_tabix.
READ TABLE lt_all_msgs INDEX lv_tabix TRANSPORTING NO FIELDS.
IF ls_all_msgs_old IS NOT INITIAL AND ( ls_all_msgs-tdline+0(3) = 'VA0' OR sy-subrc IS NOT INITIAL ).
SPLIT ls_all_msgs_old-tdline AT ';' INTO ls_data-trx ls_data-posnr ls_data-lines.
ls_head_text-tdobject = 'VBBP'.
CONCATENATE vbak-vbeln ls_data-posnr INTO ls_head_text-tdname.
ls_head_text-tdid = 'ZP17'.
ls_head_text-tdspras = '4'.
ls_head_text-tdform = 'SYSTEM'.
ls_head_text-tdversion = '00001'.
ls_head_text-tdfuser = sy-uname.
ls_head_text-tdfreles = '701'.
ls_head_text-tdfdate = sy-datum.
ls_head_text-tdftime = sy-uzeit.
ls_head_text-tdluser = sy-uname.
ls_head_text-tdlreles = sy-saprl.
ls_head_text-tdldate = sy-datum.
ls_head_text-tdltime = sy-uzeit.
ls_head_text-tdlinesize = '120'.
ls_head_text-tdtxtlines = ls_data-lines.
ls_head_text-tdtranstat = '0'.
ls_head_text-tdmacode1 = 'VA02SAPMV45A'.
ls_head_text-mandt = '200'.
CALL FUNCTION 'EDIT_TEXT_INLINE'
EXPORTING
header = ls_head_text
inline_count = '0'
save = 'X'
IMPORTING
newheader = ls_head_textn
TABLES
inlines = lt_inlines
lines = lt_text_lines.
IF ls_data-trx = 'VA01'.
ls_head_text = ls_head_textn.
ENDIF.
* *
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
client = sy-mandt
header = ls_head_text
insert = ''
savemode_direct = 'X'
owner_specified = 'X'
IMPORTING
function = lv_function
TABLES
lines = lt_text_lines
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5.
CALL FUNCTION 'COMMIT_TEXT'
EXPORTING
object = 'VBBP'
savemode_direct = 'X'
IMPORTING
commit_count = count.
CLEAR lt_text_lines.
ENDIF.
IF ls_all_msgs-tdline+0(3) = 'VA0'.
ls_all_msgs_old = ls_all_msgs.
ENDIF.
ENDLOOP.
ENDIF.
I can't seam to find a place where to put this code (which in other cases works just "perfect", executed in a program or whatever) because the COMMIT_TEXT, COMMIT, SAVE_TEXT functions do not work.
The limitations I have are:
vbak-vbeln HAS to be not initial (I use the same code for VA01 and for VA02), ergo ... I need the document number
and
IMPORT FROM MEMORY statement doesn't work if I move it, for example in "FORM USEREXIT_SAVE_DOCUMENT.".
I actually need some solutions and not guesses or "thinks" ...
Thank you allot in advance,
Marius
PS: Places in which this code has been ...
/BEV1/CL_IM_SR_SALES_ORD_1
/BEV1/CL_IM_TS_SD_SALES
/DSD/CL_IM_SL_BADI_SD_SALE
/SAPTRX/CL_IM_SD_SALESORD
CL_IM_CMPD_BADI_SD_SALES
CL_IM_CMP_BADI_SD_SALES
CL_IM_FOAP_BADI_SD_SALES
CL_IM_IMP_EHS_SVT_CHECK
CL_IM_IM_CORE_CHECK
CL_EX_BADI_SD_SALES
or enhancements all over the SAPMV45A. If the save_text works .... the IMPORT doesn't work (I receive the sy-subrc = 0 value but the memory isn't read )
‎2011 Jul 28 2:49 PM
can you write commit work and wait?
i know that commit_text needs to be used to save it. just try with an extra statement.
i experienced the similar kind of issue, i resolved it by using commit work and wait statememt
‎2011 Jul 28 2:50 PM
Just add the "commit work and wait" at the end ?
PS: Nope .. that ain't it :(. I added the commit work, commit work and wait .... nothing ... the text isn't there in the new order (I'm testing still with VA01)
‎2011 Jul 28 3:23 PM
Do NOT put a COMMIT WORK in user_exit_save_document_prepare!! WRONG advice. We don't ever put commit work in these exits, since you would flush the update queue to the database tables before SAP is ready to do so.
‎2011 Jul 28 3:25 PM
‎2011 Jul 28 3:44 PM
‎2011 Jul 28 3:45 PM
‎2011 Jul 28 3:49 PM
Okay... have you tried just a function module that would put the text into the tables? If that works, then calling that FM in update task in USER_EXIT_SAVE_DOCUMENT will do that same thing. That's all that exit is for, e.g., firing off additional processes.
When you say it doesn't work, it take it that means that after you do this, you don't find the entry in table STXH with the id, object, name, langu you specified?
And, sorry for the obvious question, but I don't see a check to see if the import from memory was successful and if what was imported contains any rows/data? You are certain that after import you have data?
‎2011 Jul 28 4:00 PM
Also
Try to check the abap code of fm CREATE_TEXT (it's called in fm SD_SALES_DOCU_MAINTAIN): here the fm COMMIT_TEXT is called, but the text name is also transfered, not only object type.
Max
‎2011 Jul 28 4:05 PM
Yes Dave, that's true. I don't find my ID, OBJECT, LANGU etc in the table, nor in the document at the given position.
And YES I'm 100% sure that the IMPORT is successful. If I remove the "IN UPDATE TASK" statement, the debug shows me the lines in the text table.
I've found a work around ... if you guys can advise about it:
SELECT SINGLE * FROM TVAK WHERE AUART = US_AUART. "the sales document type
data: da_rc like inri-returncode.
call function 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = TVAK-NUMKI
object = 'RV_BELEG'
IMPORTING
returncode = da_rc
number = vbak-vbeln.
and I get the document number ... a bit in advance than the standard SAP program does. Ergo, I can use it where the standard SAP program allows me to use the current programming.
‎2011 Jul 28 4:14 PM
In the form USER_EXIT_SAVE_DOCUMENT you know the number of sales order,
This exit is just to save some data in own custom table, so you don't need to use that code,
Max
‎2011 Jul 28 4:19 PM
In that form, the SAVE_TEXT doesn't work. BUT it works in another place ... Class "/BEV1/CL_IM_SR_SALES_ORD_1" methid "IF_EX_BADI_SD_SALES~SAVE_DOCUMENT_PREPARE" where the "EXPORT" is 😛
‎2011 Jul 28 4:32 PM
That is very strange
I don't know that BADI (I suppose it's a standard one) but that method is called just before or after the form USEREXIT_SAVE_DOCUMENT_PREPARE, so here you don't know the number and you can use the code to get the number because the sales order number will be go twice:
- The first time by you
- The second time by the standard
The result will be you'll have a different number, not one will be assigned to document.
Max
‎2011 Jul 28 4:35 PM
Yeah ... saw the number thingy. In debug worked like a charm .... have to study some more the solution
‎2011 Jul 28 4:40 PM
It's complicated .... if I run the FM ... the text isn't saved ... if I input manually, instead of the FM for the next document, the text is saved ...
‎2011 Jul 28 4:43 PM
Hi
After getting the number the standard program call the fm SD_COMMIT_TEXT, try to check the code of this fm:
Include MV45AF0B_BELEG_SICHERN:
* Texte sichern
append vbak-vbeln to da_text_vbeln.
call function 'SD_COMMIT_TEXT'
exporting
fi_caller = gc_text_appl_id-sales_document
fit_vbeln = da_text_vbeln[]
fi_keep = 'X'
exceptions
others = 1.
Max
‎2011 Jul 28 2:54 PM
Hi
Try to place your code in a your own fm placed in form USEREXIT_SAVE_DOCUMENT, here you should know the order number.
Your fm should be called in UPDATE TASK
Max
‎2011 Jul 28 3:22 PM