Sent Mail PDF Attachment

Some Time Requirement to send mail as PDF attachments below peace of 
code send mail as PDF attachment to user so try to write code and test yourself as pdf attachment 
code 




DATA : lv_credit_note TYPE zcredti_note_n,
         lv_post_docu   TYPE char10,
         e_devtype  TYPE  rspoptype.

  lv_credit_note = p_l_number1.
  lv_post_docu = p_lv_obj_key+0(10).
* Internal Table declarations
  DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
        i_tline TYPE TABLE OF tline WITH HEADER LINE,
        i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
        i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
* Objects to send mail.
        i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
        i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
        i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
        i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
* Work Area declarations
        wa_objhead TYPE soli_tab,
        w_ctrlop TYPE ssfctrlop,
        w_compop TYPE ssfcompop,
        w_return TYPE ssfcrescl,
        wa_doc_chng TYPE sodocchgi1,
        w_data TYPE sodocchgi1,
        wa_buffer TYPE string, "To convert from 132 to 255
* Variables declarations
        v_form_name TYPE rs38l_fnam,
        v_len_in LIKE sood-objlen,
        v_len_out LIKE sood-objlen,
        v_len_outn TYPE i,
        v_lines_txt TYPE i,
        v_lines_bin TYPE i.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = 'ZSD_DELIVERY_ORDER'
    IMPORTING
      fm_name            = v_form_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  w_ctrlop-getotf = 'X'.
  w_ctrlop-no_dialog = 'X'.
  w_ctrlop-preview = space.
  w_ctrlop-device = 'PRINTER'.
*  w_compop-tdnoprev = 'X'.
  CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
    EXPORTING
      i_language             = 'E'
    IMPORTING
      e_devtype              = e_devtype
    EXCEPTIONS
      no_language            = 1
      language_not_installed = 2
      no_devtype_found       = 3
      system_error           = 4
      OTHERS                 = 5.

  w_compop-tdprinter = e_devtype.

  CALL FUNCTION v_form_name
    EXPORTING
      control_parameters = w_ctrlop
      output_options     = w_compop
*     user_settings      = 'X'
      s_cnumb            = ' '
      s_fnumb            = lv_post_docu
    IMPORTING
      job_output_info    = w_return
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  i_otf[] = w_return-otfdata[].
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
      max_linewidth         = 132
    IMPORTING
      bin_filesize          = v_len_in
    TABLES
      otf                   = i_otf
      lines                 = i_tline
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      OTHERS                = 4.
  IF sy-subrc <> 0.
  ENDIF.
  LOOP AT i_tline.
    TRANSLATE i_tline USING '~'.
    CONCATENATE wa_buffer i_tline INTO wa_buffer.
  ENDLOOP.
  TRANSLATE wa_buffer USING '~'.
  DO.
    i_record = wa_buffer.
    APPEND i_record.
    SHIFT wa_buffer LEFT BY 255 PLACES.
    IF wa_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
* Attachment
  REFRESH: i_reclist,
  i_objtxt,
  i_objbin,
  i_objpack.
  CLEAR wa_objhead.
  i_objbin[] = i_record[].
* Create Message Body Title and Description
  i_objtxt = 'Delivery Order  pdf-Attachment!'.
  APPEND i_objtxt.
  DESCRIBE TABLE i_objtxt LINES v_lines_txt.
  READ TABLE i_objtxt INDEX v_lines_txt.
  wa_doc_chng-obj_name = 'Delivery Order'.
  wa_doc_chng-expiry_dat = sy-datum + 10.
  wa_doc_chng-obj_descr = 'Delivery Order'.
  wa_doc_chng-sensitivty = 'F'.
  wa_doc_chng-doc_size = v_lines_txt * 255.
* Main Text
  CLEAR i_objpack-transf_bin.
  i_objpack-head_start = 1.
  i_objpack-head_num = 0.
  i_objpack-body_start = 1.
  i_objpack-body_num = v_lines_txt.
  i_objpack-doc_type = 'RAW'.
  APPEND i_objpack.
* Attachment (pdf-Attachment)
  i_objpack-transf_bin = 'X'.
  i_objpack-head_start = 1.
  i_objpack-head_num = 0.
  i_objpack-body_start = 1.
  DESCRIBE TABLE i_objbin LINES v_lines_bin.
  READ TABLE i_objbin INDEX v_lines_bin.
  i_objpack-doc_size = v_lines_bin * 255 .
  i_objpack-body_num = v_lines_bin.
  i_objpack-doc_type = 'PDF'.
  i_objpack-obj_name = 'smart'.
  i_objpack-obj_descr = 'Delivery Order'.
  APPEND i_objpack.
  CLEAR i_reclist.
  i_reclist-receiver = 'rkm4888@gmail.com'.
  i_reclist-rec_type = 'U'.
  APPEND i_reclist.
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = wa_doc_chng
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = i_objpack
      object_header              = wa_objhead
      contents_bin               = i_objbin
      contents_txt               = i_objtxt
      receivers                  = i_reclist
    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 <> 0.
*    WRITE:/ 'Error When Sending the File', sy-subrc.
  ELSE.
    MESSAGE 'Mail sent' TYPE 'S'.
  ENDIF.
