‎2019 May 03 3:56 PM
HI team,
i am sending excel to user. need send 3k records information with different excel sheets. each excel having 1k records.. my code works for first 1k records, 2nd 1k recoreds also sent bt error shown in above. and 3rd 1k records not sent. below is my code.
lo_document = cl_document_bcs=>create_document( "create document
i_type = lc_raw "'RAW' "Type of document HTM, TXT etc
i_text = lt_text "Email body internal table
i_subject = lc_subject ).
loop internal table wa.
if count = 1000.
cl_bcs_convert=>string_to_solix( "mothed to covert to binary
lo_document->add_attachment( "attached file
lo_send_request->set_sender( "sent user
EXPORTING
i_sender = lo_sender ).
lo_send_request->add_recipient(
CALL METHOD lo_send_request->set_send_immediately
lo_send_request->send(
EXPORTING
i_with_error_screen = gc_x ).
Clear count.
endif.
endloop.
my code works for first 1k recored and second 1k recored also sent but getting hiligted error. Thats way 3rd 1k recoreds not sent.
help me.
‎2019 May 03 7:46 PM
Presistace class and create document class place the inside the loop. It's creating 3 xl sheets with 1k records. But issue is it's triggered mail 3 times for each xl sheet but we need single mail with all 3 sheets..help me ?
‎2019 May 03 8:20 PM
HI Try bellow code
FORM email_attachment .
DATA: lo_send_request TYPE REF TO cl_bcs,
lv_date(10),
lv_text TYPE char255, " Text
lv_subject TYPE so_obj_des,
lo_document TYPE REF TO cl_document_bcs,
lv_binary_content TYPE solix_tab,
lv_size TYPE so_obj_len,
lv_string TYPE string,
lt_main_text TYPE bcsy_text,
lo_recipient TYPE REF TO if_recipient_bcs,
lv_sent_to_all TYPE os_boolean,
lo_bcs_exception TYPE REF TO cx_bcs,
lv_email TYPE ad_smtpadr,
lv_lines TYPE i.
*Delimiters for spreadsheet attachment
CLASS:cl_abap_char_utilities DEFINITION LOAD.
CONSTANTS: gc_tab TYPE c VALUE cl_bcs_convert=>gc_tab,
gc_crlf TYPE c VALUE cl_bcs_convert=>gc_crlf.
DATA: gv_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
gv_newline TYPE c VALUE cl_abap_char_utilities=>newline,
gv_line_feed TYPE c VALUE cl_abap_char_utilities=>cr_lf.
DATA : BEGIN OF gt_up_file OCCURS 0,
line(255) TYPE c,
END OF gt_up_file.
WRITE sy-datum TO lv_date DD/MM/YYYY.
lv_lines = lines( gt_up_file ).
IF lv_lines GT 65000.
MESSAGE i000(zmm) WITH
'Report has more than 65,000 lines. Email cannot be'
'sent - Report can only be displayed.'
'In order to email report,'
'please change your selection criteria.'.
EXIT.
ENDIF.
LOOP AT gt_up_file . "you internal table
CONCATENATE lv_string gt_up_file gc_crlf gv_newline
INTO lv_string.
ENDLOOP.
* --------------------------------------------------------------
* convert the text string into UTF-16LE binary data including
* byte-order-mark. Mircosoft Excel prefers these settings
* all this is done by new class cl_bcs_convert (see note 1151257)
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_string
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
IMPORTING
et_solix = lv_binary_content
ev_size = lv_size ).
CATCH cx_bcs.
MESSAGE e445(so).
ENDTRY.
TRY.
* -------- create persistent send request ------------------------
lo_send_request = cl_bcs=>create_persistent( ).
* -------- create and set document with attachment ---------------
* create document object from internal table with text
lv_text = lv_date.
APPEND lv_text TO lt_main_text.
APPEND INITIAL LINE TO lt_main_text.
lv_text = 'REPORT Heading... '.
APPEND lv_text TO lt_main_text.
CONCATENATE 'Customer Price List' sy-datum sy-uzeit
INTO lv_subject SEPARATED BY '_'.
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_main_text
i_subject = lv_subject ).
* add the spread sheet as attachment to document object
lo_document->add_attachment(
i_attachment_type = 'XLS'
i_attachment_subject = lv_subject
i_attachment_size = lv_size
i_att_content_hex = lv_binary_content ).
* add document object to send request
lo_send_request->set_document( lo_document ).
* --------- add recipient (e-mail address) -----------------------
* create recipient object
LOOP AT s_ercpt.
lv_email = s_ercpt-low.
lo_recipient = cl_cam_address_bcs=>create_internet_address(
lv_email ).
* add recipient object to send request
lo_send_request->add_recipient( lo_recipient ).
ENDLOOP.
* ---------- send document ---------------------------------------
lv_sent_to_all = lo_send_request->send( i_with_error_screen = 'X' ).
COMMIT WORK.
IF lv_sent_to_all IS INITIAL.
MESSAGE s500(sbcoms) WITH ''.
ELSE.
MESSAGE s022(so).
ENDIF.
* ------------ exception handling ----------------------------------
CATCH cx_bcs INTO lo_bcs_exception.
MESSAGE i865(so) WITH lo_bcs_exception->error_type.
ENDTRY.
ENDFORM. " EMAIL_ATTACHMENT
‎2019 May 06 10:59 AM
thanks, and i got solution to ZIP the file and sent to User by using
cl_abap_zip class.