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

Batch Email

Former Member
0 Likes
685

Hello there,

I've written a program which runs daily in batch and produces a file on

the application server. Because this program runs in batch is there

anyway I can have an automated email if the program produces a file.

I'm not sure if you can do this in the background or not??

Any help much appreciated.

Andy

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
639

Hi Andy,

Sure you can. In your program write a procedure for sending email and then all you need is to call a program releaseing the document to be sent in the background mode.

Sample code for sending email in background mode.


REPORT z_ext_email NO STANDARD PAGE HEADING.

CONSTANTS con_cret(2) TYPE c VALUE cl_abap_char_utilities=>cr_lf.

DATA: doc_attr TYPE sodocchgi1,
      it_packing_list TYPE TABLE OF sopcklsti1 WITH HEADER LINE,
      it_message TYPE TABLE OF solisti1 WITH HEADER LINE,
      it_attachment TYPE TABLE OF solisti1 WITH HEADER LINE,
      it_txt TYPE TABLE OF solisti1 WITH HEADER LINE,
      it_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE.

"Document attributes
doc_attr-obj_name = 'EXT_MAIL'.
doc_attr-obj_descr = 'External test mail'.   "title
doc_attr-obj_langu = sy-langu.
doc_attr-sensitivty = 'F'.      "functional message

"Message in ASCII (txt) format
APPEND 'This is body message' TO it_message.   "message is from 1 to 2
APPEND 'and second line for message.' TO it_message.
APPEND LINES OF it_message TO it_txt.

"Determine how data are distrtibuted to document and attachment
"First line in it_packing describes message body
it_packing_list-transf_bin = space.  "ASCII format
it_packing_list-body_start = 1.      "message body starts from 1st line
DESCRIBE TABLE it_message LINES it_packing_list-body_num.  "lines in it_txt table for message body
it_packing_list-doc_type = 'RAW'.
APPEND it_packing_list.

"Attachment in ASCII (txt) format
APPEND 'This is body of an attachment' TO it_attachment.
CONCATENATE con_cret  'and the second line for it.' INTO it_attachment.
APPEND it_attachment.
APPEND LINES OF it_attachment TO it_txt.

"Further lines in it_packing describe attachment
CLEAR it_packing_list.
it_packing_list-transf_bin = space.  "ASCII format
it_packing_list-body_start = 3.
DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.
it_packing_list-doc_type = 'txt'.
it_packing_list-obj_name = 'Test attachment'.
it_packing_list-obj_descr = 'Title of an attachment'.
it_packing_list-obj_langu = sy-langu.
"size od attachment = length of last line + all remaining lines * 255
READ TABLE it_attachment INDEX it_packing_list-body_num.
it_packing_list-doc_size = STRLEN( it_attachment ) + 255 * ( it_packing_list-body_num - 1 ).
APPEND it_packing_list.

"Receivers
it_receivers-receiver =  'Some_email_address'.
it_receivers-rec_type = 'U'.  "internet address
it_receivers-com_type = 'INT'. "send via internet
APPEND it_receivers.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data                    = doc_attr
    put_in_outbox                    = 'X'
    commit_work                      = 'X'
  TABLES
    packing_list                     = it_packing_list
   contents_txt                     = it_txt
    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.
  WAIT UP TO 2 SECONDS.
  SUBMIT rsconn01 WITH mode = 'INT'
*                    WITH ouput = 'X'       "this parameter determins wheter program to be run in fore/back ground mode
                  AND RETURN.
ENDIF.

Hope this helps you

Marcin

4 REPLIES 4
Read only

MarcinPciak
Active Contributor
0 Likes
640

Hi Andy,

Sure you can. In your program write a procedure for sending email and then all you need is to call a program releaseing the document to be sent in the background mode.

Sample code for sending email in background mode.


REPORT z_ext_email NO STANDARD PAGE HEADING.

CONSTANTS con_cret(2) TYPE c VALUE cl_abap_char_utilities=>cr_lf.

DATA: doc_attr TYPE sodocchgi1,
      it_packing_list TYPE TABLE OF sopcklsti1 WITH HEADER LINE,
      it_message TYPE TABLE OF solisti1 WITH HEADER LINE,
      it_attachment TYPE TABLE OF solisti1 WITH HEADER LINE,
      it_txt TYPE TABLE OF solisti1 WITH HEADER LINE,
      it_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE.

"Document attributes
doc_attr-obj_name = 'EXT_MAIL'.
doc_attr-obj_descr = 'External test mail'.   "title
doc_attr-obj_langu = sy-langu.
doc_attr-sensitivty = 'F'.      "functional message

"Message in ASCII (txt) format
APPEND 'This is body message' TO it_message.   "message is from 1 to 2
APPEND 'and second line for message.' TO it_message.
APPEND LINES OF it_message TO it_txt.

"Determine how data are distrtibuted to document and attachment
"First line in it_packing describes message body
it_packing_list-transf_bin = space.  "ASCII format
it_packing_list-body_start = 1.      "message body starts from 1st line
DESCRIBE TABLE it_message LINES it_packing_list-body_num.  "lines in it_txt table for message body
it_packing_list-doc_type = 'RAW'.
APPEND it_packing_list.

"Attachment in ASCII (txt) format
APPEND 'This is body of an attachment' TO it_attachment.
CONCATENATE con_cret  'and the second line for it.' INTO it_attachment.
APPEND it_attachment.
APPEND LINES OF it_attachment TO it_txt.

"Further lines in it_packing describe attachment
CLEAR it_packing_list.
it_packing_list-transf_bin = space.  "ASCII format
it_packing_list-body_start = 3.
DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.
it_packing_list-doc_type = 'txt'.
it_packing_list-obj_name = 'Test attachment'.
it_packing_list-obj_descr = 'Title of an attachment'.
it_packing_list-obj_langu = sy-langu.
"size od attachment = length of last line + all remaining lines * 255
READ TABLE it_attachment INDEX it_packing_list-body_num.
it_packing_list-doc_size = STRLEN( it_attachment ) + 255 * ( it_packing_list-body_num - 1 ).
APPEND it_packing_list.

"Receivers
it_receivers-receiver =  'Some_email_address'.
it_receivers-rec_type = 'U'.  "internet address
it_receivers-com_type = 'INT'. "send via internet
APPEND it_receivers.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data                    = doc_attr
    put_in_outbox                    = 'X'
    commit_work                      = 'X'
  TABLES
    packing_list                     = it_packing_list
   contents_txt                     = it_txt
    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.
  WAIT UP TO 2 SECONDS.
  SUBMIT rsconn01 WITH mode = 'INT'
*                    WITH ouput = 'X'       "this parameter determins wheter program to be run in fore/back ground mode
                  AND RETURN.
ENDIF.

Hope this helps you

Marcin

Read only

Former Member
0 Likes
639

Thankyou very much Marcin for your reply.

Solved a very big headache!

Thanks

Andy

Read only

Former Member
0 Likes
639

Hi Marcin

I have similar question about sending SD document (eg. billing doc) out to customer's email in the customer master.

1. I have assign the output medium to 5 (External send) and the email with the billing doc attached was sent out ok.

2. But now I want to send a few billing doc belonging to the same customer in ONE email; have you done something like that or it is possible?

Thank you,

Patrick

Read only

Former Member
0 Likes
639

I would imagine that you just append the different email addresses to the table

it_receivers