#1
|
|||
|
|||
Enviar ALV en excel por mail
Hola a todos.
Tengo programado un listado el cúal muestra un ALV. Me piden que si el programa se ejecuta vía Job se envie dicho ALV en un excel por mail. ¿ Cómo puedo hacer ésto ??? Saludos y gracias a todos |
#2
|
|||
|
|||
Te pego el trozo de código que utilizo yo.
Como verás lo que hay que hacer es trasladar el contenido que vas a pasar al alv a una tabla interna en la que todos los campos son caracter y donde indicas la longitud máxima de los mismos. No te pongo la rutina seleccion_datos porque aquí simplemente obtengo los datos de la b.d. Espero que te sirva. Un saludo. DATA: BEGIN OF t_impresion OCCURS 0, factura LIKE VBRK-VBElN, fkart LIKE VBRK-FKART, END OF t_impresion. TYPES: BEGIN OF t_charekpo, factura(10) TYPE c, fkart(4) TYPE c, END OF t_charekpo. DATA: wa_charekpo TYPE t_charekpo. DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE. DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE. 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, gd_error TYPE sy-subrc, gd_reciever TYPE sy-subrc. END-OF-SELECTION perform seleccionar_datos. perform populate_email_message_body. * Send file by email as .xls speadsheet PERFORM send_file_as_email_attachment tables it_message it_attach using p_email 'INFORME FACTURADOS NO ENVIADOS' 'XLS' 'filename' mensaje ' ' ' ' changing gd_error gd_reciever. * Instructs mail send program for SAPCONNECT to send email(rsconn01) PERFORM initiate_mail_execute_program. *&---------------------------------------------------------------------* *& Form INITIATE_MAIL_EXECUTE_PROGRAM *&---------------------------------------------------------------------* * Instructs mail send program for SAPCONNECT to send email. *----------------------------------------------------------------------* FORM initiate_mail_execute_program. WAIT UP TO 2 SECONDS. SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN. ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM *&---------------------------------------------------------------------* *& Form BUILD_XLS_DATA_TABLE *&---------------------------------------------------------------------* * Build data table for .xls document *----------------------------------------------------------------------* FORM build_xls_data_table. "CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode " con_tab TYPE x VALUE '09'. "OK for non Unicode " *If you have Unicode check active in program attributes thnen you will *need to declare constants as follows *class cl_abap_char_utilities definition load. constants: con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB, con_cret type c value cl_abap_char_utilities=>CR_LF. DATA: fechaFactura(10) type c, fechaPedido(10) type c. CONCATENATE 'PEDIDO' 'F.PEDIDO' INTO it_attach SEPARATED BY con_tab. CONCATENATE con_cret it_attach INTO it_attach. APPEND it_attach. LOOP AT t_impresion. " * Tenemos que hacerlo así porque en un sistema UNICODE no se puede * pasar datos de tipo no string (p, i, f) a un carácter. MOVE-CORRESPONDING t_impresion TO wa_charekpo. CONCATENATE wa_charekpo-pedido fechaPedido INTO it_attach SEPARATED BY con_tab. CONCATENATE con_cret it_attach INTO it_attach. APPEND it_attach. ENDLOOP. ENDFORM. " BUILD_XLS_DATA_TABLE *&---------------------------------------------------------------------* *& Form INITIATE_MAIL_EXECUTE_PROGRAM *&---------------------------------------------------------------------* * Instructs mail send program for SAPCONNECT to send email. *----------------------------------------------------------------------* FORM initiate_mail_execute_program. WAIT UP TO 2 SECONDS. SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN. ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM *&---------------------------------------------------------------------* *& Form POPULATE_EMAIL_MESSAGE_BODY *&---------------------------------------------------------------------* * Populate message body text *----------------------------------------------------------------------* form populate_email_message_body. CLEAR mensaje. CONCATENATE 'Informe de facturados no enviados de' sfechaInicio sfechaFin INTO mensaje SEPARATED BY SPACE. REFRESH it_message. "it_message = 'Se adjunta el listado con los registros de facturados'. it_message = mensaje. APPEND it_message. endform. *&---------------------------------------------------------------------* *& Form SEND_FILE_AS_EMAIL_ATTACHMENT *&---------------------------------------------------------------------* * Send email *----------------------------------------------------------------------* FORM send_file_as_email_attachment tables pit_message pit_attach using p_email p_mtitle p_format p_filename p_attdescription p_sender_address p_sender_addres_type changing p_error p_reciever. 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 so_obj_nam , 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. ld_email = p_email. ld_mtitle = p_mtitle. ld_format = p_format. ld_attdescription = p_attdescription. ld_attfilename = p_filename. ld_sender_address = p_sender_address. ld_sender_address_type = p_sender_addres_type. * 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_attach INDEX w_cnt. w_doc_data-doc_size = ( w_cnt - 1 ) * 255 + STRLEN( it_attach ). 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'. CLEAR t_attachment. REFRESH t_attachment. t_attachment[] = pit_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_message 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 t_attachment 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. t_receivers-receiver = ld_email. "lista de distribución general: C "lista de distribución personal: P "dirección externa de correo U. t_receivers-rec_type = p_r_type. t_receivers-com_type = 'INT'. t_receivers-notif_del = 'X'. t_receivers-notif_ndel = 'X'. APPEND t_receivers. CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = w_doc_data "este es el asunto del mail put_in_outbox = 'X' "-> salida a sapoffice. 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 = t_attachment "contenido del alv. contents_txt = it_message "nombre archivo adjunto receivers = t_receivers "lista de destinatarios 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. ENDFORM. |
#3
|
|||
|
|||
Muchas gracias.
Me vale casi el 100% solo se me presenta un problema!!!! Mi tablita interna tiene un montón de campos y toda una fila me supera de largo los 255 caracteres posibles. ¿ Cómo podría solucionar ésto??? Saludos y muchsa gracias!!!!! |
#4
|
||||
|
||||
Hola, puedes pasar cada campo de tu tabla interna a otra tabla, por ejemplo, de una longitud de 300, y para separar cada campo, concatena todos los campos a un registro de la nueva tabla interna pero separalos por un tabulador, ese tabulador es de tipo hexadecimal
Yo lo hago asi: Donde pt_mdkp es una tabla interna con muchos campos, y lt_conten es una tabla interna con un solo campo de longuitud 1024, espero te pueda ayudar
__________________
David Carballido Córdova |
#5
|
|||
|
|||
Muchas gracias pero no me sirve.
La función que utilizo para enviar el mail es SO_NEW_DOCUMENT_ATT_SEND_API1 y la tablita interna donde tengo que ir formando mi excel es del tipo SOLISTI1, o sea, que cada línea debe tener como máximo 255 caracteres... Muchas gracias de todos modos!!!!! Saludos |
#6
|
|||
|
|||
Hola !
Me podrías decir cómo resolviste el problema?. Please!
|
Herramientas | Buscar en Tema |
Desplegado | |
|
|