Application Development and Automation 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: 
Read only

email sending after validation

Former Member
0 Likes
701

Hi ,

I am working on a user exit.It is a BAdI.I have to validate the name of the person who signed the PO invoice.Once approved the person has to receive an email with a standard subject text and email text.I dont know how I should proceed for email sending.Can you please help me out on this.

Points will be rewarded .Thanks in advance.

Thanks,

Reni

1 ACCEPTED SOLUTION
Read only

anversha_s
Active Contributor
0 Likes
666

hi,

<b><i>how to send email.</i></b>

chk this sample code.

Try this sample code :-

REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200. 

DATA : BEGIN OF ITAB OCCURS 0, 
PERNR LIKE PA0001-PERNR, 
ENAME LIKE PA0001-ENAME, 
END OF ITAB. 

DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE, 
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE, 
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE, 
listobject LIKE abaplist OCCURS 10, 
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE, 
w_object_hd_change LIKE sood1, 
compressed_size LIKE sy-index. 

START-OF-SELECTION. 

SELECT PERNR ENAME 
INTO CORRESPONDING FIELDS OF TABLE ITAB 
FROM PA0001 
WHERE PERNR < 50. 

LOOP AT ITAB. 
WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50 
SY-VLINE. 
ENDLOOP. 
  

* Receivers 
receiver_list-recextnam = '[email protected]'. "--> 
* EMAIL ADDRESS 
RECEIVER_list-RECESC = 'E'. "<- 
RECEIVER_list-SNDART = 'INT'."<- 
RECEIVER_list-SNDPRI = '1'."<- 

APPEND receiver_list. 

* General data 
w_object_hd_change-objla = sy-langu. 
w_object_hd_change-objnam = 'Object name'. 
w_object_hd_change-objsns = 'P'. 
* Mail subject 
w_object_hd_change-objdes = 'Message subject'. 

* Mail body 
APPEND 'Message content' TO message_content. 

* Attachment 
CALL FUNCTION 'SAVE_LIST' 
EXPORTING 
list_index = '0' 
TABLES 
listobject = listobject. 

CALL FUNCTION 'TABLE_COMPRESS' 
IMPORTING 
compressed_size = compressed_size 
TABLES 
in = listobject 
out = compressed_attachment. 

DESCRIBE TABLE compressed_attachment. 
CLEAR packing_list. 
packing_list-transf_bin = 'X'. 
packing_list-head_start = 0. 
packing_list-head_num = 0. 
packing_list-body_start = 1. 
packing_list-body_num = sy-tfill. 
packing_list-objtp = 'ALI'. 
packing_list-objnam = 'Object name'. 
packing_list-objdes = 'Attachment description'. 
packing_list-objlen = compressed_size. 
APPEND packing_list. 

CALL FUNCTION 'SO_OBJECT_SEND' 
EXPORTING 
object_hd_change = w_object_hd_change 
object_type = 'RAW' 
owner = sy-uname 
TABLES 
objcont = message_content 
receivers = receiver_list 
packing_list = packing_list 
att_cont = compressed_attachment.

rgds

anver

Hi ,

I am working on a user exit.It is a BAdI.I have to validate the name of the person who signed the PO invoice.Once approved the person has to receive an email with a standard subject text and email text.I dont know how I should proceed for email sending.Can you please help me out on this.

Points will be rewarded .Thanks in advance.

Thanks,

Reni

4 REPLIES 4
Read only

Former Member
0 Likes
666

Hi jose

you can use this FM to send a mail to any user he may be sapuser id or it can be other mail id like [email protected] etc..

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = L_WA_DOCDATA

TABLES

PACKING_LIST = L_IT_OBJPACK

CONTENTS_TXT = L_IT_OBJTXT

RECEIVERS = L_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 IS NOT INITIAL.

CLEAR L_IT_OBJTXT.

ENDIF.

Please let me know you r problem is solved

Regrads

Nary.....

Read only

0 Likes
666

Hi ,

Thanks a lot for your reply .Can you please tell me what all configurations I have to do for this mail send?

Thanks in advance.

Reni

Read only

0 Likes
666

Hi,

Normally there is no need to make any configaration.

Already the BASIS guys might handled it

rgds

anver

Read only

anversha_s
Active Contributor
0 Likes
667

hi,

<b><i>how to send email.</i></b>

chk this sample code.

Try this sample code :-

REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200. 

DATA : BEGIN OF ITAB OCCURS 0, 
PERNR LIKE PA0001-PERNR, 
ENAME LIKE PA0001-ENAME, 
END OF ITAB. 

DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE, 
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE, 
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE, 
listobject LIKE abaplist OCCURS 10, 
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE, 
w_object_hd_change LIKE sood1, 
compressed_size LIKE sy-index. 

START-OF-SELECTION. 

SELECT PERNR ENAME 
INTO CORRESPONDING FIELDS OF TABLE ITAB 
FROM PA0001 
WHERE PERNR < 50. 

LOOP AT ITAB. 
WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50 
SY-VLINE. 
ENDLOOP. 
  

* Receivers 
receiver_list-recextnam = '[email protected]'. "--> 
* EMAIL ADDRESS 
RECEIVER_list-RECESC = 'E'. "<- 
RECEIVER_list-SNDART = 'INT'."<- 
RECEIVER_list-SNDPRI = '1'."<- 

APPEND receiver_list. 

* General data 
w_object_hd_change-objla = sy-langu. 
w_object_hd_change-objnam = 'Object name'. 
w_object_hd_change-objsns = 'P'. 
* Mail subject 
w_object_hd_change-objdes = 'Message subject'. 

* Mail body 
APPEND 'Message content' TO message_content. 

* Attachment 
CALL FUNCTION 'SAVE_LIST' 
EXPORTING 
list_index = '0' 
TABLES 
listobject = listobject. 

CALL FUNCTION 'TABLE_COMPRESS' 
IMPORTING 
compressed_size = compressed_size 
TABLES 
in = listobject 
out = compressed_attachment. 

DESCRIBE TABLE compressed_attachment. 
CLEAR packing_list. 
packing_list-transf_bin = 'X'. 
packing_list-head_start = 0. 
packing_list-head_num = 0. 
packing_list-body_start = 1. 
packing_list-body_num = sy-tfill. 
packing_list-objtp = 'ALI'. 
packing_list-objnam = 'Object name'. 
packing_list-objdes = 'Attachment description'. 
packing_list-objlen = compressed_size. 
APPEND packing_list. 

CALL FUNCTION 'SO_OBJECT_SEND' 
EXPORTING 
object_hd_change = w_object_hd_change 
object_type = 'RAW' 
owner = sy-uname 
TABLES 
objcont = message_content 
receivers = receiver_list 
packing_list = packing_list 
att_cont = compressed_attachment.

rgds

anver