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: 

sending mail.

Former Member
0 Kudos

Hi,

How can we send a mail to the user intimating him that his report/BDC is completed in background

Thanks in advance,

Das.

2 REPLIES 2

Former Member
0 Kudos

Yes you can.use FM 'SO_DOCUMENT_SEND_API1'.If your job generates spool you can convert it into pdf and send mail.

check out the following code.

&----


*& Report ZBP_BDCP_ACC

*&

&----


*&

*&

&----


REPORT zbp_bdcp_acc no standard page heading.

CONSTANTS:c_per TYPE bu_type VALUE '1',

c_comp TYPE bu_type VALUE '2',

c_arn_id_type TYPE bu_id_type VALUE 'ZID004',

c_grp TYPE bu_type VALUE '3'.

TYPES:BEGIN OF w_data,

category(120) TYPE c ,

role TYPE bu_role,

name TYPE bu_namep_f,

street TYPE ad_strspp1,

street1 TYPE ad_strspp1,

street2 TYPE ad_hsnm1,

arn TYPE BU_ID_NUMBER,

city TYPE ad_city1,

state TYPE regio,

country TYPE land1,

pin TYPE ad_pstcd1,

off_ph1 TYPE ad_tlnmbr1,

off_ph2 TYPE ad_tlnmbr1,

extension TYPE ad_tlxtns1,

res_ph1 TYPE ad_tlnmbr1,

res_ph2 TYPE ad_tlnmbr1,

fax1 TYPE ad_fxnmbr1, "Fax number

fax2 TYPE ad_fxnmbr1, "Fax number

mobile TYPE ad_mbnmbr1, "Mobile

email TYPE ad_smtpadr, "Email

END OF w_data.

TYPES:BEGIN OF w_success,

num LIKE sy-tabix,

category(120) TYPE c,

role TYPE bu_role,

name TYPE bu_namep_f,

bp TYPE bu_partner,

END OF w_success.

TYPES:BEGIN OF w_error,

num LIKE sy-tabix,

category(120) TYPE c,

role TYPE bu_role,

name TYPE bu_namep_f,

msg TYPE bapi_msg,

bp TYPE bu_partner,

END OF w_error.

  • Job Runtime Parameters

DATA: g_eventid LIKE tbtcm-eventid,

g_eventparm LIKE tbtcm-eventparm,

g_external_program_active LIKE tbtcm-xpgactive,

g_jobcount LIKE tbtcm-jobcount,

g_jobname LIKE tbtcm-jobname,

g_stepcount LIKE tbtcm-stepcount,

g_error LIKE sy-subrc,

g_reciever LIKE sy-subrc.

DATA: g_email1 TYPE somlreci1-receiver

VALUE 'raghuram_devagiri@mindtree.com',

g_sender TYPE somlreci1-receiver

VALUE 'raghuram_devagiri@mindtree.com'.

*converting spool request to PDF and to trigger mail

DATA: g_recsize TYPE i,

g_subject LIKE sodocchgi1-obj_descr,

g_sender_type LIKE soextreci1-adr_typ,

g_attachment_desc TYPE so_obj_nam,

g_attachment_name TYPE so_obj_des.

*Spool IDs

TYPES: BEGIN OF w_tbtcp.

INCLUDE STRUCTURE tbtcp.

TYPES: END OF w_tbtcp.

data: w1_tbtcp TYPE w_tbtcp.

*Binary store for PDF

CONSTANTS:c_device(4) TYPE c VALUE 'LOCL',

C_FORMAT(3) TYPE C VALUE 'PDF',

c_no(1) TYPE c VALUE ' '.

  • Binary store for PDF

DATA: BEGIN OF i_pdf_output OCCURS 0.

INCLUDE STRUCTURE tline.

DATA: END OF i_pdf_output.

DATA: i_tbtcp TYPE STANDARD TABLE OF w_tbtcp INITIAL SIZE 0.

DATA: i_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: w_centraldata TYPE bapibus1006_central,

w_centralperson TYPE bapibus1006_central_person,

w_address TYPE bapibus1006_address,

w_centralgrp TYPE bapibus1006_central_group,

w_centralorg TYPE bapibus1006_central_organ.

