FORM enviar_mail_aviso.
MESSAGE s499 WITH 'Envio Mail'.
* Data Declaration
DATA: wa_docdata TYPE sodocchgi1,
wa_objpack TYPE sopcklsti1 ,
it_objpack TYPE TABLE OF sopcklsti1,
wa_objtxt TYPE solisti1,
it_objtxt TYPE TABLE OF solisti1,
wa_reclist TYPE somlreci1,
it_reclist TYPE TABLE OF somlreci1.
DATA: tab_lines TYPE i.
* Cabecera
wa_objtxt = '<SPAN style="font-family:arial;font-size:10.5pt;color:black">'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt = 'Estimados: <BR>'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt = 'Los siguientes colaboradores se encuentran desvinculados de'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt = 'la compañía. Favor informar deudas pendientes a la brevedad.<BR><BR><BR>'.
APPEND wa_objtxt TO it_objtxt.
wa_objtxt = '<SPAN>'.
APPEND wa_objtxt TO it_objtxt.
* Detalle
wa_objtxt = '<table border=1 cellspacing=0 cellpadding=2 bordercolor="666666"><tr>'.APPEND wa_objtxt TO it_objtxt.
wa_objtxt = '<th scope="col" bgcolor="666666">Cod. Personal</th>'.APPEND wa_objtxt TO it_objtxt.
wa_objtxt = '<th scope="col" bgcolor="666666">Nombre</th>'.APPEND wa_objtxt TO it_objtxt.
wa_objtxt = '<th scope="col" bgcolor="666666">DNI</th>'.APPEND wa_objtxt TO it_objtxt.
wa_objtxt = '<th scope="col" bgcolor="666666">Fecha Alta</th>'.APPEND wa_objtxt TO it_objtxt.
wa_objtxt = '<th scope="col" bgcolor="666666">Fecha Baja</th>'.APPEND wa_objtxt TO it_objtxt.
wa_objtxt = '<th scope="col" bgcolor="666666">Div. Personal</th>'.APPEND wa_objtxt TO it_objtxt.
"Nueva Fila
LOOP AT it_salida.
wa_objtxt = '</tr><tr>'.APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td>' it_salida-pernr '</td>' INTO wa_objtxt.APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td>' it_salida-fname '</td>' INTO wa_objtxt.APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td>' it_salida-perid '</td>' INTO wa_objtxt.APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td>' it_salida-f_alta+6(2) '.'
it_salida-f_alta+4(2) '.'
it_salida-f_alta+0(4) ''
'</td>' INTO wa_objtxt.
APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td>' it_salida-f_baja+6(2) '.'
it_salida-f_baja+4(2) '.'
it_salida-f_baja+0(4) ''
'</td>' INTO wa_objtxt.
APPEND wa_objtxt TO it_objtxt.
CONCATENATE '<td>' it_salida-werks '</td>' INTO wa_objtxt.APPEND wa_objtxt TO it_objtxt.
ENDLOOP.
"Fin de la Tabla
wa_objtxt = '</tr></table>'.APPEND wa_objtxt TO it_objtxt.
*
DESCRIBE TABLE it_objtxt LINES tab_lines.
READ TABLE it_objtxt INTO wa_objtxt INDEX tab_lines.
wa_docdata-obj_name = 'Notificación'.
wa_docdata-obj_descr = 'Nuevas Desvinculaciones'.
wa_docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( wa_objtxt ).
CLEAR wa_objpack-transf_bin.
wa_objpack-head_start = 1.
wa_objpack-head_num = 0.
wa_objpack-body_start = 1.
wa_objpack-body_num = tab_lines.
wa_objpack-doc_type = 'HTM'.
APPEND wa_objpack TO it_objpack.
*
*create receiver list
"- Inbox SAP
* wa_reclist-receiver = SY-UNAME.
* wa_reclist-rec_type = 'B'.
"- Correo Externo
wa_reclist-receiver = 'abaperohr@gmail.com'.
wa_reclist-rec_type = 'U'.
APPEND wa_reclist TO it_reclist.
*send_mail .
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = wa_docdata
put_in_outbox = 'X'"' '
commit_work = 'X'
TABLES
packing_list = it_objpack
contents_txt = it_objtxt
receivers = it_reclist
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.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1.
ELSE.
WRITE : / 'Mail sent to', sy-uname.
ENDIF.
ENDFORM. " send_mail