Return to Snippet

Revision: 40862
at February 9, 2011 02:10 by gunshit


Initial Code
*&---------------------------------------------------------------------*
*&      Form  ENVIAR_FACTURA_EMAIL_PDF
*&---------------------------------------------------------------------*
form enviar_factura_email_pdf.
  data: itl_otf type standard table of itcoo with header line,
        itl_addrnum type standard table of zstr_addrnum with header line
        ,
        itl_smtp type standard table of adsmtp with header line.
  data: lv_asunto type tdtitle.
  data: lv_langu like kna1-spras.
  data: fact_text type standard table of zeessweb_text_det with header
  line.

  data: itl_soli type standard table of soli with header line,
        itl_objc type standard table of soli with header line.
  data: ind_updtask like sy-subrc,
        ind_commit  type xfeld.
*update1
  data: cuerpo_mensaje like tline occurs 0 with header line.
  data: asunto_aux type string.
  data: fecha_out(10) type c.
  data: fecha_in type sy-datum.
  data: texto_standar(70) type c.

  data wa_zcppcli_mail type zcppcli_mail.                   "INDRA_24

  itl_otf[] = otf[].


*
*  check sy-subrc = 0 .
*
*  if itl_smtp[] is initial.
*    retcode = 1.
*    syst-msgid = 'Z0'.
*    syst-msgno = '651'.
*    syst-msgty = 'E'.
*    syst-msgv1 = vbdkr-kunre.
*    syst-msgv2 = 'FACTUARENER'.
**    perform protocol_update. exit.
*  endif.


  perform convert_otf_pdf tables itl_otf
                                 itl_soli.

*Comprobamos que sea alguna de las clases de mensaje con este tipo de
*envío:
  check envio_email_ener = 'X'.

** Comprobamos que el Dest. Factura tenga la etiqueta 'FACTURAENER'
** y el email informado:
  call function 'Z_SID_LEER_COMM_ALERTAS'
    exporting
      im_kunnr = nast-parnr
      im_refer = 'FACTURAENER'
    tables
      tf_smtp  = itl_smtp.

*Si no tenemos dirección de email,
*entonces únicamente archivamos, no enviamos.
*  check itl_smtp[] is not initial.
  loop at itl_smtp.
    itl_addrnum-smtp_addr = itl_smtp-smtp_addr.
    append itl_addrnum.
  endloop.
* Leemos el idioma para el cuerpo de mail.
*  select single spras from kna1 into lv_langu
*                     where kunnr = vbdkr-kunre.
* En principio será siempre en español:
  lv_langu = 'S'.

* El cuerpo del mensaje depende de si el cliente tiene o no firmado el
* Acuerdo de Factura Electrónica:
 refresh cuerpo_mensaje.
 clear: cuerpo_mensaje, fecha_out, texto_standar.
* Para comprobar el acuerdo buscaremos el cliente en
* la tabla ZRTF_TERCERO con el acuerdo digital firmado
  select single * from zrtf_tercero
              where tercero = vbrk-kunrg
                and receptor = nast-parnr
                and flag = 'S'.

  if sy-subrc = 0.
*     Comprobamos la Org. Ventas:
      if vbrk-vkorg = '24ES'.
        texto_standar = 'Z_ENVIO_PDF_EMAIL_CES_F'.
      else.
        texto_standar = 'Z_ENVIO_PDF_EMAIL_F'.

      endif.

   else.
*     Comprobamos la Org. Ventas:
      if vbrk-vkorg = '24ES'.
        texto_standar = 'Z_ENVIO_PDF_EMAIL_CES'.
      else.
        texto_standar = 'Z_ENVIO_PDF_EMAIL'.

      endif.

  endif.

  call function 'READ_TEXT'
    exporting
*     CLIENT                        = SY-MANDT
      id                            = 'ST'
      language                      = lv_langu
      name                          = texto_standar
      object                        = 'TEXT'
*     ARCHIVE_HANDLE                = 0
*     LOCAL_CAT                     = ' '
*   IMPORTING
*     HEADER                        =
    tables
      lines                         = cuerpo_mensaje
*   EXCEPTIONS
*     ID                            = 1
*     LANGUAGE                      = 2
*     NAME                          = 3
*     NOT_FOUND                     = 4
*     OBJECT                        = 5
*     REFERENCE_CHECK               = 6
*     WRONG_ACCESS_TO_ARCHIVE       = 7
*     OTHERS                        = 8
            .


*  Convertimos la fecha
fecha_in = vbrk-fkdat.
write fecha_in using edit mask '__.__.____' to fecha_out.

loop at cuerpo_mensaje.



  replace first occurrence of 'IIIIIIIIII' in cuerpo_mensaje-tdline with
  nast-objky.
  replace first occurrence of 'DDDDDDDDDD' in cuerpo_mensaje-tdline with
  fecha_out.

  itl_objc = cuerpo_mensaje-tdline.
  append itl_objc.

endloop.

  call function 'TH_IN_UPDATE_TASK'
    importing
      in_update_task = ind_updtask.
  if ind_updtask is initial.
    ind_commit = 'X'.
  endif.
  asunto_aux = 'Factura: '.
  concatenate asunto_aux space nast-objky
  into lv_asunto separated by space.
* Envío de mail.
  call function 'Z_SID_ENVIO_FICH'
    exporting
      im_tipo_env          = 'INT'
      im_asunto            = lv_asunto
      im_remit             = '[email protected]'
      im_remit_type        = 'U'
      im_file_ext          = 'PDF'
      im_commit            = ind_commit
    tables
      tf_addrnum           = itl_addrnum
      tf_objcont           = itl_objc
      tf_soli              = itl_soli
    exceptions
      error_envio          = 1
      error_cuerpo_fax     = 2
      error_cuerpo_mail    = 3
      error_no_existe_fax  = 4
      error_no_existe_mail = 5
      error_tipo_envio     = 6
      others               = 7.

endform.                    " ENVIAR_FACTURA_EMAIL_PDF

Initial URL


Initial Description


Initial Title
ABAP - Enviar email (Factura en PDF)

Initial Tags


Initial Language
Other