DATA: g_filename TYPE string VALUE 'ZACC_FILE_DATA.TXT',

g_identification TYPE bapibus1006_identification,

g_bpnum TYPE bu_partner,

g_stat TYPE i,

g_tabix LIKE sy-tabix,

g_buspartner TYPE bapibus1006_head-bpartner.

  • Spool to PDF conversions

DATA: g_spool_nr LIKE tsp01-rqident,

g_destination LIKE rlgrap-filename,

g_bytecount LIKE tst01-dsize,

g_buffer TYPE string.

DATA: i_data TYPE STANDARD TABLE OF w_data WITH HEADER LINE,

i_phonedata TYPE STANDARD TABLE OF bapiadtel WITH HEADER LINE,

i_phdata TYPE STANDARD TABLE OF bapinoadtel WITH HEADER LINE,

i_fxdata TYPE STANDARD TABLE OF bapiadfax WITH HEADER LINE,

i_fxdata1 TYPE STANDARD TABLE OF bapinoadfax WITH HEADER LINE,

i_email TYPE STANDARD TABLE OF bapiadsmtp WITH HEADER LINE,

i_bapiret2 TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE,

i_error TYPE STANDARD TABLE OF w_error WITH HEADER LINE,

i_success TYPE STANDARD TABLE OF w_success WITH HEADER LINE,

i_partner_role TYPE STANDARD TABLE OF bapibusisb990_bproles WITH HEADER LINE.

START-OF-SELECTION.

PERFORM file_upload USING g_filename.

LOOP AT i_data.

  • if i_data-role = 'Z2INVP'.

  • PERFORM duplicate_check.

  • if g_stat <> 1.

*

  • endif.

g_tabix = sy-tabix.

IF i_data-category = 'Mr.' OR i_data-category = 'Ms.'.

PERFORM central_emp TABLES i_data.

PERFORM prep_data TABLES i_data.

PERFORM process_data USING c_per.

ELSEIF i_data-category = 'COMPANY'.

PERFORM central_org TABLES i_data.

PERFORM prep_data TABLES i_data.

PERFORM process_data USING c_comp.

ELSEIF i_data-category = 'GRP'.

PERFORM central_group TABLES i_data.

PERFORM prep_data TABLES i_data.

PERFORM process_data USING c_grp.

ENDIF.

ENDLOOP.

PERFORM show_status TABLES i_error i_success.

  • Converting the return messages into PDF file and trigerring a mail notification

IF sy-batch EQ 'X'.

PERFORM get_job_details. "To get job details

PERFORM obtain_spool_id. "To obtain spool id

PERFORM convert_spool_to_pdf. "To convert spool to pdf

PERFORM process_email. "To process email

WAIT UP TO 5 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = 'X'

AND RETURN.

ENDIF.

&----


*& Form file_upload

&----


  • text

----


  • -->P_G_FILENAME text

----


FORM file_upload USING uv_filename.

OPEN DATASET uv_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

DO.

READ DATASET uv_filename INTO i_data.

IF sy-subrc <> 0.

EXIT.

ELSE.

APPEND i_data.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET uv_filename.

ENDFORM. " file_upload

&----


*& Form process_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM process_data USING uv_cat TYPE any.

CALL FUNCTION 'BAPI_BUPA_FS_CREATE_FROM_DATA2'

EXPORTING

  • BUSINESSPARTNEREXTERN =

partnercategory = uv_cat

  • PARTNERGROUP =

centraldata = w_centraldata

centraldataperson = w_centralperson

centraldataorganization = w_centralorg

centraldatagroup = w_centralgrp

addressdata = w_address

  • DUPLICATE_MESSAGE_TYPE =

  • ACCEPT_ERROR = ' '

  • TESTRUN =

  • CHANGEDOCU =

IMPORTING

businesspartner = g_buspartner

TABLES

telefondata = i_phonedata

faxdata = i_fxdata

  • TELETEXDATA =

  • TELEXDATA =

