cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in opening attached PDF file in SAP Inbox

Former Member
0 Kudos

Hi experts,

I am facing a problem in email sending with PDF as attachment.

Actually my reqirement  is to pass data from web dynpro to smartform and covert this smartform to pdf.

After converting to PDF it should be sent to email with this PDF as attachment.

Till converting to PDF i was successful and i was also able to send email with PDF as attachment.

but  i am not able to open this PDF file in the sent email(SAP Inbox).

I have noticed in debugging that one of the parameter(Table:: LINES )in FM Convert_OTF is showing Initial?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Venkat,

First of all you have to be sure that your smartforms is returning data:

   CALL FUNCTION fm_name
          EXPORTING
            control_parameters = ssfctrlop
            output_options     = ssfcompop
          IMPORTING
            job_output_info    = it_otf_data

Check in debug if it_otf_data-otfdata[] is not initial.

After that do the conversion:

   

     it_otf_final[] = it_otf_data-otfdata[].

    CALL FUNCTION 'CONVERT_OTF'
      EXPORTING
        format = 'PDF'
      IMPORTING
        bin_filesize = bin_filesize
* bin_file =
      TABLES
        otf = it_otf_final
        lines = it_pdfdata[]
      EXCEPTIONS

If it_pdfdata[] is not initial continue with (check after that the content of it_pdf[] 😞

        CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
        EXPORTING
          line_width_dst              = '255'
        TABLES
          content_in                  = it_pdfdata[]
          content_out                 = it_pdf[]
        EXCEPTIONS
          err_line_width_src_too_long = 1
          err_line_width_dst_too_long = 2
          err_conv_failed             = 3
          OTHERS                      = 4.
      IF sy-subrc <> 0.
      ELSE.

this conversion bellow in binary_content variable is only for sending email with cl_bcs_document class

         TRY.

            CLEAR: binary_content, size.
            CALL METHOD cl_bcs_convert=>soli_to_solix
              EXPORTING
                it_soli  = it_pdf[]
              RECEIVING
                et_solix = binary_content.
......

if you use FM: SO_NEW_DOCUMENT_ATT_SEND_API1 to send email you can call like this:

        CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
          EXPORTING
            document_data              = w_document_data
            put_in_outbox              = 'X'
            commit_work                = 'X'
          IMPORTING
            sent_to_all                = g_sent_to_all
          TABLES
            packing_list               = i_packing_list
            contents_bin               = it_pdf
            contents_txt               = i_body_msg
            receivers                  = i_receivers

..............

Regards,

Catalin

Former Member
0 Kudos

Hi Catalin,

Thank you very much for your quick response.

I am sure that my  smartform is returning data.

After commenting the parameter bin_file ,now i am able to see the PDF attachment and open the attachment.

With the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1' i was able to see email in SAP inbox but not in SOST transaction.?

Also i have not used any cl_bcs_document class.

Two things i need

one is i should receive an email in SOST transaction only

second is my pdf should be opened.

I will also post my code below.

*CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

*EXPORTING

*line_width_dst = '255'

*TABLES

*content_in     = wd_this->lt_dummy

*content_out    = it_pdf[].

*IF sy-subrc = 0.

*

*"Subject of the mail.

*w_document_data-obj_name  = 'MAIL_TO_HEAD'.

*w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.

*"Body of the mail

*w_body_msg = 'This is body of mail msg.'.

*APPEND w_body_msg TO i_body_msg.

*CLEAR  w_body_msg.

*"Write Packing List for Body

*DESCRIBE TABLE i_body_msg LINES g_tab_lines.

*w_packing_list-head_start = 1.

*w_packing_list-head_num   = 0.

*w_packing_list-body_start = 1.

*w_packing_list-body_num   = g_tab_lines.

*w_packing_list-doc_type   = 'RAW'.

*APPEND w_packing_list TO i_packing_list.

*CLEAR  w_packing_list.

*"Write Packing List for Attachment

*w_packing_list-transf_bin = 'X'.

*w_packing_list-head_start = 1.

*w_packing_list-head_num   = 1.

*w_packing_list-body_start = 1.

*DESCRIBE TABLE it_pdf LINES w_packing_list-body_num.

*w_packing_list-doc_type   = 'PDF'.

*w_packing_list-obj_descr  = 'PDF Attachment'.

*w_packing_list-obj_name   = 'PDF_ATTACHMENT'.

*w_packing_list-doc_size   = w_packing_list-body_num * 255.

*APPEND w_packing_list TO i_packing_list.

*CLEAR  w_packing_list.

*"Fill the document data and get size of attachment

*w_document_data-obj_langu  = sy-langu.

*READ TABLE it_pdf INTO w_pdf INDEX g_tab_lines.

*w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).

