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: 

Email Attachment Not Going

pankaj_adhikari
Active Participant
0 Kudos

Hi All

I m a functional consultant & learning ABAP these days. I was practicing to send xls or csv attachment through email but there is no email being triggered. Can someone pls advice on the issue in code? Also I would like to only show record as per system date only i.e. if i run today it should only send record for updated today.

*&---------------------------------------------------------------------*
*& Report ZREP_Test
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zrep_test.
TABLES : tcurr.
*&---------------------------------------------------------------------*
*& Types Declaration
*&---------------------------------------------------------------------*
TYPES : BEGIN OF ty_final,
kurst TYPE tcurr-kurst,
fcurr TYPE tcurr-fcurr,
tcurr TYPE tcurr-tcurr,
gdatu TYPE tcurr-gdatu,
ukurs TYPE tcurr-ukurs,
END OF ty_final.
*&---------------------------------------------------------------------*
*& Internal Table Declaration
*&---------------------------------------------------------------------*
DATA : it_final TYPE TABLE OF ty_final,
wa_final TYPE REF TO cl_salv_table.
DATA: lv_xstring TYPE xstring,
lv_xlen TYPE int4,
lt_binary_table TYPE solix_tab,
lr_request TYPE REF TO cl_bcs,
lv_body_text TYPE bcsy_text,
lv_subject TYPE so_obj_des,
lr_recepient TYPE REF TO if_recipient_bcs,
lr_document TYPE REF TO cl_document_bcs,
lv_size TYPE so_obj_len.
*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME.
SELECT-OPTIONS : s_KURST FOR tcurr-kurst ,
s_FCURR FOR tcurr-fcurr,
s_TCURR FOR tcurr-tcurr,
s_GDATU FOR sy-datum.
SELECTION-SCREEN END OF BLOCK a.

*&---------------------------------------------------------------------*
*& Start of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
SELECT kurst fcurr tcurr gdatu
FROM tcurr INTO CORRESPONDING FIELDS OF TABLE it_final.
*where KURST = 'M'
*AND FCURR = 'CAD'
*AND TCURR = 'USD'.
TRY.
CALL METHOD cl_salv_table=>factory
* EXPORTING
* list_display = IF_SALV_C_BOOL_SAP=>FALSE
* r_container =
* container_name =
IMPORTING
r_salv_table = wa_final
CHANGING
t_table = it_final.
CATCH cx_salv_msg.
ENDTRY.
TRY.
lv_xstring = wa_final->to_xml( if_salv_bs_xml=>c_type_xlsx ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstring
IMPORTING
output_length = lv_xlen
TABLES
binary_tab = lt_binary_table.
lr_request = cl_bcs=>create_persistent( ).

APPEND 'Pls find daily exchange rates' TO lv_body_text.
lv_subject = 'Daily Exchange Rates'.

lr_document = cl_document_bcs=>create_document(
EXPORTING
i_type = 'RAW'
i_subject = lv_subject
i_text = lv_body_text ).

lv_size = lv_xlen.
lr_document->add_attachment(
i_attachment_type = 'EXT'
i_attachment_subject = lv_subject && '.xlsx'
i_attachment_size = lv_size
i_att_content_hex = lt_binary_table ).
lr_request->set_document( lr_document ).
lr_recepient = cl_cam_address_bcs=>create_internet_address( 'xyz@xyz.com' ).
lr_request->add_recipient( lr_recepient ).
lr_request->send( ).
MESSAGE 'Email Sent.' TYPE 'S'.
CATCH cx_bcs.
MESSAGE 'E-mail not sent.' TYPE 'A'.
ENDTRY.

I m practicing on S/4 Hana system.

Regards

Pankaj

1 ACCEPTED SOLUTION

jens_michaelsen
Participant
0 Kudos

Is it possible, that you've forgot the 'COMMIT WORK'?

2 REPLIES 2

jens_michaelsen
Participant
0 Kudos

Is it possible, that you've forgot the 'COMMIT WORK'?

pankaj_adhikari
Active Participant
0 Kudos

Thanks Jens. Adding 'COMMIT WORK resolved issue. Can you pls add your answer through 'Your Answer'? I guess you answered through 'Add a comment' & hence I m not able to award you points.

Regards

Pankaj