08-09-2010 11:36 AM
Dear Experts,
I want to send a Mail with some details whenever we Create & Save a new Process Order in COR1.
I have written my code at the below location where i have all the required data stored in the IT'S.
Enhancement - PPCO0001
FM - EXIT_SAPLCOBT_001
Include - zxco1u01
I have the below code to send the Mail in the include.
Send the document
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = wa_doc_chng
put_in_outbox = 'X'
commit_work = ""
tables
packing_list = it_objpack
contents_txt = it_objtxt
receivers = it_reclist
exceptions
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8.
if sy-subrc = 0.
To refresh SAP Work Office so that mail can be recieved immediataly.
submit rsconn01 with mode = 'INT'
with output = ''
and return.
else.
message 'Problem in sending Email.' type 'I'.
endif. " End of sy-subrc
Here my exporting parameter "commit_work" is blank, i have not passed "X" in it.
When i pass "X" in this, it gives me a dump as below.
Short text
Invalid COMMIT WORK in a COMMIT WORK or ROLLBACK WORK.
What happened?
Error in the ABAP Application Program
The current ABAP program "SAPLSOI1" had to be terminated because it has
come across a statement that unfortunately cannot be executed.
Error analysis
The call of a COMMIT WORK in a FORM, that will not be executed until
the commit or rollback point of the caller using the variant
PERFORM ... ON COMMIT or PERFORM ... ON ROLLBACK is not permitted.
Trigger Location of Runtime Error
Program SAPLSOI1
Include LSOI1U32
Row 154
Module type (FUNCTION)
Module Name SO_DOCUMENT_SEND_API1
When i take out "X" from "commit_work", it does not send mail and also the transaction does not give any Dump.
Can you please help out me with this?
Thanks,
Praveen
08-09-2010 11:47 AM
Hi Praveen,
In user exit you should not use commit work statement .It is rule. You can put the code in a function and call the function module in update mode.
Thanks
Kamath
08-09-2010 12:36 PM
Hi ,
I have tried the Same Code at the below location and it does work fine.
FM - EXIT_SAPLCOZV_001
Include - ZXCO1U06
It works perfect.
Can you please let me know what is the difference between these two?
Thanks,
Praveen
08-09-2010 1:25 PM
Hello Praveen,
As you may be aware, in order to avoid data inconsistency SAP is using bundling techniques and lock mechanisms . PERFORM..... ON COMMIT, and CALL FM... IN UPDATE TASK etc are the bundling techniques that SAP is normally using.
Now during customer exit, what we are doing is we are just introducing a new piece of code or some more logic to change some value, or will do some validation etc.....SAP itself will have a bundling technique here, like a lot perform on commit statements are already bundled but not yet committed, or a lot of IN UPDATE TASK FMs are logged into table VBLOG , waiting for a COMMIT statement.
Now in your code what you had done is you just implicitly called a commit statement,which may be before actual intended COMMIT statement, coz you are totally disturbing SAP logic of database update. Thats why SAP is giving dump, the dump analysys is also saying the same.
You can use your send mail function in this exit itself without COMMIT statement , once the transaction COMMIT happen, this will send mail.
Now why it is not giving dump in another exit: SAP code is just checking whether it cause any inconsistency due to this commit statement, if it is not, then program will flow with out any problem.
Thanks and Regards,
Antony Thomas
Edited by: Antony Thomas on Aug 9, 2010 8:25 AM
08-09-2010 1:47 PM
Hi Antony,
When i write the below code in FM = EXIT_SAPLCOBT_001 and include = zxco1u01, it does not work for sending the mail.
Mail Data.
types: begin of ty_mail,
tcode type zmail-tcode,
email type zmail-email,
end of ty_mail.
*
IT Creation.
data: it_mail type standard table of ty_mail.
*
WA Creation.
data: wa_mail type ty_mail.
*
Email Related Internal Tables.
data: it_reclist type standard table of somlreci1, "Recipients
it_objpack type standard table of sopcklsti1,
it_objhead type standard table of solisti1,
it_objtxt type standard table of solisti1 initial size 0 with header line, "Body of EMail
it_objbin type standard table of solisti1, "Attachment of EMail
it_contents_hex like standard table of solix,
it_objbin1 type standard table of solisti1, "Attachment of EMail
it_contents_hex1 like standard table of solix.
*
Email Related Work Area.
data: wa_doc_chng type sodocchgi1. "attributes of document to send
*
data: l_reclist like line of it_reclist,
l_objpack like line of it_objpack,
l_tab_lines type i.
*
data: lv_answer type string,
w_msg1(100) type c,
w_gamng type string.
*
select tcode email from zmail into table it_mail
where tcode = 'ZQA15'.
*
refresh it_objtxt[].
*
it_objtxt = '-----------------------------------------------------------------------------------------------------'.
append it_objtxt.
*
concatenate 'Order Number - ' header_table-aufnr into it_objtxt separated by space.
append it_objtxt.
*
concatenate 'Plant - ' header_table-werks into it_objtxt separated by space.
append it_objtxt.
*
concatenate 'Material No. - ' position_table-matnr into it_objtxt separated by space.
append it_objtxt.
*
concatenate 'Material Description - ' header_table-ktext into it_objtxt separated by space.
append it_objtxt.
*
concatenate 'Batch No. - ' position_table-charg into it_objtxt separated by space.
append it_objtxt.
*
w_gamng = header_table-gamng.
concatenate 'Batch Size - ' w_gamng into it_objtxt separated by space.
append it_objtxt.
*
concatenate 'MFG. Date - ' position_table-verid into it_objtxt separated by space.
refresh it_reclist[].
*
loop at it_mail into wa_mail.
clear l_reclist.
*
l_reclist-receiver = wa_mail-email.
l_reclist-express = 'X'.
l_reclist-rec_type = 'U'.
l_reclist-no_forward = 'X'.
*
append l_reclist to it_reclist.
clear wa_mail.
endloop.
*
Fill the document data.
*
wa_doc_chng-doc_size = 1.
*
Populate the subject/generic message attributes
*
wa_doc_chng-obj_langu = sy-langu.
wa_doc_chng-obj_name = 'PO DETAILS'.
*
wa_doc_chng-obj_descr = 'PO Details To QC'.
*
wa_doc_chng-sensitivty = 'F'. " Send mail as a confidential
wa_doc_chng-no_change = 'X'.
*
*
Describe the body of the message
if it_objpack is initial.
l_objpack-transf_bin = space.
l_objpack-head_start = 1.
l_objpack-head_num = 1.
l_objpack-body_start = 1.
*
describe table it_objtxt lines l_objpack-body_num.
*
l_objpack-doc_type = 'RAW'.
*
append l_objpack to it_objpack.
clear l_objpack.
clear l_tab_lines.
endif.
*
Send the document
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = wa_doc_chng
put_in_outbox = 'X'
commit_work = ''
tables
packing_list = it_objpack
contents_txt = it_objtxt
receivers = it_reclist
exceptions
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8.
*
if sy-subrc = 0.
*
To refresh SAP Work Office so that mail can be recieved immediataly.
submit rsconn01 with mode = 'INT'
with output = ''
and return.
*
else.
message 'Problem in sending Email.' type 'I'.
endif. " End of sy-subrc
*
endif. " End of lw_answer
But when i write the same above code in FM = EXIT_SAPLCOZV_001 and include = zxco1u06, it does work fine.
I am not able to understand why it works at one place and does not at the other?
Thanks,
Praveen
08-09-2010 1:55 PM
Hi Parveen,
As I mentioned in previous thread, first exit may be calling in midst of a transaction, where an implicit commit will create inconsistency, so SAP wont allow you to proceed further.
In the case secod exit, where you are successfull coz, an implicit commit wont create any problem here.so it allows you to proceed further.
If you need more insight into this area, probably you can go through documents regarding database updates, LUWs, lock mechanisms etc...
Regards,
Antony Thomas
08-10-2010 10:36 AM
Dear Gurus,
I solved this problem at my end.
Thanks at a lot for all the help on this.
Thanks,
Praveen
10-11-2011 9:10 PM
Hi Praveen,
I am using 'SO_NEW_DOCUMENT_ATT_SEND_API1' in user exit EXIT_SAPFP50M_002 include zxpadu02. I am calling a smartform
converting to PDF and sending as attachment.
For me it generates entry in table SOST and the mail stays in the SAP outbox with the status 'waiting for communication'.
I tried to run RSCONN01 my self. it doesnt send the email. Other thing i see is even though it adds record to SOST table, but does not show the email in scot as pending. If I send email from a Z program this works fine.
I tried with and without commit both.
Please let me know how did you resolve your issue.
Surinder Pal Singh