Archivo

Posts Tagged ‘mails’

Adjuntar y enviar archivo Excel (XLS) por Mail

Caso: se desea adjuntar un archivo Excel y enviarlo por E-Mail.

Solución:

REPORT  zmail_con_excel.
 
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:   gv_email   TYPE somlreci1-receiver VALUE 'eduardo@eduardo.com'.
 
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.
 
TYPES: BEGIN OF tty_salida,
  sociedad        TYPE bukrs,   " Sociedad
  documento       TYPE belnr_d, " Nro. documento
  ejercicio       TYPE gjahr,   " Ejercicio
  periodo         TYPE monat,   " Período
  fecha_doc       TYPE bldat,   " Fecha doc.
  fecha_contable  TYPE budat,   " Fecha cont.
  clase_doc       TYPE blart,   " Clase doc.
  importe_ml      TYPE dmbtr,   " Importe ML
  usuario         TYPE sy-uname.    " Usuario
TYPES: END OF tty_salida.
 
DATA: gt_salida TYPE STANDARD TABLE OF tty_salida,
      gs_salida TYPE tty_salida.
 
 
START-OF-SELECTION.
* Registro de prueba
  gs_salida-sociedad       = '1000'.
  gs_salida-documento      = '1600000393'.
  gs_salida-ejercicio      = '2014'.
  gs_salida-periodo        = '10'.
  gs_salida-fecha_doc      = '20141022'.
  gs_salida-fecha_contable = '20141022'.
  gs_salida-clase_doc      = 'AB'.
  gs_salida-importe_ml     = '150000'.
  gs_salida-usuario        = sy-uname.
  APPEND gs_salida TO gt_salida.
 
END-OF-SELECTION.
 
  PERFORM armar_mail.
 
*&---------------------------------------------------------------------*
*&      Form  ARMAR_MAIL – Rutina Principal
*&---------------------------------------------------------------------*
FORM armar_mail .
 
*   Populate table with details to be entered into .xls file
  PERFORM build_xls_data_table.
 
* Populate message body text
  PERFORM populate_email_message_body.
 
* Send file by email as .xls speadsheet
  PERFORM send_file_as_email_attachment
                               TABLES it_message
                                      it_attach
                                USING gv_email
                                      'Asunto del mail!'
                                      'XLS'
                                      'Reporte'
                                      'Reporte'
                                      ' '
                                      ' '
                             CHANGING gd_error
                                      gd_reciever.
 
*   Instructs mail send program for SAPCONNECT to send email(rsconn01)
  PERFORM initiate_mail_execute_program.
 
ENDFORM.                    " ARMAR_MAIL
*&---------------------------------------------------------------------*
*&      Form  BUILD_XLS_DATA_TABLE
* Las etiquetas no pueden superar los 255 caracteres en una línea, esa es * una limitante pero al parecer hay formas de solucionarlo. Además todos * los tipos de datos deben ser caracteres.
*&---------------------------------------------------------------------*
FORM build_xls_data_table .
  DATA: lv_importe_ml_char        TYPE char15,
        lv_importe_md_char        TYPE char15,
        lv_tc_cab_char            TYPE char11,
        lv_tc_pos_char            TYPE char11,
        lv_dif_tc_reg_char        TYPE char13,
        lv_dif_porcentaje_char    TYPE char11,
        lv_tc_obs_char            TYPE char11,
        lv_dif_tc_reg_b_char      TYPE char13,
        lv_dif_porcentaje_b_char  TYPE char11.
 
  CONSTANTS:
    con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
    con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
 
  CONCATENATE 'Sociedad' 'Nro Documento' 'Ejer.' 'Periodo' 'Fecha Doc.' 'Fecha Cont.' 'Clase Doc.'
              'Importe ML' 'User'
          INTO it_attach SEPARATED BY con_tab.
 
  CONCATENATE con_cret it_attach  INTO it_attach.
  APPEND  it_attach.
 
  LOOP AT gt_salida INTO gs_salida.
    MOVE gs_salida-importe_ml TO lv_importe_ml_char.
    CONDENSE lv_importe_ml_char NO-GAPS.
 
    CONCATENATE gs_salida-sociedad gs_salida-documento gs_salida-ejercicio gs_salida-periodo gs_salida-fecha_doc
                gs_salida-fecha_contable gs_salida-clase_doc lv_importe_ml_char gs_salida-usuario
           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  POPULATE_EMAIL_MESSAGE_BODY
*&---------------------------------------------------------------------*
FORM populate_email_message_body .
 
  REFRESH it_message.
  it_message = 'Cuerpo del mensaje (body)!'.
  APPEND it_message.
 
ENDFORM.                    " POPULATE_EMAIL_MESSAGE_BODY
 
*&---------------------------------------------------------------------*
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
FORM send_file_as_email_attachment  TABLES pit_message
                                          pit_attach
                                    USING gv_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               = gv_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.
  t_receivers-rec_type   = 'U'.
  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
      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               = t_attachment
      contents_txt               = it_message
      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.
 
ENDFORM.                    " SEND_FILE_AS_EMAIL_ATTACHMENT
 