e_maildata = i_email

  • RMLADDRESSDATA =

  • X400ADDRESSDATA =

  • RFCADDRESSDATA =

  • PRTADDRESSDATA =

  • SSFADDRESSDATA =

  • URIADDRESSDATA =

  • PAGADDRESSDATA =

  • ADDRESSNOTES =

  • COMMUNICATIONNOTES =

  • TELEFONDATANONADDRESS = i_phdata

  • FAXDATANONADDRESS = i_fxdata1

  • TELETEXDATANONADDRESS =

  • TELEXDATANONADDRESS =

  • E_MAILDATANONADDRESS =

  • RMLADDRESSDATANONADDRESS =

  • X400ADDRESSDATANONADDRESS =

  • RFCADDRESSDATANONADDRESS =

  • PRTADDRESSDATANONADDRESS =

  • SSFADDRESSDATANONADDRESS =

  • URIADDRESSDATANONADDRESS =

  • PAGADDRESSDATANONADDRESS =

  • COMMUNICATIONNOTESNONADDRESS =

return = i_bapiret2

  • ADDRESSDUPLICATES =

roles = i_partner_role.

IF g_buspartner IS NOT INITIAL.

if i_data-role = 'Z2INVP'.

PERFORM duplicate_check.

IF g_stat <> 1.

PERFORM commit_transaction .

i_success-num = g_tabix.

i_success-category = i_data-category.

i_success-role = i_data-role.

i_success-bp = g_buspartner.

i_success-name = i_data-name.

APPEND i_success.

else.

i_error-num = g_tabix.

i_error-category = i_data-category.

i_error-role = i_data-role.

i_error-msg = text-001.

i_error-name = i_data-name.

i_error-bp = g_bpnum.

APPEND i_error.

IF i_data-arn IS NOT INITIAL.

PERFORM add_identification.

ENDIF.

endif.

else.

PERFORM commit_transaction .

i_success-num = g_tabix.

i_success-category = i_data-category.

i_success-role = i_data-role.

i_success-bp = g_buspartner.

i_success-name = i_data-name.

APPEND i_success.

i_error-num = g_tabix.

i_error-category = i_data-category.

i_error-role = i_data-role.

i_error-msg = i_bapiret2-message.

i_error-name = i_data-name.

IF i_data-arn IS NOT INITIAL.

PERFORM add_identification.

ENDIF.

APPEND i_error.

ENDIF.

ENDIF.

*if G_BUSPARTNER IS NOT INITIAL.

ENDFORM. " process_data

&----


*& Form commit_transaction

&----


  • text

----


FORM commit_transaction .

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ENDFORM. "commit_transaction

&----


*& Form prep_emp_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM prep_data TABLES ut_data STRUCTURE i_data .

DATA:l_title TYPE tsad3t-title.

SELECT SINGLE title FROM tsad3t INTO l_title

WHERE

langu = 'E'

AND

title_medi = ut_data-category.

w_centraldata-searchterm1 = ut_data-name+1(10).

w_centraldata-title_key = l_title.

w_address-street = ut_data-street.

w_address-str_suppl1 = ut_data-street1.

w_address-str_suppl2 = ut_data-street2.

w_address-city = ut_data-city.

w_address-region = ut_data-state.

w_address-country = ut_data-country.

w_address-postl_cod1 = ut_data-pin.

i_phonedata-telephone = ut_data-res_ph1.

i_phonedata-r_3_user = '1'.

APPEND i_phonedata.

i_phonedata-telephone = ut_data-res_ph2.

i_phonedata-r_3_user = '1'.

APPEND i_phonedata.

i_phonedata-telephone = ut_data-mobile.

i_phonedata-r_3_user = '2'.

APPEND i_phonedata.

  • i_phdata-telephone = i_data-mobile.

  • i_phdata-r_3_user = '2'.

  • i_phdata-extension = i_data-extension.

  • append i_phdata.

i_fxdata-fax = ut_data-fax1.

APPEND i_fxdata.

i_fxdata1-fax = ut_data-fax2.

APPEND i_fxdata1.

i_email-e_mail = ut_data-email.

APPEND i_email.

i_partner_role-partnerrole = ut_data-role.

APPEND i_partner_role.

ENDFORM. " prep_emp_data

&----


*& Form PREP_ORG_DATA

&----


  • text

----


  • -->P_I_DATA text