*********************************************** ZSD CREDIT NOT SMARTFORMS **********************************************************
  REFRESH: i_objpack[], wa_objhead[],i_objbin[],i_objtxt[],i_reclist[].
  CLEAR:wa_doc_chng,i_record,w_ctrlop,w_compop.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = 'ZSD_CREDITNOTE'
    IMPORTING
      fm_name            = v_form_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  w_ctrlop-getotf = 'X'.
  w_ctrlop-no_dialog = 'X'.
  w_ctrlop-preview = space.
  w_ctrlop-device = 'PRINTER'.
*  w_compop-tdnoprev = 'X'.
  CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
    EXPORTING
      i_language             = 'E'
    IMPORTING
      e_devtype              = e_devtype
    EXCEPTIONS
      no_language            = 1
      language_not_installed = 2
      no_devtype_found       = 3
      system_error           = 4
      OTHERS                 = 5.

  w_compop-tdprinter = e_devtype.

**CALL FUNCTION '/1BCDWB/SF00000759'
**  EXPORTING
***   ARCHIVE_INDEX              =
***   ARCHIVE_INDEX_TAB          =
***   ARCHIVE_PARAMETERS         =
***   CONTROL_PARAMETERS         =
***   MAIL_APPL_OBJ              =
***   MAIL_RECIPIENT             =
***   MAIL_SENDER                =
***   OUTPUT_OPTIONS             =
***   USER_SETTINGS              = 'X'
**    s_cnumb                    =
**    s_finumb                   =
*** IMPORTING
***   DOCUMENT_OUTPUT_INFO       =
***   JOB_OUTPUT_INFO            =
***   JOB_OUTPUT_OPTIONS         =
*** EXCEPTIONS
***   FORMATTING_ERROR           = 1
***   INTERNAL_ERROR             = 2
***   SEND_ERROR                 = 3
***   USER_CANCELED              = 4
***   OTHERS                     = 5
  .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  CALL FUNCTION v_form_name
    EXPORTING
      control_parameters = w_ctrlop
      output_options     = w_compop
*     user_settings      = 'X'
      s_cnumb            = lv_credit_note
      s_finumb           = ' '
    IMPORTING
      job_output_info    = w_return
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  i_otf[] = w_return-otfdata[].
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
      max_linewidth         = 132
    IMPORTING
      bin_filesize          = v_len_in
    TABLES
      otf                   = i_otf
      lines                 = i_tline
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      OTHERS                = 4.
  IF sy-subrc <> 0.
  ENDIF.
  LOOP AT i_tline.
    TRANSLATE i_tline USING '~'.
    CONCATENATE wa_buffer i_tline INTO wa_buffer.
  ENDLOOP.
  TRANSLATE wa_buffer USING '~'.
  DO.
    i_record = wa_buffer.
    APPEND i_record.
    SHIFT wa_buffer LEFT BY 255 PLACES.
    IF wa_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
* Attachment
  REFRESH: i_reclist,
  i_objtxt,
  i_objbin,
  i_objpack.
  CLEAR wa_objhead.
  i_objbin[] = i_record[].
* Create Message Body Title and Description
  i_objtxt = 'Credit Note  pdf-Attachment!'.
  APPEND i_objtxt.
  DESCRIBE TABLE i_objtxt LINES v_lines_txt.
  READ TABLE i_objtxt INDEX v_lines_txt.
  wa_doc_chng-obj_name = 'Credit Note'.
  wa_doc_chng-expiry_dat = sy-datum + 10.
  wa_doc_chng-obj_descr = 'Credit Note'.
  wa_doc_chng-sensitivty = 'F'.
  wa_doc_chng-doc_size = v_lines_txt * 255.
* Main Text
  CLEAR i_objpack-transf_bin.
  i_objpack-head_start = 1.
  i_objpack-head_num = 0.
  i_objpack-body_start = 1.
  i_objpack-body_num = v_lines_txt.
  i_objpack-doc_type = 'RAW'.
  APPEND i_objpack.
* Attachment (pdf-Attachment)
  i_objpack-transf_bin = 'X'.
  i_objpack-head_start = 1.
  i_objpack-head_num = 0.
  i_objpack-body_start = 1.
  DESCRIBE TABLE i_objbin LINES v_lines_bin.
  READ TABLE i_objbin INDEX v_lines_bin.
  i_objpack-doc_size = v_lines_bin * 255 .
  i_objpack-body_num = v_lines_bin.
  i_objpack-doc_type = 'PDF'.
  i_objpack-obj_name = 'smart'.
  i_objpack-obj_descr = 'Credit Note'.
  APPEND i_objpack.
  CLEAR i_reclist.
  i_reclist-receiver = 'rkm4888@gmail.com'.
  i_reclist-rec_type = 'U'.
  APPEND i_reclist.
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = wa_doc_chng
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = i_objpack
      object_header              = wa_objhead
      contents_bin               = i_objbin
      contents_txt               = i_objtxt
      receivers                  = i_reclist
    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 <> 0.
*    WRITE:/ 'Error When Sending the File', sy-subrc.
  ELSE.
    MESSAGE 'Mail sent' TYPE 'S'.
  ENDIF.

Comments

Popular posts from this blog

Business senario : FB60 AND FB70 validation and subsituation

MB_MIGO_BADI THIS BADI USED TO POSTING DATA IN MIGO

all user exit mv45afzz (implicit user exit )