Skip to Content
author's profile photo Former Member
Former Member

sending mail 2 days before

Hi

<b><i>I have to develop a report which sends a mail to the vendor automataically 2days before of the due date. I'm having a report which fires a mail but i want to fire it before due date here is my code.</i></b>

 *&---------------------------------------------------------------------*
*& Report  ZTESTMAIL                                                   *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZTESTMAIL                               .




tables: bseg.


parameters: p_email type somlreci1-receiver default
'praveen.srrec@gmail.com'.


data: it_message type standard table of solisti1 initial size 0
with header line.
data: it_attach type standard table of solisti1 initial size 0
with header line.

data: zuonr1 like bseg-zuonr.

*DATA: begin of int_bseg occurs 0,
*
*       zuonr like bseg-zuonr,
*     end of int_bseg.

data: t_packing_list like sopcklsti1 occurs 0 with header line,
      t_contents like solisti1 occurs 0 with header line,
      t_receivers like somlreci1 occurs 0 with header line,
      t_attachment like solisti1 occurs 0 with header line,
      t_object_header like solisti1 occurs 0 with header line,


w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1,
gd_error type sy-subrc,
gd_reciever type sy-subrc.





***********************************************************************
*
*START_OF_SELECTION
start-of-selection.
* Retrieve sample data from table ekpo
perform data_retrieval.

* Populate table with detaisl to be entered into .xls file
*perform build_xls_data_table.


***********************************************************************
*
*END-OF-SELECTION
end-of-selection.
* Populate message body text
perform populate_email_message_body.

* Send file by email as .xls speadsheet

perform send_file_as_email_attachment
tables it_message
it_attach
using p_email
'Assignment Date after 2 days'
'XLS'
'filename'
' '
' '
' '
changing gd_error
gd_reciever.

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


*&---------------------------------------------------------------------
*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------
*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------
Form DATA_RETRIEVAL.

dATA wa_days LIKE P0347-SCRDD.
*DATA int_bseg1 LIKE TABLE OF int_bseg WITH HEADER LINE .


DATA: date LIKE sy-datum,
date1 like P0001-BEGDA.
*changedate(10) TYPE c.

DATA: BEGIN OF it_date1, " To accept date into a internal table
yyyy(4),
mm(2),
dd(2),
END OF it_date1.

DATA: BEGIN OF it_date2, " Internal table for dd/mm/yyyy format
dd(2),
mm(2),
yyyy(4),
END OF it_date2.


DATA: BEGIN OF it_date3, " To accept date into a internal table
yyyy(4),
mm(2),
dd(2),
END OF it_date3.

DATA: BEGIN OF it_date4, " Internal table for dd/mm/yyyy format
dd(2),
mm(2),
yyyy(4),
END OF it_date4.


date = sy-datum.
it_date1 = date.


  MOVE-CORRESPONDING it_date1 TO: it_date2.

data : int_bseg like bseg occurs 0 with header line.

select single zuonr from bseg into corresponding fields of int_bseg
where bukrs = 'GSPL'  and
      gJAHR = '2006'.

*loop at int_bseg.
*write int_bseg-zuonr.
*endloop.
*if sy-subrc <> 0.
*   write 'no records found'.
*endif.
*



*select  * from bseg into zuonr1
*where belnr = 100000020 and
*      bukrs = 'GSPL'  and
*      zuonr <> ' '  .
*      and
*  belnr = 100000020.
*



LOOP AT int_bseg.

      date1 = zuonr1.
      it_date3 = date1.

      MOVE-CORRESPONDING it_date3 TO: it_date4.


      CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
          EXPORTING
                  DATE1 = it_date4
                  DATE2 = it_date2
                  OUTPUT_FORMAT = '03'
          IMPORTING
                  DAYS = wa_days
      .
*else.
*      exit.
*endif.
*