----


&----


*& Form CENTRAL_EMP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM central_emp TABLES ut_data STRUCTURE i_data.

CLEAR:w_centralorg,w_centralgrp.

CLEAR: i_partner_role,i_phonedata,i_fxdata,i_fxdata1,i_email.

REFRESH:i_partner_role,i_phonedata,i_fxdata,i_fxdata1,i_email.

w_centralperson-firstname = ut_data-name.

ENDFORM. " CENTRAL_EMP

&----


*& Form CENTRAL_ORG

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM central_org TABLES ut_data STRUCTURE i_data.

CLEAR: w_centralperson,w_centralgrp.

*clear w_centralorg.

CLEAR: i_partner_role,i_phonedata,i_fxdata,i_fxdata1,i_email.

REFRESH:i_partner_role,i_phonedata,i_fxdata,i_fxdata1,i_email.

w_centralorg-name1 = i_data-name.

ENDFORM. " CENTRAL_ORG

&----


*& Form CENTRAL_GROUP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM central_group TABLES ut_data STRUCTURE i_data.

CLEAR: w_centralperson,w_centralorg.

CLEAR: i_partner_role,i_phonedata,i_fxdata,i_fxdata1,i_email.

REFRESH:i_partner_role,i_phonedata,i_fxdata,i_fxdata1,i_email.

w_centralgrp-namegroup1 = ut_data-name.

ENDFORM. " CENTRAL_GROUP

&----


*& Form add_identification

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM add_identification .

CALL FUNCTION 'BUPA_IDENTIFICATION_ADD'

EXPORTING

iv_partner = g_buspartner

iv_identificationnumber = i_data-arn

is_identification = g_identification

iv_identificationtype = c_arn_id_type

iv_x_save = 'X'

TABLES

et_return = i_bapiret2.

PERFORM commit_transaction.

ENDFORM. " add_identification

&----


*& Form DUPLICATE_CHECK

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM duplicate_check .

CALL FUNCTION 'ZACC_DUPLICATION_CHECK'

EXPORTING

firstname = i_data-name

  • PAN_NO =

mobile = i_data-mobile

email = i_data-email

  • ADDRESS = I_DATA

IMPORTING

bpnumber = g_bpnum

status = g_stat.

ENDFORM. " DUPLICATE_CHECK

&----


*& Form show_status

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM show_status TABLES ut_error STRUCTURE i_error

ut_success STRUCTURE i_success.

DATA: l_error_lines TYPE i,

l_lines TYPE i,

l_success_lines TYPE i.

DESCRIBE TABLE i_data LINES l_lines.

DESCRIBE TABLE ut_error LINES l_error_lines.

l_success_lines = l_lines - l_error_lines.

WRITE:/ text-001 , g_filename ,60 text-002 , l_lines.

SKIP 1.

WRITE: / text-003, l_success_lines.

WRITE: / text-004, l_error_lines.

SKIP 2.

IF ut_success IS NOT INITIAL.

WRITE: / text-005.

WRITE: / '----


'.

WRITE: /12 text-006,20 text-007, 30 text-008.

LOOP AT ut_success.

WRITE:/6 ut_success-num , 20 ut_success-name , 30 ut_success-bp.

ENDLOOP.

ENDIF.

if ut_error[] is not initial.

write:/ text-009.

WRITE: / '----


'.

WRITE: /1 text-006,10 text-007, 20 text-010.

loop at ut_error.

write:/1 ut_error-num , 10 ut_error-name , 20 ut_error-msg.

endloop.

endif.

  • For Spool request to be converted to PDF

NEW-PAGE.

COMMIT WORK.

NEW-PAGE PRINT OFF.

ENDFORM. " show_status

&----


*& Form get_job_details

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form get_job_details .

  • Get current job details

CALL FUNCTION 'GET_JOB_RUNTIME_INFO'

IMPORTING

eventid = g_eventid

eventparm = g_eventparm

external_program_active = g_external_program_active

jobcount = g_jobcount

jobname = g_jobname

stepcount = g_stepcount

EXCEPTIONS

no_runtime_info = 1

OTHERS = 2.

endform. " get_job_details

&----


