Application Development 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: 

Automatic mail sending for goods receipt

Former Member
0 Kudos

Hello friends

When a goods receipt against a PO (movement type 101) is done into any plant , an e-mail should be sent to ‘xyz@xyz.com ’ stating:

Material # XXXX quantity XXX has been received into Plant XXXX (field WERKS) Storage Location XXXX (field LGORT) and the date received in.

Plz suggest how to do this.

what are the tables that can be used

wat are the fms that can be used etc

where this can be configuered,, or done thru ABAP.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi kvc,

check this code.

                  • data declaration *****************************************

tables: ekko.

DATA : outlook LIKE obj_record,

outmail LIKE obj_record.

data v_char(100) type c.

data h_char(100) type c.

data result(200) type c.

DATA: v_hex type c ,

cmp type string value 'company code' ,

pur type string value 'purchase document type' .

types: begin of it_table,

bukrs type bukrs,

bsart type bsart,

end of it_table.

DATA: it_tab TYPE TABLE OF it_table WITH HEADER LINE,

wa_table type it_table.

***********start of selection*****************

start-of-selection.

select single bukrs bsart from ekko into it_tab where bedat between '01.05.2007' and '18.05.2007' .

***********using ole interfaces to send mail*****************

CONCATENATE cmp it_tab-bukrs INTO v_char SEPARATED BY v_hex.

CONCATENATE pur it_tab-bsart INTO h_char SEPARATED BY v_hex.

CONCATENATE v_char h_char INTO result SEPARATED BY v_hex.

write result.

CREATE OBJECT outlook 'Outlook.Application'.

CALL METHOD OF outlook 'CREATEITEM' = outmail EXPORTING #1 = 0.

SET PROPERTY OF outmail 'TO' = ' <enter ur email id here> '.

SET PROPERTY OF outmail 'SUBJECT' = 'Document details'.

SET PROPERTY OF outmail 'BODY' = result.

CALL METHOD OF outmail 'SEND'.

FREE OBJECT outlook.

if sy-subrc = 0.

write:/ 'Message sent successfully'.

endif.

regards,

niky

5 REPLIES 5

Former Member
0 Kudos

Hi

This can be done using the Workflow using the Business Object MKPF

Create a method SENDMAIL by coping this business object to ZMKPF and create a task and build the workflow and so that when GR created a mail is sent to the receipant.

Use the following code;

  • Call Function Module To send mail

CALL FUNCTION 'UWSP_SEND_MAIL_TO_WEB'

EXPORTING

id_header = v_header

id_body = v_body

id_receiver = v_receiver

id_sender = v_sendor

  • ID_HTML_MAIL =

id_commit_work = 'X'

EXCEPTIONS

error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Reward points if useful

Regards

Anji

Former Member
0 Kudos

Hi,

We can use this FM for sending the mail

'SO_NEW_DOCUMENT_ATT_SEND_API1

Regards,

kumar.

Former Member
0 Kudos

Hi,

The code below demonstrates how to send an email to an external email address

&----


*& Report ZSENDEMAIL *

*& *

&----


*& Example of sending external email via SAPCONNECT *

*& *

&----


REPORT zsendemail .

PARAMETERS: psubject(40) type c default 'Hello',

p_email(40) type c default 'test@sapdev.co.uk' .

data: it_packing_list like sopcklsti1 occurs 0 with header line,

it_contents like solisti1 occurs 0 with header line,

it_receivers like somlreci1 occurs 0 with header line,

it_attachment like solisti1 occurs 0 with header line,

gd_cnt type i,

gd_sent_all(1) type c,

gd_doc_data like sodocchgi1,

gd_error type sy-subrc.

data: it_message type standard table of SOLISTI1 initial size 0

with header line.

***********************************************************************

*START-OF-SELECTION.

START-OF-SELECTION.

Perform populate_message_table.

*Send email message, although is not sent from SAP until mail send

*program has been executed(rsconn01)

PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)

perform initiate_mail_execute_program.

&----


*& Form POPULATE_MESSAGE_TABLE

&----


  • Adds text to email text table

----


form populate_message_table.

Append 'Email line 1' to it_message.

Append 'Email line 2' to it_message.

Append 'Email line 3' to it_message.

Append 'Email line 4' to it_message.

endform. " POPULATE_MESSAGE_TABLE

&----


*& Form SEND_EMAIL_MESSAGE

&----


  • Send email message

----


form send_email_message.

  • Fill the document data.

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 it_packing_list.

refresh it_packing_list.

it_packing_list-transf_bin = space.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

describe table it_message lines it_packing_list-body_num.

it_packing_list-doc_type = 'RAW'.

append it_packing_list.

  • Add the recipients email address

clear it_receivers.

refresh it_receivers.

it_receivers-receiver = p_email.

it_receivers-rec_type = 'U'.

it_receivers-com_type = 'INT'.

it_receivers-notif_del = 'X'.

it_receivers-notif_ndel = 'X'.

append it_receivers.

  • Call the FM to post the message to SAPMAIL

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = gd_doc_data

put_in_outbox = 'X'

importing

sent_to_all = gd_sent_all

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.

  • Store function module return code

gd_error = sy-subrc.

  • Get it_receivers return code

loop at it_receivers.

endloop.

endform. " SEND_EMAIL_MESSAGE

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • Instructs mail send program for SAPCONNECT to send email.

----


form initiate_mail_execute_program.

wait up to 2 seconds.

if gd_error eq 0.

submit rsconn01 with mode = 'INT'

with output = 'X'

and return.

endif.

endform. " INITIATE_MAIL_EXECUTE_PROGRAM

Hope this helps.

Reward if helpful.

Regards,

Sipra

Former Member
0 Kudos

hi kvc,

check this code.

                  • data declaration *****************************************

tables: ekko.

DATA : outlook LIKE obj_record,

outmail LIKE obj_record.

data v_char(100) type c.

data h_char(100) type c.

data result(200) type c.

DATA: v_hex type c ,

cmp type string value 'company code' ,

pur type string value 'purchase document type' .

types: begin of it_table,

bukrs type bukrs,

bsart type bsart,

end of it_table.

DATA: it_tab TYPE TABLE OF it_table WITH HEADER LINE,

wa_table type it_table.

***********start of selection*****************

start-of-selection.

select single bukrs bsart from ekko into it_tab where bedat between '01.05.2007' and '18.05.2007' .

***********using ole interfaces to send mail*****************

CONCATENATE cmp it_tab-bukrs INTO v_char SEPARATED BY v_hex.

CONCATENATE pur it_tab-bsart INTO h_char SEPARATED BY v_hex.

CONCATENATE v_char h_char INTO result SEPARATED BY v_hex.

write result.

CREATE OBJECT outlook 'Outlook.Application'.

CALL METHOD OF outlook 'CREATEITEM' = outmail EXPORTING #1 = 0.

SET PROPERTY OF outmail 'TO' = ' <enter ur email id here> '.

SET PROPERTY OF outmail 'SUBJECT' = 'Document details'.

SET PROPERTY OF outmail 'BODY' = result.

CALL METHOD OF outmail 'SEND'.

FREE OBJECT outlook.

if sy-subrc = 0.

write:/ 'Message sent successfully'.

endif.

regards,

niky

Former Member
0 Kudos

scheduled a backgound job. as no user exit and badi is available