*&---------------------------------------------------------------------*
*&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
FORM initiate_mail_execute_program .
 
  WAIT UP TO 3 SECONDS.
  SUBMIT rsconn01 WITH mode = 'INT'
                  WITH output = 'X'
                  AND RETURN.
 
ENDFORM.                    " INITIATE_MAIL_EXECUTE_PROGRAM
Anuncios

Enviar E-Mail – Mejor forma

Caso: buscando encontré este código para envío de mail, muy correcto y simple.

Solución: Lo hice en una función

FUNCTION z_envio_mail.
*"----------------------------------------------------------------------
*"*"Interfase local
*"  IMPORTING
*"     REFERENCE(I_SUBJECT) TYPE  SO_OBJ_DES OPTIONAL
*"     REFERENCE(I_BODY) TYPE  BCSY_TEXT OPTIONAL
*"     REFERENCE(I_TYPE_DOC) TYPE  SO_OBJ_TP OPTIONAL
*"     REFERENCE(I_SENDER) TYPE  AD_SMTPADR OPTIONAL
*"     REFERENCE(I_RECEIVERS) TYPE  BCSY_SMTPA
*"----------------------------------------------------------------------
 
  DATA: lo_send_request   TYPE REF TO cl_bcs,
        lo_bcs_exception  TYPE REF TO cx_bcs,
        lo_document       TYPE REF TO cl_document_bcs,
        lo_sender         TYPE REF TO if_sender_bcs,
        lo_recipient      TYPE REF TO if_recipient_bcs,
        lit_message_body  TYPE bcsy_text,
        lx_document_bcs   TYPE REF TO cx_document_bcs,
        lv_sent_to_all    TYPE os_boolean,
        lv_sender         TYPE adr6-smtp_addr,
        lv_uname          TYPE uname,
        lv_emailadd       TYPE adr6-smtp_addr,
        wa_receivers      TYPE LINE OF bcsy_smtpa,
        lv_sub            TYPE so_obj_des,
        lv_subrc          TYPE sy-subrc,
        lv_error          TYPE string.
 
  TRY.
      lo_send_request = cl_bcs=>create_persistent( ).
*************** Subject      *****************************************
      CLEAR lv_sub.
      lv_sub = i_subject. " Asunto
*************** Message Body *****************************************
      REFRESH:lit_message_body.
      lit_message_body[] = i_body[].
 
*     put your text into the document
      IF i_type_doc IS NOT INITIAL.
        lo_document = cl_document_bcs=>create_document(
                         i_type     = i_type_doc
                         i_text     = lit_message_body
                         i_subject  = lv_sub ).
      ELSE.
        lo_document = cl_document_bcs=>create_document(
                         i_type     = 'RAW'
                         i_text     = lit_message_body
                         i_subject  = lv_sub ).
      ENDIF.
*************** Create sender *****************************************
      lv_sender = i_sender.                               " 'remitente@mail.com'.
      IF lv_sender IS INITIAL.
        lo_sender = cl_sapuser_bcs=>create( sy-uname ).
      ELSE.
        lo_sender = cl_cam_address_bcs=>create_internet_address( lv_sender ).
      ENDIF.
 
*         Set sender
      lo_send_request->set_sender( lo_sender ).
 
*************** Create Receiver *****************************************
      LOOP AT i_receivers INTO wa_receivers.
        lv_emailadd = wa_receivers. " destinatario@mail.com
        lo_recipient = cl_cam_address_bcs=>create_internet_address(
                                lv_emailadd  ).
 
*           Add recipient object to send request
        CALL METHOD lo_send_request->add_recipient
          EXPORTING
            i_recipient = lo_recipient
            i_express   = 'X'.
      ENDLOOP.
*************** Send Email *****************************************
      lo_send_request->set_document( lo_document ).
 
      lo_send_request->send(
        EXPORTING
          i_with_error_screen = 'X'
        RECEIVING
          result = lv_sent_to_all ).
 
      COMMIT WORK.
 
      IF lv_sent_to_all IS INITIAL.
        lv_subrc = '1'.
      ELSE.
        CLEAR lv_subrc.
      ENDIF.
 
    CATCH cx_bcs  INTO lo_bcs_exception.
      lv_error = lo_bcs_exception->get_text( ).
      lv_subrc = '1'.
 
  ENDTRY.
 
ENDFUNCTION.

Link: http://www.patelashish.com/wordpress/2013/08/abap-code-best-way-series-send-email/

Categorías:ABAP/4 Etiquetas: , , , ,

Eliminar/depurar SAP Business Workplace

Caso: luego de la reincorporación de un usuario, la carpeta de SBW estaba llena de archivos/mails internos.

Solución Para la depuración del SAP Business Workplace, se debe correr el programa RSSODLIN desde la transacción SA38.

Ingresar el nombre de usuario y las carpetas sobre las cuales de debe depurar.

Destildar la opcion “Ejecutar como test”.

A modo de ejemplo se selecciono la depuración de la carpeta “Salida”, “Archivo personal sólo documentos” y “Archivo personal documentos y carpetas”

Importante: analizar que carpeta se va a depurar ya que borra todo el contenido de la misma.

Al final el proceso indica el usuario, la carpeta y el resultado de la operación.

Categorías:ABAP/4 Etiquetas: , ,