*& Form obtain_spool_id

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form obtain_spool_id .

CHECK NOT ( g_jobname IS INITIAL ).

CHECK NOT ( g_jobcount IS INITIAL ).

SELECT * FROM tbtcp

INTO TABLE i_tbtcp

WHERE jobname = g_jobname

AND jobcount = g_jobcount

AND stepcount = g_stepcount

AND listident <> '0000000000'

ORDER BY jobname

jobcount

stepcount.

READ TABLE i_tbtcp INTO w1_tbtcp INDEX 1.

IF sy-subrc = 0.

g_spool_nr = w1_tbtcp-listident.

  • MESSAGE s004 WITH g_spool_nr.

ELSE.

  • MESSAGE s005 .

ENDIF.

endform. " obtain_spool_id

&----


*& Form convert_spool_to_pdf

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form convert_spool_to_pdf .

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = g_spool_nr

no_dialog = c_no

dst_device = c_device

IMPORTING

pdf_bytecount = g_bytecount

TABLES

pdf = i_pdf_output

EXCEPTIONS

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

OTHERS = 12.

CHECK sy-subrc = 0.

  • Transfer the 132-long strings to 255-long strings

LOOP AT i_pdf_output.

TRANSLATE i_pdf_output USING ' ~'.

CONCATENATE g_buffer i_pdf_output INTO g_buffer.

ENDLOOP.

TRANSLATE g_buffer USING '~ '.

DO.

i_mess_att = g_buffer.

APPEND i_mess_att.

SHIFT g_buffer LEFT BY 255 PLACES.

IF g_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

endform. " convert_spool_to_pdf

  • &---------------------------------------------------------------------

*& Form process_email

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form process_email .

DESCRIBE TABLE i_mess_att LINES g_recsize.

CHECK g_recsize > 0.

PERFORM send_email USING g_email1.

endform. " process_email

FORM send_email USING uv_email TYPE so_recname.

CHECK NOT ( uv_email IS INITIAL ).

REFRESH i_mess_bod.

  • Default subject matter

g_subject = text-016.

g_attachment_desc = text-017.

i_mess_bod = text-018.

APPEND i_mess_bod.

i_mess_bod = text-019.

APPEND i_mess_bod.

CLEAR i_mess_bod.

i_mess_bod = text-020.

APPEND i_mess_bod.

CLEAR i_mess_bod.

i_mess_bod = text-021.

APPEND i_mess_bod.

CLEAR i_mess_bod.

APPEND i_mess_bod.

APPEND i_mess_bod.

i_mess_bod = text-022.

APPEND i_mess_bod.

  • If no sender specified - default blank

IF g_sender EQ space.

g_sender_type = space.

ELSE.

g_sender_type = 'INT'.

ENDIF.

  • Send file by email as PDF document

PERFORM send_file_as_email_attachment

TABLES i_mess_bod

i_mess_att

USING uv_email

text-023

C_FORMAT

g_attachment_name

g_attachment_desc

g_sender

g_sender_type

CHANGING g_error

g_reciever.

ENDFORM. " send_email

&----


*& Form send_file_as_email_attachment

&----


  • This Subroutine is used to send the PDF file as attachment *

----


FORM send_file_as_email_attachment TABLES ut_message STRUCTURE i_mess_bod

ut_attach STRUCTURE i_mess_att

USING uv_email TYPE so_recname

uv_mtitle TYPE any

uv_format TYPE any

uv_filename TYPE so_obj_des

uv_attdescription TYPE so_obj_nam

uv_sender_address TYPE so_recname

uv_sender_addres_type TYPE so_adr_typ

CHANGING uv_error TYPE sysubrc

uv_reciever TYPE sysubrc.

DATA: l_error TYPE sy-subrc,

l_reciever TYPE sy-subrc,

l_mtitle LIKE sodocchgi1-obj_descr,

l_email LIKE somlreci1-receiver,

l_format TYPE so_obj_tp ,

l_attdescription TYPE so_obj_nam ,

l_attfilename TYPE so_obj_des ,

l_sender_address LIKE soextreci1-receiver,

l_sender_address_type LIKE soextreci1-adr_typ,

