Hello everyone,
I have created a method in Overview Page View Controller Class which needs to send emails based on the below code. I am calling this method on EH_ONSAVE.
I am facing this bizzare error where when I save the Order, the method executes but no mail is sent out ( as I can see no document is created in SOST).
But if I try to debug this method manually in GUI ( i.e. I am not calling the method in saving from UI, I am directly executing the method from Class itself and going to debug; in this case, the code works fine. ).
Any Idea why this is happening?
Below is my code :
method ZSEND_EMAIL_TEST2.
TYPES : BEGIN OF ts_rec,
recipient TYPE REF TO if_recipient_bcs,
END OF ts_rec.
DATA : ls_t1(255) TYPE c,
lt_rec TYPE TABLE OF ts_rec,
ls_rec TYPE ts_rec,
lv_email TYPE adr6-smtp_addr,
lv_text TYPE bcsy_text,
lv_document TYPE REF TO cl_document_bcs,
lv_sender TYPE REF TO if_sender_bcs,
lv_recipient TYPE REF TO if_recipient_bcs,
lv_sent_to_all TYPE os_boolean,
lv_oref TYPE REF TO cx_root,
lv_text1 TYPE string,
lv_send_request TYPE REF TO cl_bcs,
lv_tabix TYPE sy-tabix,
ls_email TYPE somlreci1.
CONSTANTS: c_type TYPE so_obj_tp VALUE 'RAW',
c_length TYPE so_obj_len VALUE '12',
c_x TYPE c VALUE 'X'.
Data : lv_subject type SO_OBJ_DES.
TRY.
* create persistent send request
lv_send_request = cl_bcs=>create_persistent( ).
ls_t1 = 'Text'.
append ls_t1 to lv_text.
lv_subject = 'test'.
lv_document = cl_document_bcs=>create_document(
i_type = c_type
i_text = lv_text
i_length = c_length
i_subject = lv_subject ).
* add document to send request
CALL METHOD lv_send_request->set_document( lv_document ).
*
** set sender
lv_sender = cl_sapuser_bcs=>create( SY-UNAME ).
** lv_sender = cl_cam_address_bcs=>create_internet_address(
** iv_sender ).
CALL METHOD lv_send_request->set_sender
EXPORTING
i_sender = lv_sender.
* add recipient (e-mail address)
* create recipient - please replace e-mail address !!!
Data lv_receiver type ADR6-SMTP_ADDR.
lv_receiver = 'myemailaddress'.
lv_recipient = cl_cam_address_bcs=>create_internet_address(
lv_receiver ).
CALL METHOD lv_send_request->add_recipient
EXPORTING
i_recipient = lv_recipient
* i_copy = c_x
i_express = c_x.
**********************************************
lv_send_request->set_send_immediately( 'X' ).
CALL METHOD lv_send_request->send(
EXPORTING
i_with_error_screen = c_x
RECEIVING
result = lv_sent_to_all ).
.
commit work.
CATCH cx_sy_arithmetic_error INTO lv_oref.
lv_text1 = lv_oref->get_text( ).
CATCH cx_root INTO lv_oref.
lv_text1 = lv_oref->get_text( ).
ENDTRY.
endmethod.