Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Submit a transaction O4B1 via job and the result as an attachment Excel

Hi, I'm executing a program in background via job to get back the result of a report as an attachment XLS on mail. the result of my program give me just title of Excel columns , but when i execute it manually , the result is perfect.

my code is : ******************************FORM MAIL******************************* FORM mail. CONCATENATE 'Expédition' 'TExp' 'PtOT' 'Crée' 'Crée le' 'St.' 'Déb. chargt' 'Désignation' 'Div.' 'Doc. vente' 'Réceptionnaire' 'Nom1' 'Nom2' 'Volume' 'UQ' INTO it_mess_att SEPARATED BY con_tab. CONCATENATE con_cret it_mess_att INTO it_mess_att. APPEND it_mess_att. CONCATENATE SPACE SPACE INTO it_mess_att SEPARATED BY con_tab. CONCATENATE con_cret it_mess_att INTO it_mess_att. APPEND it_mess_att. *CLEAR it_mess_att. LOOP AT it_tab into wa_tab. *VAL = it_tab-ZQTEMAX. CONCATENATE wa_tab-SHNUMBER wa_tab-SHTYPE wa_tab-TPLST wa_tab-CRE_NAME wa_tab-CRE_DATE wa_tab-OIG_SSTSF wa_tab-LOAD_STDTA wa_tab-VMODE_TEXT wa_tab-WERKS wa_tab-VBELN wa_tab-KUNNR wa_tab-NAME1 wa_tab-CARRIER_DE wa_tab-WGT_UOM INTO it_mess_att SEPARATED BY con_tab. CONCATENATE con_cret it_mess_att INTO it_mess_att. APPEND it_mess_att. *CLEAR it_mess_att. ENDLOOP. ENDFORM. *************************FORM SEND_MAIL******************************* FORM send_mail . DATA: send_request TYPE REF TO cl_bcs, document TYPE REF TO cl_document_bcs, recipient TYPE REF TO cl_cam_address_bcs, bcs_exception TYPE REF TO cx_bcs, sent_to_all TYPE os_boolean, lt_fields TYPE TABLE OF w3fields, lt_html TYPE TABLE OF w3html. DATA: ld_error TYPE sy-subrc, ld_reciever TYPE sy-subrc, ld_mtitle LIKE sodocchgi1-obj_descr, ld_email LIKE somlreci1-receiver, ld_format TYPE so_obj_tp , ld_attdescription TYPE sopcklsti1-obj_descr, ld_attfilename TYPE so_obj_des , ld_sender_address LIKE soextreci1-receiver, ld_sender_address_type LIKE soextreci1-adr_typ, ld_receiver LIKE sy-subrc. DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE, t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE, t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE, t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE, w_cnt TYPE i, w_sent_all(1) TYPE c, w_doc_data LIKE sodocchgi1. *MOVE p_email TO mailid. ***************ADD ADRESS MAIL************** p_email1-RECEIVER = mail . append p_email1. ********************************************* ld_email = mail. ld_mtitle = gd_attachment_desc. ld_format = 'XLS'. * ld_attdescription = gd_attachment_desc. ld_attdescription = 'Liste expéditions PN'. CONCATENATE ld_attdescription '.XLS' INTO ld_attfilename. * ld_attfilename = p_filename. ld_sender_address = w_sender. ld_sender_address_type = 'INT'. * Fill the document data. w_doc_data-doc_size = 1. * Populate the subject/generic message attributes w_doc_data-obj_langu = sy-langu. w_doc_data-obj_name = 'SAPRPT'. w_doc_data-obj_descr = ld_mtitle . w_doc_data-sensitivty = 'F'. * Fill the document data and get size of attachment CLEAR w_doc_data. READ TABLE it_mess_att INDEX 1. w_doc_data-doc_size = ( w_cnt - 1 ) * 255 + STRLEN( it_mess_att ). w_doc_data-obj_langu = sy-langu. w_doc_data-obj_name = 'SAPRPT'. w_doc_data-obj_descr = gd_attachment_desc. w_doc_data-sensitivty = 'F'. CLEAR t_attachment. REFRESH t_attachment. * t_attachment[] = it_attach[] . * Describe the body of the message clear t_packing_list. REFRESH t_packing_list. t_packing_list-transf_bin = space. t_packing_list-head_start = 1. t_packing_list-head_num = 0. t_packing_list-body_start = 1. DESCRIBE TABLE it_mess_bod LINES t_packing_list-body_num. t_packing_list-doc_type = 'RAW'. APPEND t_packing_list. * Create attachment notification t_packing_list-transf_bin = 'X'. t_packing_list-head_start = 1. t_packing_list-head_num = 1. t_packing_list-body_start = 1. DESCRIBE TABLE it_mess_att LINES t_packing_list-body_num. t_packing_list-doc_type = ld_format. t_packing_list-obj_descr = ld_attdescription. t_packing_list-obj_name = ld_attfilename. t_packing_list-doc_size = t_packing_list-body_num * 255. APPEND t_packing_list. * Add the recipients email address CLEAR t_receivers. REFRESH t_receivers. loop at p_email1. t_receivers-receiver = p_email1-receiver. t_receivers-rec_type = 'U'. t_receivers-com_type = 'INT'. t_receivers-notif_del = 'X'. t_receivers-notif_ndel = 'X'. APPEND t_receivers. endloop. CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = w_doc_data put_in_outbox = 'X' sender_address = ld_sender_address sender_address_type = ld_sender_address_type commit_work = 'X' IMPORTING sent_to_all = w_sent_all TABLES packing_list = t_packing_list contents_bin = it_mess_att contents_txt = it_mess_bod receivers = t_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. * Populate zerror return code ld_error = sy-subrc. * Populate zreceiver return code LOOP AT t_receivers. ld_receiver = t_receivers-retrn_code. ENDLOOP. WAIT UP TO 5 SECONDS. SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN. ENDFORM. " send_mail

Not what you were looking for? View more on this topic or Ask a question