endloop.
*form data_retrieval.
*
*DATA wa_days LIKE P0347-SCRDD.
*DATA int_bseg1 LIKE TABLE OF int_bseg WITH HEADER LINE .
*
*
*DATA: date LIKE sy-datum,
*      date1 like P0001-BEGDA.
**changedate(10) TYPE c.
*
*      DATA: BEGIN OF it_date1, " To accept date into a internal table
*        yyyy(4),
*        mm(2),
*        dd(2),
*      END OF it_date1.
*
*      DATA: BEGIN OF it_date2, " Internal table for dd/mm/yyyy format
*          dd(2),
*          mm(2),
*          yyyy(4),
*      END OF it_date2.
*
*
*      DATA: BEGIN OF it_date3, " To accept date into a internal table
*        yyyy(4),
*        mm(2),
*        dd(2),
*      END OF it_date3.
*
*      DATA: BEGIN OF it_date4, " Internal table for dd/mm/yyyy format
*          dd(2),
*          mm(2),
*          yyyy(4),
*      END OF it_date4.
*
*
*date = sy-datum.
*it_date1 = date.
*
*
*MOVE-CORRESPONDING it_date1 TO: it_date2.
*
*
*select zuonr  from bseg into corresponding  fields of  int_bseg.
*
**where belnr = 10000002 and bukrs = 'gspl'.
*
*
*LOOP AT int_bseg.
*
*
* date1 = int_bseg-zuonr.
* it_date3 = date1.
*
* MOVE-CORRESPONDING it_date3 TO: it_date4.
*
*
*
*
*
*  CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
*    EXPORTING
*      DATE1                         = it_date4
*
*      DATE2                         = it_date2
*     OUTPUT_FORMAT                 = '03'
*   IMPORTING
**     YEARS                         =
**     MONTHS                        =
*     DAYS                          = wa_days
**   EXCEPTIONS
**     INVALID_DATES_SPECIFIED       = 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.
*
*  IF wa_days = 3.
*    MOVE-CORRESPONDING int_bseg TO int_bseg1.
*    APPEND int_bseg1.
*    CLEAR int_bseg1.
*  ENDIF.
*endloop.


endform. " DATA_RETRIEVAL
*
*

*&---------------------------------------------------------------------
*
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------
*
* Send email
*----------------------------------------------------------------------
*
form send_file_as_email_attachment tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.


data: ld_error type sy-subrc,
ld_reciever type sy-subrc,
ld_mtitle like sodocchgi1-obj_descr,
ld_email like somlreci1-receiver,
ld_format type so_obj_tp ,
ld_attdescription type so_obj_nam ,
ld_attfilename type so_obj_des ,
ld_sender_address like soextreci1-receiver,
ld_sender_address_type like soextreci1-adr_typ,
ld_receiver like sy-subrc.

ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.


* Fill the document data.
w_doc_data-doc_size = 1.



* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.




