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: 

end user receving same mail , twice in a day .

Former Member
0 Kudos
118

Hi,

Throu this report , i am sending mail to a user. I the scheuld this program as background job.

But My problem is end user receving same mail twice a day.I am sure , Program is executed onces in day.

Plz help me to solve the problem

REPORT zplm008_tdr_mail_alert .

*DATA DECLARATION.

DATA: it_ztdr TYPE TABLE OF ztdr WITH HEADER LINE.

DATA wa_maktx TYPE makt-maktx..

*SELECTION SCREEN

PARAMETER: p_date TYPE sy-datum DEFAULT sy-datum MODIF ID dat .

*START-OF-SELECTION

START-OF-SELECTION.

SELECT * FROM ztdr INTO TABLE it_ztdr

WHERE rlddt = p_date.

IF it_ztdr[] IS NOT INITIAL.

LOOP AT it_ztdr.

PERFORM send_mail.

ENDLOOP.

ENDIF.

&----


*& Form SEND_MAIL

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM send_mail .

DATA: lt_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: ls_message TYPE char255.

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,

gf_cnt TYPE i,

gf_sent_all(1) TYPE c,

gs_doc_data LIKE sodocchgi1,

gf_error TYPE sy-subrc.

  • Adds text to email text table

----


lt_message = 'Hi,'.

APPEND lt_message.CLEAR lt_message.APPEND lt_message.

lt_message = 'Requested design is released. Pls raise the TPR (If required to be ordered).'.

APPEND lt_message.CLEAR: lt_message.APPEND lt_message.

lt_message = 'Details of the released design:'. APPEND lt_message.

lt_message = '*******************************'.APPEND lt_message.CLEAR: lt_message.APPEND lt_message.

MOVE : 'TDR No ' TO lt_message.

lt_message+21(1) = ':'.

lt_message+22(40) = it_ztdr-tdrid .APPEND lt_message.

MOVE : 'PED Part no ' TO lt_message.

lt_message+21(1) = ':'.

lt_message+22(40) = it_ztdr-matnr.

APPEND lt_message.

CLEAR: wa_maktx.

SELECT SINGLE maktx FROM makt INTO wa_maktx WHERE matnr = it_ztdr-matnr.

MOVE 'PED Part Description' TO lt_message.

lt_message+21(1) = ':'.

lt_message+22(40) = wa_maktx .APPEND lt_message.

MOVE : 'PED Part Rev no' TO lt_message .

lt_message+21(1) = ':'.

lt_message+22(40) = it_ztdr-matnr_rv .APPEND lt_message.

MOVE: 'Rnd part No ' TO lt_message .

lt_message+21(1) = ':'.

lt_message+22(40) = it_ztdr-ref_matnr . APPEND lt_message.

MOVE : 'Rnd Part Rev ' TO lt_message .

lt_message+21(1) = ':'.

lt_message+22(40) = it_ztdr-ref_matnr_rv .APPEND lt_message.

CLEAR: lt_message.

APPEND lt_message.

APPEND lt_message.

lt_message = 'To View the Design:'.

APPEND lt_message.

lt_message = '*******************'.APPEND lt_message.

CLEAR: lt_message.

APPEND lt_message.

lt_message ='For Standard gauge, use Transaction: ZPED_TOOLPRINT'.

APPEND lt_message.

lt_message ='For Non-Standard gauge, use Transaction: ZCV04N or CV04N'.

APPEND lt_message.

*

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

*program has been executed(rsconn01)

----


  • Fill the document data.

gs_doc_data-doc_size = 1.

DATA subject TYPE string.

CONCATENATE 'Design Released for' it_ztdr-tdrid 'of' it_ztdr-ref_matnr

INTO subject SEPARATED BY space.

  • Populate the subject/generic message attributes

gs_doc_data-obj_langu = sy-langu.

gs_doc_data-obj_name = 'TDREQ'.

gs_doc_data-obj_descr = subject .

gs_doc_data-sensitivty = 'O'.

  • 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 lt_message LINES lt_packing_list-body_num.

lt_packing_list-doc_type = 'RAW'.

APPEND lt_packing_list.

CLEAR lt_receivers.

REFRESH lt_receivers.

  • Add the recipients email address

  • For SAP mail

  • IF NOT GSCR_UNAME IS INITIAL.

lt_receivers-receiver = it_ztdr-reqnm.

lt_receivers-rec_type = 'U'.

APPEND lt_receivers.

  • ENDIF.

  • For external mail

  • IF NOT gs_outtab-reqnm IS INITIAL.

  • lt_receivers-receiver = gs_outtab-reqnm.

  • lt_receivers-rec_type = 'U'.

  • APPEND lt_receivers.

  • ENDIF.

  • Call the FM to post the message to SAPMAIL

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = gs_doc_data

put_in_outbox = 'X'

commit_work = 'X'

IMPORTING

sent_to_all = gf_sent_all

TABLES

packing_list = lt_packing_list

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

  • Store function module return code

gf_error = sy-subrc.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • Get lt_receivers return code

LOOP AT lt_receivers.

ENDLOOP.

PERFORM initiate_mail_execute_program.

CLEAR:lt_message[] , lt_message , gs_doc_data ,gf_sent_all,lt_packing_list[]

,lt_packing_list ,lt_receivers[], lt_receivers.

ENDFORM. " SEND_MAIL

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM initiate_mail_execute_program .

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = 'X'

AND RETURN.

ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM

3 REPLIES 3

Former Member
0 Kudos
51

Hello Rani,

Remove this part of code from your report


&---------------------------------------------------------------------
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
&---------------------------------------------------------------------


text 
----------------------------------------------------------------------

--> p1 text 
<-- p2 text 
----------------------------------------------------------------------
FORM initiate_mail_execute_program .
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.

ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM

Cheers,

Vasanth

Former Member
0 Kudos
51

Hi,

In your code

You are looping the perform in which you are calling below FM.

LOOP AT it_ztdr.

PERFORM send_mail.

ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = gs_doc_data

put_in_outbox = 'X'

commit_work = 'X'

IMPORTING

sent_to_all = gf_sent_all

TABLES

packing_list = lt_packing_list

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

So keep your FM after the loop.

Pls. reward if useful...

Former Member
0 Kudos
51

Hi vasanth,

WHt is the problem .If call the program rsconn01.

Regards,

Rani