TABLES : ZXXX , VBUK.
TYPE-POOLS : szadr.
data : BEGIN OF itab OCCURS 0,
       XXX like zxxx-xxx,
       YYY like zxxx-yyy,
       Status(5TYPE c,
       END OF itab.
DATA : control_parameters TYPE ssfctrlop,
       mail_recipient TYPE swotobjid,
       mail_sender TYPE swotobjid,
       output_options TYPE ssfcompop,
       lvs_comm_type TYPE  ad_comm       ,
       lvs_comm_values TYPE  szadr_comm_values,
       lvs_itcpo LIKE  itcpo,
       lvf_device(50).
DATA: lt_mailrecipients  TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE,
      lt_mailtxt         TYPE STANDARD TABLE OF soli      WITH HEADER LINE,
      lt_attachment      TYPE STANDARD TABLE OF solisti1  WITH HEADER LINE,
      lt_mailsubject     TYPE sodocchgi1,
      lt_packing_list    TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,
      gv_cnt             TYPE i.
SELECT from zxxx into CORRESPONDING FIELDS OF TABLE itab
  WHERE DATUM eq sy-datum.
loop at itab.
select single from vbuk
                    where vbeln itab-vbeln.
CHECK vbuk-wbstk 'C'.
delete itab WHERE vbeln itab-vbeln.
ENDLOOP.
loop at itab.
  itab-status 'OPEN'.
  MODIFY itab.
ENDLOOP.
if not itab[] is INITIAL.
lt_mailrecipients-rec_type  'U'.
lt_mailrecipients-com_type  'INT'.
lt_mailrecipients-RECEIVER  'cc@cc.com'.
APPEND lt_mailrecipients .
CLEAR lt_mailrecipients .
lt_mailtxt 'Your own words'.
APPEND lt_mailtxt.
CLEAR lt_mailtxt.
lt_mailtxt 'your own words'.
APPEND lt_mailtxt.
CLEAR lt_mailtxt.
  CLASS cl_abap_char_utilities DEFINITION LOAD.
  CONCATENATE 'xxx' 'yyy' 'zzz' ''
              INTO lt_attachment SEPARATED BY
              cl_abap_char_utilities=>horizontal_tab.
  APPEND lt_attachment.
  CLEAR lt_attachment.
  LOOP AT itab.
  CONCATENATE itab-xxx itab-yyy itab-status
              INTO lt_attachment SEPARATED BY
              cl_abap_char_utilities=>horizontal_tab.
  CONCATENATE cl_abap_char_utilities=>newline lt_attachment
              INTO lt_attachment.
  APPEND lt_attachment.
  CLEAR lt_attachment.
 ENDLOOP.
  lt_packing_list-transf_bin  SPACE.
  lt_packing_list-head_start  1.
  lt_packing_list-head_num    0.
  lt_packing_list-body_start  1.
  lt_packing_list-body_num    LINESlt_mailtxt ).
  lt_packing_list-doc_type    'RAW'.
  APPEND lt_packing_list.
  CLEAR lt_packing_list.
  lt_packing_list-transf_bin  'X'.
  lt_packing_list-head_start  1.
  lt_packing_list-head_num    1.
  lt_packing_list-body_start  1.
  lt_packing_list-body_num    LINESlt_attachment ).
  lt_packing_list-doc_type    'XLS'.
  lt_packing_list-obj_name    'data.xls'.
  lt_packing_list-obj_descr   'data.xls'.
  lt_packing_list-doc_size    lt_packing_list-body_num * 255.
  APPEND lt_packing_list.
  CLEAR lt_packing_list.
  lt_mailsubject-obj_name     'MAILATTCH'.
  lt_mailsubject-obj_langu    sy-langu.
  lt_mailsubject-obj_descr    'Email Description'.
  lt_mailsubject-sensitivty   'F'.
  gv_cnt LINESlt_attachment ).
  lt_mailsubject-doc_size     = ( gv_cnt 255 STRLEN(
  lt_attachment ).
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              lt_mailsubject
    TABLES
      packing_list               lt_packing_list
      contents_bin               lt_attachment
      contents_txt               lt_mailtxt
      receivers                  lt_mailrecipients
    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.
  IF sy-subrc EQ 0.
    COMMIT WORK.
    SUBMIT rsconn01 WITH MODE 'INT' AND RETURN.
  ENDIF.
endif.


Serkan AKKAVAK
Computer Engineer
serkurumsal@yandex.com