04-13-2012 12:12 PM
Hi All,
Once we create a sales order for any order no. using VA01,
after completion of creating sales order when clicked on save, an email notification about that order creation mail has to be send to customer.....
Is there any event that can send a mail.... that should not be any hard coding after creation....
Plz provide with code...
Thanks in advance.........
Sapient
04-16-2012 6:37 AM
Hi please go through the below code in form FORM USEREXIT_SAVE_DOCUMENT by doing implicit enhancements
data : LV_EMP_EMAILID type PA0105-USRID_LONG
DATA:it_receivers TYPE STANDARD TABLE OF somlreci1,
wa_it_receivers LIKE LINE OF it_receivers,
it_packing_list TYPE STANDARD TABLE OF sopcklsti1,
gd_doc_data TYPE sodocchgi1,
wa_it_packing_list LIKE LINE OF it_packing_list,
psubject(90) TYPE c,
it_message TYPE STANDARD TABLE OF solisti1,
wa_it_message LIKE LINE OF it_message,
c1(99) TYPE c,
c2(15) TYPE c,
num_lines TYPE i.
****** Assign the Email id and User id to Whom you want to Send ******&
FREE wa_it_receivers.
wa_it_receivers-receiver = lv_emp_emailid. "'abc@gmail.com'."lv_emp_emailid. "&---- Assign Email id
wa_it_receivers-rec_type = 'U'. "&---- Send to External Email id
wa_it_receivers-com_type = 'INT'.
wa_it_receivers-notif_del = 'X'.
wa_it_receivers-notif_ndel = 'X'.
APPEND wa_it_receivers TO it_receivers .
* FREE wa_it_receivers.
* wa_it_receivers-receiver = lv_emp_userid. "&----- Assign SAP User Id
* wa_it_receivers-rec_type = 'B'. "&-- Send to SAP Inbox
* wa_it_receivers-com_type = 'INT'.
* wa_it_receivers-notif_del = 'X'.
* wa_it_receivers-notif_ndel = 'X'.
* APPEND wa_it_receivers TO it_receivers .
*& - END of Assign the Email id and User id to Whom you want to Send --&
"&--- Read the Number of lines in the Internal Table
DESCRIBE TABLE it_receivers LINES num_lines.
"&--- Check the Sender Email id or SAP User id is got or not.
IF num_lines IS NOT INITIAL.
*&---------------------------------------------------------------------
* Add thetext to mail text table
*&----------------------------------------------------------------------
*&-- Subject of the mail -------------&*
psubject = 'Daily Activity'(001).
*&-- Body of the mail ----------------&*
CLEAR wa_it_message.
c1 = 'Dear Sir'(005).
*c2 = lv_emp_userid.
CONCATENATE c1 c2 ',' INTO
wa_it_message-line SEPARATED BY space.
APPEND wa_it_message TO it_message.
*** insert Blank Line *********************************************
CLEAR wa_it_message.
wa_it_message-line = ' '.
APPEND wa_it_message TO it_message.
******* Assign your Text below *************************************
CLEAR wa_it_message.
wa_it_message-line = 'A Timesheet sent from '."(002).
CONCATENATE wa_it_message-line ' ' LV_EMP_USERID into wa_it_message-line.
APPEND wa_it_message TO it_message.
*** insert Blank Line{} *********************************************
CLEAR wa_it_message.
wa_it_message-line = ' '.
APPEND wa_it_message TO it_message.
**********Assign your Text below ********************************
CLEAR wa_it_message.
wa_it_message-line = 'This mail generate automatically. Please do not reply.'(003).
APPEND wa_it_message TO it_message.
*********************************************************************
**********& Send EMAIL MESSAGE &*********************************
gd_doc_data-doc_size = 1.
*Populate the subject/generic message attributes
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
*Describe the body of the message
CLEAR wa_it_packing_list.
REFRESH it_packing_list.
wa_it_packing_list-transf_bin = space.
wa_it_packing_list-head_start = 1.
wa_it_packing_list-head_num = 0.
wa_it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES wa_it_packing_list-body_num.
wa_it_packing_list-doc_type = 'RAW'.
APPEND wa_it_packing_list TO it_packing_list.
*&------ Call the Function Module to send the message to External and SAP Inbox
*CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
* EXPORTING
* document_data = gd_doc_data
* put_in_outbox = 'X'
* commit_work = 'X'
* TABLES
* packing_list = it_packing_list
* contents_txt = it_message
* receivers = it_receivers
* 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.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*ENDIF.
*ENDIF. "&---- END of Check the Sender Email id or SAP User id is got or not.
"data sent(1) type c."PA0105-USRID_LONG value 'abc@gmail.com'.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = gd_doc_data
PUT_IN_OUTBOX = 'X'
SENDER_ADDRESS = 'abc@erpanderp.com' (Sender address)
SENDER_ADDRESS_TYPE = 'INT'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = sent
* NEW_OBJECT_ID =
* SENDER_ID = sent
TABLES
PACKING_LIST = it_packing_list
* OBJECT_HEADER =
* CONTENTS_BIN =
CONTENTS_TXT = it_message
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = it_receivers
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.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
IF SY-SUBRC = 0.
SUBMIT RSCONN01 WITH MODE = 'INT' WITH OUTPUT = 'X' AND RETURN.
ENDIF.
endif.
04-13-2012 12:25 PM
Check with functional folks if there is any configuration which can trigger email notification to the customer on save of sales order otherwise you can use MV45AFZZ --> FORM USEREXIT_SAVE_DOCUMENT to include email functionality.
04-16-2012 5:50 AM
Hello,
I am unable to look MV45AFZZ --> FORM USEREXIT_SAVE_DOCUMENT this part,
plz can you explore how to find this...?
Thanks,
04-13-2012 12:40 PM
SAP provide templates for an order confirmation document in SAPscript or other formats - this output can be emailed - see Output Control in the Sales and Distribution area of Configuration as well as printed. This is more of a SAP standard solution, though your company will want to revise the layout of the document so there will be some work for a forms developer.
04-13-2012 12:52 PM
Hi ,
In Include MV45AFZZ --> FORM USEREXIT_SAVE_DOCUMENT .In that we need to implement customized code . If you want the code i can provide for you.
We need to implement code using implicit enhancements
04-16-2012 5:59 AM
Hello Aditya,
Can you plz explore more abt the routine USEREXIT_SAVE_DOCUMENT, & plz even send the code of this....
Thanks & Regards,
04-13-2012 2:22 PM
As John already noted, Order Confirmation is an output from SD, and is configurable. The form can be adjusted using 'Z' customer version, and that can be assigned in your configuration. Output determination and form output control should result in email to the stored SMTP address for your sold-to customer, with a small amount of configuration and possibly a it of modification to the SAP standard order confirmation output.
One would NOT put code in userexit_save_document as "implicit enhancement", since that user exit is there for the customer's code and is always active and does not require use of implicit enhancement. One could, if absolutely essential, fire off a separate process from this exit, supplying the order no., etc., but one would need to evaluate the transaction code before making the decision to fire off another process.
04-13-2012 5:53 PM
Hi,
You mean need to send a mail to customer regarding order.if that is the requirement then you can do from stndard itself.
Regards,
Madhu.
04-13-2012 10:52 PM
04-16-2012 6:37 AM
Hi please go through the below code in form FORM USEREXIT_SAVE_DOCUMENT by doing implicit enhancements
data : LV_EMP_EMAILID type PA0105-USRID_LONG
DATA:it_receivers TYPE STANDARD TABLE OF somlreci1,
wa_it_receivers LIKE LINE OF it_receivers,
it_packing_list TYPE STANDARD TABLE OF sopcklsti1,
gd_doc_data TYPE sodocchgi1,
wa_it_packing_list LIKE LINE OF it_packing_list,
psubject(90) TYPE c,
it_message TYPE STANDARD TABLE OF solisti1,
wa_it_message LIKE LINE OF it_message,
c1(99) TYPE c,
c2(15) TYPE c,
num_lines TYPE i.
****** Assign the Email id and User id to Whom you want to Send ******&
FREE wa_it_receivers.
wa_it_receivers-receiver = lv_emp_emailid. "'abc@gmail.com'."lv_emp_emailid. "&---- Assign Email id
wa_it_receivers-rec_type = 'U'. "&---- Send to External Email id
wa_it_receivers-com_type = 'INT'.
wa_it_receivers-notif_del = 'X'.
wa_it_receivers-notif_ndel = 'X'.
APPEND wa_it_receivers TO it_receivers .
* FREE wa_it_receivers.
* wa_it_receivers-receiver = lv_emp_userid. "&----- Assign SAP User Id
* wa_it_receivers-rec_type = 'B'. "&-- Send to SAP Inbox
* wa_it_receivers-com_type = 'INT'.
* wa_it_receivers-notif_del = 'X'.
* wa_it_receivers-notif_ndel = 'X'.
* APPEND wa_it_receivers TO it_receivers .
*& - END of Assign the Email id and User id to Whom you want to Send --&
"&--- Read the Number of lines in the Internal Table
DESCRIBE TABLE it_receivers LINES num_lines.
"&--- Check the Sender Email id or SAP User id is got or not.
IF num_lines IS NOT INITIAL.
*&---------------------------------------------------------------------
* Add thetext to mail text table
*&----------------------------------------------------------------------
*&-- Subject of the mail -------------&*
psubject = 'Daily Activity'(001).
*&-- Body of the mail ----------------&*
CLEAR wa_it_message.
c1 = 'Dear Sir'(005).
*c2 = lv_emp_userid.
CONCATENATE c1 c2 ',' INTO
wa_it_message-line SEPARATED BY space.
APPEND wa_it_message TO it_message.
*** insert Blank Line *********************************************
CLEAR wa_it_message.
wa_it_message-line = ' '.
APPEND wa_it_message TO it_message.
******* Assign your Text below *************************************
CLEAR wa_it_message.
wa_it_message-line = 'A Timesheet sent from '."(002).
CONCATENATE wa_it_message-line ' ' LV_EMP_USERID into wa_it_message-line.
APPEND wa_it_message TO it_message.
*** insert Blank Line{} *********************************************
CLEAR wa_it_message.
wa_it_message-line = ' '.
APPEND wa_it_message TO it_message.
**********Assign your Text below ********************************
CLEAR wa_it_message.
wa_it_message-line = 'This mail generate automatically. Please do not reply.'(003).
APPEND wa_it_message TO it_message.
*********************************************************************
**********& Send EMAIL MESSAGE &*********************************
gd_doc_data-doc_size = 1.
*Populate the subject/generic message attributes
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
*Describe the body of the message
CLEAR wa_it_packing_list.
REFRESH it_packing_list.
wa_it_packing_list-transf_bin = space.
wa_it_packing_list-head_start = 1.
wa_it_packing_list-head_num = 0.
wa_it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES wa_it_packing_list-body_num.
wa_it_packing_list-doc_type = 'RAW'.
APPEND wa_it_packing_list TO it_packing_list.
*&------ Call the Function Module to send the message to External and SAP Inbox
*CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
* EXPORTING
* document_data = gd_doc_data
* put_in_outbox = 'X'
* commit_work = 'X'
* TABLES
* packing_list = it_packing_list
* contents_txt = it_message
* receivers = it_receivers
* 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.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*ENDIF.
*ENDIF. "&---- END of Check the Sender Email id or SAP User id is got or not.
"data sent(1) type c."PA0105-USRID_LONG value 'abc@gmail.com'.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = gd_doc_data
PUT_IN_OUTBOX = 'X'
SENDER_ADDRESS = 'abc@erpanderp.com' (Sender address)
SENDER_ADDRESS_TYPE = 'INT'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = sent
* NEW_OBJECT_ID =
* SENDER_ID = sent
TABLES
PACKING_LIST = it_packing_list
* OBJECT_HEADER =
* CONTENTS_BIN =
CONTENTS_TXT = it_message
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = it_receivers
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.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
IF SY-SUBRC = 0.
SUBMIT RSCONN01 WITH MODE = 'INT' WITH OUTPUT = 'X' AND RETURN.
ENDIF.
endif.
04-17-2012 5:43 AM