Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

pdf file attach with mail

Hi ABAPers,

I am trying to send a PDF through mail . for that i am using the following code. but no result is coming.

Please help me.

  p_control_parameters-no_dialog = 'X'.
  p_control_parameters-getotf = 'X'.
 p_output_options-xsfcmode = 'X'.
  p_output_options-xsf = space.
  p_output_options-xdfcmode = 'X'.
  p_output_options-xdf = space.
  p_output_options-tdprinter = p_e_devtype.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
       EXPORTING
         formname                 = 'ZREQUEST_FORM'
*            VARIANT                  = ' '
*            DIRECT_CALL              = ' '
      IMPORTING
        fm_name                  = frm
*          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.

  CALL FUNCTION   frm                " '/1BCDWB/SF00000304'
                   EXPORTING
*                     ARCHIVE_INDEX              =
*                     ARCHIVE_INDEX_TAB          =
*                     ARCHIVE_PARAMETERS         =
                     control_parameters         =  p_control_parameters
*                     MAIL_APPL_OBJ              =
*                     MAIL_RECIPIENT             =
*                     MAIL_SENDER                =
                     output_options             =   p_output_options
                     user_settings              = 'X'
                   IMPORTING
*                     DOCUMENT_OUTPUT_INFO       =
                     job_output_info            = p_job_output_info
*                     JOB_OUTPUT_OPTIONS         =
          TABLES
            itab                       = itab
            it71                       = it71
*                   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.
  p_otf[] = p_job_output_info-otfdata[].

  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
      max_linewidth         = 132
    IMPORTING
      bin_filesize          = v_len_in
    TABLES
      otf                   = p_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.
    it_record = wa_buffer.
    APPEND it_record.
    SHIFT wa_buffer LEFT BY 255 PLACES.
    IF wa_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.

  it_objbin[] = it_record[].

  DESCRIBE TABLE it_table LINES v_lines.


*-----Create Message Body and Title and Description
  it_mess =
  'i have successfully converted smartform from otf format to pdf' .
  " and i have attached that in mail'.
  APPEND it_mess.
  wa_doc_data-obj_name = 'smartform'.
  wa_doc_data-expiry_dat = sy-datum + 10.
  wa_doc_data-obj_descr = 'smartform'.
  wa_doc_data-sensitivty = 'F'.
  wa_doc_data-doc_size = v_lines * 255.
  APPEND it_pcklist.

*-----PDF Attachment
  it_pcklist-transf_bin = 'X'.
  it_pcklist-head_start = 1.
  it_pcklist-head_num = 0.
  it_pcklist-body_start = 1.
  it_pcklist-doc_size = v_lines_bin * 255 .
  it_pcklist-body_num = v_lines.
  it_pcklist-doc_type = 'PDF'.
  it_pcklist-obj_name = 'SMARTFORM'.
  it_pcklist-obj_descr = 'smart_desc'.
  it_pcklist-obj_langu = 'E'.
  it_pcklist-doc_size = v_lines * 255.
  APPEND it_pcklist.

*-----Giving the receiver email-id
  CLEAR it_receivers.
  it_receivers-receiver = email1.
  it_receivers-rec_type = 'U'.
  APPEND it_receivers.
*CLEAR it_receivers.

*-----Calling the function module to sending email
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = wa_doc_data
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = it_pcklist
      contents_txt               = it_mess
      contents_hex               = it_table
      receivers                  = it_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.

  IF sy-subrc = 0.
    SUBMIT rsconn01 WITH mode = 'INT'
    WITH output = 'X'
    WITH rfcgroup = 'iwdf7ytc_YD3_94'
    AND RETURN.
    REFRESH: it_receivers,
    it_mess,
    it_pcklist.

  ENDIF.

Regards
Debjani

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question