l_receiver LIKE sy-subrc.

DATA: lt_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

lt_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,

lt_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

lt_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,

lt_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,

l_cnt TYPE i,

l_sent_all(1) TYPE c,

wa_doc_data LIKE sodocchgi1.

l_email = uv_email.

l_mtitle = uv_mtitle.

l_format = uv_format.

l_attdescription = uv_attdescription.

l_attfilename = uv_filename.

l_sender_address = uv_sender_address.

l_sender_address_type = uv_sender_addres_type.

  • Fill the document data.

wa_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

wa_doc_data-obj_langu = sy-langu.

wa_doc_data-obj_name = 'SAPRPT'.

wa_doc_data-obj_descr = l_mtitle .

wa_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

CLEAR wa_doc_data.

READ TABLE ut_attach INDEX l_cnt.

wa_doc_data-doc_size =

( l_cnt - 1 ) * 255 + STRLEN( ut_attach ).

wa_doc_data-obj_langu = sy-langu.

wa_doc_data-obj_name = 'SAPRPT'.

wa_doc_data-obj_descr = l_mtitle.

wa_doc_data-sensitivty = 'F'.

CLEAR lt_attachment.

REFRESH lt_attachment.

lt_attachment[] = ut_attach[].

  • Describe the body of the message

CLEAR lt_packing_list.

REFRESH lt_packing_list.

lt_packing_list-transf_bin = space.

lt_packing_list-head_start = 1.

lt_packing_list-head_num = 0.

lt_packing_list-body_start = 1.

DESCRIBE TABLE ut_message LINES lt_packing_list-body_num.

lt_packing_list-doc_type = 'RAW'.

APPEND lt_packing_list.

  • Create attachment notification

lt_packing_list-transf_bin = 'X'.

lt_packing_list-head_start = 1.

lt_packing_list-head_num = 1.

lt_packing_list-body_start = 1.

DESCRIBE TABLE lt_attachment LINES lt_packing_list-body_num.

lt_packing_list-doc_type = l_format.

lt_packing_list-obj_descr = l_attdescription.

lt_packing_list-obj_name = l_attfilename.

lt_packing_list-doc_size = lt_packing_list-body_num * 255.

APPEND lt_packing_list.

  • Add the recipients email address

CLEAR lt_receivers.

REFRESH lt_receivers.

lt_receivers-receiver = l_email.

lt_receivers-rec_type = 'U'.

lt_receivers-com_type = 'INT'.

lt_receivers-notif_del = 'X'.

lt_receivers-notif_ndel = 'X'.

APPEND lt_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = wa_doc_data

put_in_outbox = 'X'

commit_work = 'X'

IMPORTING

sent_to_all = l_sent_all

TABLES

packing_list = lt_packing_list

contents_bin = lt_attachment

contents_txt = ut_message

receivers = lt_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.

  • Populate zerror return code

l_error = sy-subrc.

  • Populate zreceiver return code

LOOP AT lt_receivers.

l_receiver = lt_receivers-retrn_code.

ENDLOOP.

ENDFORM. " send_file_as_email_attachment

Former Member
0 Kudos

hi,

: You can use FUNCTION RS_SEND_MAIL_FOR_SPOOLLIST

If Unix is being used, you may send a report to any internet mail with the following:

REPORT ZSNDMAIL .

DATA: COMND(200) type c.

DATA: RESULT(200) type c occurs 100 with header line.

PARAMETERS: FILE(60) type c lower case default '/sapdata/sd_outbound/testmail.dat'.

PARAMETERS: SUBJECT(60) type c lower case.

PARAMETERS: EMAIL(60) type c lower case.

INITIALIZATION.

TRANSLATE EMAIL TO LOWER CASE.

START-OF-SELECTION.

TRANSLATE EMAIL TO LOWER CASE.

CONCATENATE 'cat' FILE '| elm -s "' subject '"' email into comnd seperated by space.

CALL 'SYSTEM' ID 'COMMAND' FIELD comnd 'TAB' FIELD UNIX_RESULTS-SYS.

Loop at Results.

write: /1 results.

endloop

end-of-selection.

Reward points if found helpful...

Cheers,

Siva Ramakrishna.