‎2007 Apr 05 11:13 AM
Hi all,
How to send an e-mail notification to the recipient if a particular record is selected ( in the ALV using OOPS )and if that record has some specific value?
Is it possible to send an email, if there is some defect found in the record in ALV-OOPS?
‎2007 Apr 05 11:25 AM
Hi,
You have to maintain the data related to a userid in USR21 and ADR6 tables. USR21 table will have a person number and address number for one user and then based on these two fields you can get the email id from ADR6 table.
Try out the following code for sending email.
*..Outlook mail structures and variables
DATA: doc_chng TYPE sodocchgi1,
lv_tablines TYPE i.
DATA: li_objpack TYPE STANDARD TABLE OF gs_objpack,
lw_objpack TYPE gs_objpack.
DATA: li_objhead TYPE STANDARD TABLE OF gs_objhead,
lw_objhead TYPE gs_objhead.
DATA: li_objbin TYPE STANDARD TABLE OF gs_objhead,
lw_objbin TYPE gs_objhead.
DATA: li_objtxt TYPE STANDARD TABLE OF gs_objhead,
lw_objtxt TYPE gs_objhead.
DATA: li_reclist TYPE STANDARD TABLE OF gs_reclist,
lw_reclist TYPE gs_reclist.
After this you have to write two select queries to get the data from USR21 and ADR6 tables respectively.
IF NOT lv_requester IS INITIAL. "lv_requester = userid
*..Fetching Person Number and Address Number for the SOD approver
SELECT SINGLE persnumber addrnumber
FROM usr21
INTO (lv_persnumber , lv_addrnumber)
WHERE bname EQ lv_requester.
*..Fetching the SMTP address
IF sy-subrc = 0.
SELECT SINGLE smtp_addr
FROM adr6
INTO lv_reciever
WHERE addrnumber EQ lv_addrnumber
AND persnumber EQ lv_persnumber.
ENDIF.
ENDIF.
*..Populate the Email address to table.
MOVE : lv_reciever TO lw_reclist-receiver,
'U' TO lw_reclist-rec_type,
'X' TO lw_reclist-express.
APPEND lw_reclist TO li_reclist.
CLEAR: lw_reclist.
*..Subject line of the mail.
CONCATENATE text-126 gv_sasref text-132
INTO doc_chng-obj_descr SEPARATED BY space.
*..Body of the mail
lw_objtxt = text-135.
APPEND lw_objtxt TO li_objtxt.
CLEAR : lw_objtxt.
lw_objtxt = text-133.
APPEND lw_objtxt TO li_objtxt.
CLEAR lw_objtxt.
lw_objtxt = text-136.
APPEND lw_objtxt TO li_objtxt.
CLEAR lw_objtxt.
lw_objtxt = text-134.
APPEND lw_objtxt TO li_objtxt.
CLEAR lw_objtxt.
lw_objtxt = text-137.
APPEND lw_objtxt TO li_objtxt.
CLEAR lw_objtxt.
lw_objtxt = text-136.
APPEND lw_objtxt TO li_objtxt.
CLEAR lw_objtxt.
lw_objtxt = text-138.
APPEND lw_objtxt TO li_objtxt.
CLEAR lw_objtxt.
*..File Name
doc_chng-obj_name = gc_sendfile.
CLEAR: lv_tablines,lw_objtxt.
DESCRIBE TABLE li_objtxt LINES lv_tablines.
READ TABLE li_objtxt INTO lw_objtxt INDEX lv_tablines.
doc_chng-doc_size = ( lv_tablines - 1 ) * 255 + STRLEN( lw_objtxt ).
*..Creation of the entry for the compressed document
CLEAR lw_objpack-transf_bin.
lw_objpack-head_start = 1.
lw_objpack-head_num = 0.
lw_objpack-body_start = 1.
lw_objpack-body_num = lv_tablines.
lw_objpack-doc_type = 'HTM'.
APPEND lw_objpack TO li_objpack.
CLEAR lw_objpack.
*..Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
commit_work = 'X'
TABLES
packing_list = li_objpack
object_header = li_objhead
contents_bin = li_objbin
contents_txt = li_objtxt
receivers = li_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
<b>P.S.</b> The text symbols used in the above code carry the necessary statement which will be passed to the email.
reward all useful answers.