*"Receivers List.

*w_receivers-rec_type   = 'B'."Internet address

*w_receivers-receiver   = 'LZJYQC'.

*w_receivers-com_type   = 'INT'.

*w_receivers-notif_del  = 'X'.

*w_receivers-notif_ndel = 'X'.

*APPEND w_receivers TO i_receivers .

*CLEAR:w_receivers.

*"Function module to send mail to Recipients

*CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

*EXPORTING

*document_data              = w_document_data

*put_in_outbox              = 'X'

*commit_work                = 'X'

*IMPORTING

*sent_to_all                = g_sent_to_all

*TABLES

*packing_list               = i_packing_list

*contents_bin               = it_pdf

*contents_txt               = i_body_msg

*receivers                  = i_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 .

*MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.

*ENDIF.

*

*ENDIF.

Former Member
0 Kudos

Hi Venkat,

First, thanks for SOST tcode (I did some work for a client which permit only internal mails in their mail domain and I could not see the result of the tests . I allways had to ask somebody to confirm if the attachment is ok). No with SOST I can see the result of the tests.

I use this code bellow and I'm able to see in SBWP the PDF attachment (not in SOST - probably is only for external mail, faxes, etc not for SAP mail):

DATA: it_nfal TYPE nfal OCCURS 0 WITH HEADER LINE.
DATA: fm_name TYPE rs38l_fnam.
DATA: ssfctrlop TYPE ssfctrlop.
DATA: ssfcompop TYPE ssfcompop.
DATA: it_otf_data TYPE ssfcrescl.
DATA: it_otf_final TYPE itcoo OCCURS 0 WITH HEADER LINE.
DATA: bin_filesize TYPE i.
DATA: it_pdfdata TYPE TABLE OF tline.
DATA: it_pdf TYPE TABLE OF solisti1.

* MAIL RELATED DECLARATIONS
DATA : g_sent_to_all TYPE sonv-flag,
g_tab_lines TYPE i.

TYPES: t_document_data TYPE sodocchgi1,
t_packing_list TYPE sopcklsti1,
t_attachment TYPE solisti1,
t_body_msg TYPE solisti1,
t_receivers TYPE somlreci1,
t_pdf TYPE tline.

DATA : w_document_data TYPE t_document_data,
w_packing_list TYPE t_packing_list,
w_attachment TYPE t_attachment,
w_body_msg TYPE t_body_msg,
w_receivers TYPE t_receivers,
w_pdf TYPE t_pdf.

DATA: customer TYPE scustom,
bookings TYPE ty_bookings,
connections TYPE ty_connections.
DATA: var_a.

DATA : i_document_data TYPE STANDARD TABLE OF t_document_data,
i_packing_list TYPE STANDARD TABLE OF t_packing_list,
i_attachment TYPE STANDARD TABLE OF t_attachment,
i_body_msg TYPE STANDARD TABLE OF t_body_msg,
i_receivers TYPE STANDARD TABLE OF t_receivers,
i_pdf TYPE STANDARD TABLE OF t_pdf.

PARAMETERS: p_mail TYPE char120 OBLIGATORY,
            p_aufnr TYPE aufnr DEFAULT '2000000021'.

START-OF-SELECTION.

  ssfctrlop-no_dialog = 'X'.
  ssfctrlop-preview = 'X'.
  ssfctrlop-getotf = 'X'.
  ssfcompop-tddest = 'LP01'.

* GET FUNCTION MODULE NAME FOR GIVEN SMARTFORM
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname = 'ZYOURSMARTORM'
    IMPORTING
      fm_name  = fm_name.

  CALL FUNCTION fm_name
    EXPORTING
      control_parameters = ssfctrlop
      id_aufnr           = p_aufnr
    IMPORTING
      job_output_info    = it_otf_data.

* APPENDING THE OTF DATA INTO THE FINAL TABLE
  it_otf_final[] = it_otf_data-otfdata[].

* CONVERTING OTF DATA INTO PDF DATA
  CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
  format = 'PDF'
  IMPORTING
  bin_filesize = bin_filesize
* bin_file =
  TABLES
  otf = it_otf_final
  lines = it_pdfdata[]
  EXCEPTIONS
  err_max_linewidth = 1
  err_format = 2
  err_conv_not_possible = 3
  err_bad_otf = 4
  OTHERS = 5.

