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

SEND MAIL FROM BADI

Former Member
0 Likes
3,125

Hi guys,

I have the following code to send mail from a HR BADI. When i paste this code in a simple report , the mail is sent successfully. but when i execute the transaction PA40 i see the code gets executed successfully with sy-subrc eq 0 but i never see the mail in the queue throught SCOT.. any idea what i am doing wrong ??

METHOD if_ex_hrpad00infty~in_update.
  DATA: it_message        TYPE swftlisti1,
        it_packing_list   TYPE swftpcklst,
        it_receivers      TYPE ptreq_email_receivers_tab,
        ls_receivers      TYPE somlreci1,
        ls_packing_list   TYPE sopcklsti1,
        ls_message        TYPE solisti1,
        lv_to(40)         TYPE c,
        ls_doc_data       TYPE sodocchgi1,
        lv_sent_all(1)    TYPE c.

  BREAK-POINT.
  IF ipspar-massn = '20'.

    ls_message-line = 'this is a test'.
    APPEND ls_message TO it_message.

* Fill the document data.
    ls_doc_data-doc_size = 1.
    ls_doc_data-obj_langu = sy-langu.
    ls_doc_data-obj_name  = 'SAPRPT'.
    ls_doc_data-obj_descr = 'Actions'.
    ls_doc_data-sensitivty = 'F'.

    ls_packing_list-transf_bin = space.
    ls_packing_list-head_start = 1.
    ls_packing_list-head_num = 0.
    ls_packing_list-body_start = 1.
    ls_packing_list-doc_type = 'RAW'.
    DESCRIBE TABLE it_message[] LINES ls_packing_list-body_num.
    APPEND  ls_packing_list TO it_packing_list.

    REFRESH it_receivers[].
    ls_receivers-receiver   = '[email protected]'.
    ls_receivers-rec_type   = 'U'.   " Outlook Distribution List
    ls_receivers-com_type   = 'INT'.
    ls_receivers-notif_del  = ' '.
    ls_receivers-notif_ndel = ' '.
    APPEND ls_receivers TO it_receivers.


* Call the FM to post the message to SAPMAIL
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data              = ls_doc_data
        put_in_outbox              = 'X'
        commit_work                = 'X'
      IMPORTING
        sent_to_all                = lv_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.

    WAIT UP TO 2 SECONDS.
    IF sy-subrc EQ 0.
      SUBMIT rsconn01 WITH mode   = 'INT'
                      WITH output = space
                    AND RETURN.
    ENDIF.


  ENDIF.

ENDMETHOD.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,830

Hi Amandeep,

Try putting COMMIT WORK after the FM call.

Regards,

Atish

Hi guys,

I have the following code to send mail from a HR BADI. When i paste this code in a simple report , the mail is sent successfully. but when i execute the transaction PA40 i see the code gets executed successfully with sy-subrc eq 0 but i never see the mail in the queue throught SCOT.. any idea what i am doing wrong ??

METHOD if_ex_hrpad00infty~in_update.
  DATA: it_message        TYPE swftlisti1,
        it_packing_list   TYPE swftpcklst,
        it_receivers      TYPE ptreq_email_receivers_tab,
        ls_receivers      TYPE somlreci1,
        ls_packing_list   TYPE sopcklsti1,
        ls_message        TYPE solisti1,
        lv_to(40)         TYPE c,
        ls_doc_data       TYPE sodocchgi1,
        lv_sent_all(1)    TYPE c.

  BREAK-POINT.
  IF ipspar-massn = '20'.

    ls_message-line = 'this is a test'.
    APPEND ls_message TO it_message.

* Fill the document data.
    ls_doc_data-doc_size = 1.
    ls_doc_data-obj_langu = sy-langu.
    ls_doc_data-obj_name  = 'SAPRPT'.
    ls_doc_data-obj_descr = 'Actions'.
    ls_doc_data-sensitivty = 'F'.

    ls_packing_list-transf_bin = space.
    ls_packing_list-head_start = 1.
    ls_packing_list-head_num = 0.
    ls_packing_list-body_start = 1.
    ls_packing_list-doc_type = 'RAW'.
    DESCRIBE TABLE it_message[] LINES ls_packing_list-body_num.
    APPEND  ls_packing_list TO it_packing_list.

    REFRESH it_receivers[].
    ls_receivers-receiver   = '[email protected]'.
    ls_receivers-rec_type   = 'U'.   " Outlook Distribution List
    ls_receivers-com_type   = 'INT'.
    ls_receivers-notif_del  = ' '.
    ls_receivers-notif_ndel = ' '.
    APPEND ls_receivers TO it_receivers.


* Call the FM to post the message to SAPMAIL
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data              = ls_doc_data
        put_in_outbox              = 'X'
        commit_work                = 'X'
      IMPORTING
        sent_to_all                = lv_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.

    WAIT UP TO 2 SECONDS.
    IF sy-subrc EQ 0.
      SUBMIT rsconn01 WITH mode   = 'INT'
                      WITH output = space
                    AND RETURN.
    ENDIF.


  ENDIF.

ENDMETHOD.

9 REPLIES 9
Read only

Former Member
0 Likes
1,831

Hi Amandeep,

Try putting COMMIT WORK after the FM call.

Regards,

Atish

Read only

0 Likes
1,830

i did that.. it doesn't send either..

Read only

0 Likes
1,830

Check with user profile SU01 Transaction ..

in user profile - Manitain email id and Commutinion method - should be internet connection.

once you set up logoff the system and login again.

Test the program and see the results in SOST Transaction.

Thanks

Seshu

Read only

0 Likes
1,830

Hi Seshu,

No Luck.. the user has email Id maintained, and has proper communication type set to internet, from the autorisations the user has SAP_ALL/SAP_NEW profiles. The thing is same code works in the Report... but doesn't work in BADI.. is this the correct FM i am using in the BADI ? is there any specific FM to be used in BADI to send mail... i am not sure.. getting confused now....

All i want to do it to send a mail out when an Employee is hired or when he gets terminated. This is a BADI (HRPAD00INFTY) for PA40 which i am using.

Are there any other options to send mail out except Dynamic Actions in HR ?

Thanks

Amandeep

Read only

0 Likes
1,830

Hi Amandeep,

The same FM should work,As you mentioned everything is perfect in user profile .

Better to talk to basis guy ,he might be know the reason.I am sure that program is fine.

In my company ( Dev) - when i send any email ,it will not send since dev system does not have Internet connection),if i use QA or PRD,it works fine.

Thanks

Seshu

Read only

0 Likes
1,830

Seshu,

The thing is when i execute this code in the report, it sends the mail out as i see an entry in SOST..but no entry gets created when executed from the BADI. Don't you think it should do the same if execued in the BADI ?

Anyways thnks for looking in.

Amandeep

Read only

0 Likes
1,830

Hi Amandeep,

Put the E-mail function call in another Report program and SUBMIT that report from the BAdI. Also use COMMIT work in that program.

I think it will solve your problem.

Regards,

Atish

Read only

0 Likes
1,830

Hi Atish,

Works fine now.. but i would be glad if someone can explain me why didn't the FM work inside the BADI ??

Points awarded

Thanks

Amandeep

Read only

0 Likes
1,830

Hi Amandeep,

This FM uses SAPConenct for sending the mails and it requires explicit COMMIT WORK. This also works on business objects so when you call this FM in BADI there is a conflict between the COMMIT WORK so system can't send the e-mail.

Regards,

Atish