** Fill the document data and get size of attachment
clear w_doc_data.
read table it_attach index w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + strlen( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
clear t_attachment.
refresh t_attachment.
t_attachment[] = pit_attach[].

* Describe the body of the message
clear t_packing_list.
refresh t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
describe table it_message lines t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
append t_packing_list.


* Add the recipients email address
clear t_receivers.
refresh t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
append t_receivers.

call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
importing
sent_to_all = w_sent_all
tables
object_header = t_object_header
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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
ld_error = sy-subrc.

* Populate zreceiver return code
loop at t_receivers.
ld_receiver = t_receivers-retrn_code.
endloop.
endform.



*&---------------------------------------------------------------------
*
*& 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



*&---------------------------------------------------------------------
*
*& Form POPULATE_EMAIL_MESSAGE_BODY
*&---------------------------------------------------------------------
*
* Populate message body text
*----------------------------------------------------------------------
*
form populate_email_message_body.
refresh it_message.
it_message = 'Assignment Date is coming After 2 Days Please check
doc.'.
append it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY






















*tables: bseg.
*
*
*parameters: p_email type somlreci1-receiver default
*'laxman@gujaratpetro.com'.
*
*
*data: it_message type standard table of solisti1 initial size 0
*with header line.
*data: it_attach type standard table of solisti1 initial size 0
*with header line.
*
*DATA: begin of int_bseg occurs 0,
*
*       zuonr like bseg-zuonr,
*     end of int_bseg.
*
*data: t_packing_list like sopcklsti1 occurs 0 with header line,
*      t_contents like solisti1 occurs 0 with header line,
*      t_receivers like somlreci1 occurs 0 with header line,
*      t_attachment like solisti1 occurs 0 with header line,
*      t_object_header like solisti1 occurs 0 with header line,
*
*w_cnt type i,
*w_sent_all(1) type c,
*w_doc_data like sodocchgi1,
*gd_error type sy-subrc,
*gd_reciever type sy-subrc.
*
*
************************************************************************
**
**START_OF_SELECTION
*start-of-selection.
** Retrieve sample data from table ekpo
*perform data_retrieval.
*
** Populate table with detaisl to be entered into .xls file
**perform build_xls_data_table.
*
*
************************************************************************
**
**END-OF-SELECTION
*end-of-selection.
** Populate message body text
*perform populate_email_message_body.
*
** Send file by email as .xls speadsheet
*
*perform send_file_as_email_attachment
*tables it_message
*it_attach
*using p_email
*'Assignment Date after 2 days'
*'XLS'
*'filename'
*' '
*' '
*' '
*changing gd_error
*gd_reciever.
*
** Instructs mail send program for SAPCONNECT to send email(rsconn01)
*perform initiate_mail_execute_program.
*
*
**&---------------------------------------------------------------------
**
**& Form DATA_RETRIEVAL
**&---------------------------------------------------------------------
**
** Retrieve data form EKPO table and populate itab it_ekko
**----------------------------------------------------------------------
**
*form data_retrieval.
*
*
*
*select zuonr from bseg into corresponding  fields of int_bseg.
*endselect.
*
*DATA: begin of int_bseg1 occurs 0,
*
*       zuonr1 like bseg-zuonr,
*     end of int_bseg1.
*
*
*loop at int_bseg.
*
*      int_bseg1-zuonr1 = int_bseg-zuonr.
*
*
*endloop.
*
*endform. " DATA_RETRIEVAL
*
*
*
**&---------------------------------------------------------------------
**
**& Form SEND_FILE_AS_EMAIL_ATTACHMENT
**&---------------------------------------------------------------------
**
** Send email
**----------------------------------------------------------------------
**
*form send_file_as_email_attachment tables pit_message
*pit_attach
*using p_email
*p_mtitle
*p_format
*p_filename
*p_attdescription
*p_sender_address
*p_sender_addres_type
*changing p_error
*p_reciever.
*
*
*data: ld_error type sy-subrc,
*ld_reciever type sy-subrc,
*ld_mtitle like sodocchgi1-obj_descr,
*ld_email like somlreci1-receiver,
*ld_format type so_obj_tp ,
*ld_attdescription type so_obj_nam ,
*ld_attfilename type so_obj_des ,
*ld_sender_address like soextreci1-receiver,
*ld_sender_address_type like soextreci1-adr_typ,
*ld_receiver like sy-subrc.
*
*ld_email = p_email.
*ld_mtitle = p_mtitle.
*ld_format = p_format.
*ld_attdescription = p_attdescription.
*ld_attfilename = p_filename.
*ld_sender_address = p_sender_address.
*ld_sender_address_type = p_sender_addres_type.
*
*
** Fill the document data.
*w_doc_data-doc_size = 1.
*
*
*
** Populate the subject/generic message attributes
*w_doc_data-obj_langu = sy-langu.
*w_doc_data-obj_name = 'SAPRPT'.
*w_doc_data-obj_descr = ld_mtitle .
*w_doc_data-sensitivty = 'F'.
*
*
*
*
*** Fill the document data and get size of attachment
*clear w_doc_data.
*read table it_attach index w_cnt.
*w_doc_data-doc_size =
*( w_cnt - 1 ) * 255 + strlen( it_attach ).
*w_doc_data-obj_langu = sy-langu.
*w_doc_data-obj_name = 'SAPRPT'.
*w_doc_data-obj_descr = ld_mtitle.
*w_doc_data-sensitivty = 'F'.
*clear t_attachment.
*refresh t_attachment.
*t_attachment[] = pit_attach[].
*
** Describe the body of the message
*clear t_packing_list.
*refresh t_packing_list.
*t_packing_list-transf_bin = space.
*t_packing_list-head_start = 1.
*t_packing_list-head_num = 0.
*t_packing_list-body_start = 1.
*describe table it_message lines t_packing_list-body_num.
*t_packing_list-doc_type = 'RAW'.
*append t_packing_list.
*
*
** Add the recipients email address
*clear t_receivers.
*refresh t_receivers.
*t_receivers-receiver = ld_email.
*t_receivers-rec_type = 'U'.
*t_receivers-com_type = 'INT'.
*t_receivers-notif_del = 'X'.
*t_receivers-notif_ndel = 'X'.
*append t_receivers.
*
*call function 'SO_DOCUMENT_SEND_API1'
*exporting
*document_data = w_doc_data
*put_in_outbox = 'X'
*sender_address = ld_sender_address
*sender_address_type = ld_sender_address_type
*commit_work = 'X'
*importing
*sent_to_all = w_sent_all
*tables
*object_header = t_object_header
*packing_list = t_packing_list
*contents_bin = t_attachment
*contents_txt = it_message
*receivers = t_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
*ld_error = sy-subrc.
*
** Populate zreceiver return code
*loop at t_receivers.
*ld_receiver = t_receivers-retrn_code.
*endloop.
*endform.
*
*
*
**&---------------------------------------------------------------------
**
**& 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
*
*
*
**&---------------------------------------------------------------------
**
**& Form POPULATE_EMAIL_MESSAGE_BODY
**&---------------------------------------------------------------------
**
** Populate message body text
**----------------------------------------------------------------------
**
*form populate_email_message_body.
*refresh it_message.
*it_message = 'Assignment Date is coming After 2 Days Please check
*doc.'.
*append it_message.
*endform. " POPULATE_EMAIL_MESSAGE_BODY

<u><b>I'm having all types of examples for sending an pdf format file or anything so please dont provide any examples of that kind i just want to fire this mail before two days</b></u>

<i><b>any help will be rewarded surely</b></i>

Regards

Pavan

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 12, 2007 at 12:46 PM

    Hi Pavan,

    You can schedule the job on daily basis. Check in the report that whether the system date and duedate of particular vendor difference is 2 days and in that case only send mail other wise no.

    Reward all helpful ansers.

    Regards,

    Kiran I

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Rich Heilman

      Hi Rich

      Actually in the new version there is no due_date so i used this field ZUONR where this field will accept any variable which will be easy for me to fetch the values. If u find any field related to this Due_date plz provide me

      Regards

      Pavan

  • author's profile photo Former Member
    Former Member
    Posted on Jun 12, 2007 at 12:40 PM

    hi pavan

    u can schedule your report to run in Background and make it to execute on 2 days before the due date.

    regards

    ravish

    <b>plz dont forget to reward points if helpful</b>

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 13, 2007 at 06:25 AM

    Hi

    You can run/schedule this prg to run daily. (i.e if its running today, it will select <b>all data whose due date is 2 days from now</b>...i.e 15 June 2007).

    Regards

    Raj

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi

      Actually i have to run my program like that only it have to check the data regularly and fire a message for the related person. Is my coding is sufficient to run it daily or any modifications should be made then plz suggest me

      regards

      Pavan

  • author's profile photo Former Member
    Former Member
    Posted on Jun 13, 2007 at 06:41 AM

    HI PAVAN,

    I am also having the same requirement like to send mail with attachment.

    I dont have idea to configure the SCOT.

    I f u dont mine can u send me ur code pls.

    Its users urgent requirement.But no one is helping me.

    I am facing lot of problems to complete that requirement.

    My mail id is

    goudjayasankar@yahoo.co.in

    Pls help me.

    I dont know how to configure the SCOT also.Pls tell me that one also.Here in my company even basis people they dont have idea to configure the SCOT. they were asking me to tell how to configure the SCOT.

    At least pls send ur code .

    Pls help me.

    Thanks & Regards,

    LOkesh.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.