* To send data as email attachment, we need to have a table of SOLISTI1.
* This table contains line size of 255 characters. Below function module
* does the trick of changing the table from X character sized lines into
* any given Y character sized lines.

  CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
    EXPORTING
      line_width_dst              = '255'
    TABLES
      content_in                  = it_pdfdata[]
      content_out                 = it_pdf[]
    EXCEPTIONS
      err_line_width_src_too_long = 1
      err_line_width_dst_too_long = 2
      err_conv_failed             = 3
      OTHERS                      = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.

* SUBJECT OF THE MAIL.
    w_document_data-obj_name = 'MAIL_TO_HEAD'.
    w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.

* BODY OF THE MAIL
    w_body_msg = 'This is body of mail msg.'.
    APPEND w_body_msg TO i_body_msg.
    CLEAR w_body_msg.

* WRITE PACKING LIST FOR BODY
    DESCRIBE TABLE i_body_msg LINES g_tab_lines.
    w_packing_list-head_start = 1.
    w_packing_list-head_num = 0.
    w_packing_list-body_start = 1.
    w_packing_list-body_num = g_tab_lines.
    w_packing_list-doc_type = 'RAW'.
    APPEND w_packing_list TO i_packing_list.
    CLEAR w_packing_list.

* WRITE PACKING LIST FOR ATTACHMENT
    w_packing_list-transf_bin = 'X'.
    w_packing_list-head_start = 1.
    w_packing_list-head_num = 1.
    w_packing_list-body_start = 1.

    DESCRIBE TABLE it_pdf LINES w_packing_list-body_num.
    w_packing_list-doc_type = 'PDF'.
    w_packing_list-obj_descr = 'PDF Attachment'.
    w_packing_list-obj_name = 'PDF_ATTACHMENT'.
    w_packing_list-doc_size = w_packing_list-body_num * 255.
    APPEND w_packing_list TO i_packing_list.
    CLEAR w_packing_list.

* FILL THE DOCUMENT DATA &GET SIZE OF ATTACHMENT
    w_document_data-obj_langu = sy-langu.
    READ TABLE it_pdf INTO w_pdf INDEX g_tab_lines.
    w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).

    w_receivers-receiver = p_mail. "<-- change address
    w_receivers-rec_type = 'B'. " 'U'. " B - for sap mail; U for internet email
    APPEND w_receivers TO i_receivers.

    BREAK-POINT.

* SEND MAILS TO RECIPIENTS
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data              = w_document_data
        put_in_outbox              = 'X'
        commit_work                = 'X'
      IMPORTING
        sent_to_all                = g_sent_to_all
      TABLES
        packing_list               = i_packing_list
        contents_bin               = it_pdf
        contents_txt               = i_body_msg
        receivers                  = i_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 .
      MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.
    ENDIF.
  ENDIF.

Former Member
0 Kudos

Thank you Catalin,

Now i am able to see mails in SOST.

The only difference is

w_receivers-rec_type = 'B'.

earlier it was 'U'.

Answers (1)

Answers (1)

Former Member
0 Kudos

Check this code, it's working fine here:

  CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

      format                = 'PDF'

    IMPORTING

      bin_filesize          = lv_bin_filesize

      bin_file              = lv_pdf_bin

    TABLES

      otf                   = ls_job_output-otfdata

      lines                 = lt_lines

    EXCEPTIONS

      err_max_linewidth     = 1

      err_format            = 2

      err_conv_not_possible = 3

      err_bad_otf           = 4

      OTHERS                = 5.

  TRY.

      send_request = cl_bcs=>create_persistent( ).

      lp_pdf_size = XSTRLEN( lv_pdf_bin ).

      pdf_content = cl_document_bcs=>xstring_to_solix(

          ip_xstring = lv_pdf_bin ).

      document = cl_document_bcs=>create_document(

            i_type    = 'PDF'

            i_hex     = pdf_content

            i_length  = lp_pdf_size

            i_subject = lv_subject ).      

      send_request->set_document( document ).

      recipient = cl_cam_address_bcs=>create_internet_address(

          i_address_string = lv_mailto ).

      send_request->add_recipient( i_recipient = recipient ).

      sent_to_all = send_request->send(

          i_with_error_screen = 'X' ).

      IF sent_to_all = 'X'.

      ENDIF.

      COMMIT WORK.

    CATCH cx_bcs INTO bcs_exception.

      EXIT.

  ENDTRY.