Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Send email through SO_NEW_DOCUMENT_ATT_SEND_API1 with PDF attachement of smartforms.

nishant_jain3
Explorer
0 Kudos

Hi,

I am converting a smartform to PDF and then sending it as an attachment to email using FM SO_NEW_DOCUMENT_ATT_SEND_API1.

But I am getting this error. 'Error calling FM <SBCOMS_SEND_REQUEST_CREATE> in <SO_DOCUMENT_SEND_API1> with SY-SUBRC <1>'

I am passing below entries to packaging list table.

Packing list for Email Text

        ls_packing_list-head_start = 1.
        ls_packing_list-head_num   = 1.
        ls_packing_list-body_start = 1.
        ls_packing_list-doc_type   = 'RAW'.

Packing list for PDF

        ls_packing_list-transf_bin = 'X'
        ls_packing_list-head_start = 1.
        ls_packing_list-head_num   = 1.
        ls_packing_list-body_start = 1.
        ls_packing_list-doc_type   = 'PDF'.

Please let me know if I am missing anything.

Regards,

Nishant

11 REPLIES 11

alessandroieva
Active Participant
0 Kudos

HI

this is my code:

1)

FORM sx_table_line_width_change TABLES t_pdf TYPE tttext

                             CHANGING t_contents_bin TYPE swftlisti1.

  CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

    EXPORTING

      line_width_src              = 134

      line_width_dst              = 255

    TABLES

      content_in                  = t_pdf

      content_out                 = t_contents_bin

    EXCEPTIONS

      err_line_width_src_too_long = 1

      err_line_width_dst_too_long = 2

      err_conv_failed             = 3

      OTHERS                      = 4.

ENDFORM.                    " SX_TABLE_LINE_WIDTH_CHANGE

2)

FORM popola_destinatari  CHANGING l_it_recvlist TYPE somlreci1_t.

  DATA: wa_somlreci1 TYPE somlreci1.

  wa_somlreci1-receiver = 'ADRESS MAIL'.

  wa_somlreci1-rec_type = 'U'.

  wa_somlreci1-com_type = 'INT'.

  APPEND wa_somlreci1 TO l_it_recvlist.

  CLEAR wa_somlreci1.

ENDFORM.                    " POPOLA_DESTINATARI

3)

FORM document_data USING l_it_contents TYPE srm_t_solisti1

                CHANGING l_document    TYPE sodocchgi1

                         t_contents_bin  TYPE swftlisti1.

  DATA: wa_solisti1 TYPE solisti1,

        tablines    TYPE i,

        fieldlen   TYPE i,

        wa_contents_bin TYPE solisti1.

  DESCRIBE FIELD wa_solisti1-line LENGTH fieldlen IN BYTE MODE.

  DESCRIBE TABLE l_it_contents LINES tablines.

  MULTIPLY fieldlen BY tablines.

  l_document-obj_name = 'MAIL'.

  l_document-obj_descr = 'DESCRIPTION'.

  l_document-obj_langu = sy-langu.

  l_document-obj_prio = 9.

  l_document-priority = 9.

  READ TABLE t_contents_bin INTO wa_contents_bin INDEX tablines.

  l_document-doc_size = ( tablines - 1 ) * 255 + strlen( wa_contents_bin ).

ENDFORM.                    " DOCUMENT_DATA

4)

FORM packing_list TABLES t_pdf TYPE tttext

                  USING l_it_contents TYPE srm_t_solisti1

               CHANGING l_it_packlist TYPE sopcklsti1_t

                        t_contents_bin TYPE  swftlisti1 .

  DATA: wa_sopcklsti1 TYPE sopcklsti1,

        wa_contents TYPE solisti1,

       wa_pdf TYPE tline,

       wa_contents_bin TYPE solisti1.

*---------------------------------------

  CLEAR wa_sopcklsti1-transf_bin.

  wa_sopcklsti1-head_start = 1.

  wa_sopcklsti1-head_num = 0.

  wa_sopcklsti1-body_start = 1.

  DESCRIBE TABLE l_it_contents LINES wa_sopcklsti1-body_num.

  wa_sopcklsti1-doc_type = 'RAW'.

  APPEND wa_sopcklsti1 TO l_it_packlist.

  wa_sopcklsti1-transf_bin = 'X'.

  wa_sopcklsti1-head_start = 1.

  wa_sopcklsti1-head_num = 0.

  wa_sopcklsti1-body_start = 1.

  DESCRIBE TABLE t_contents_bin LINES wa_sopcklsti1-body_num.

  wa_sopcklsti1-doc_type = 'PDF'.

  wa_sopcklsti1-obj_descr = 'Pdf prova'.

  wa_sopcklsti1-obj_name = 'Pdf prova'.

  wa_sopcklsti1-doc_size = wa_sopcklsti1-body_num * 255.

  APPEND wa_sopcklsti1 TO l_it_packlist.

ENDFORM.                    " PACKING_LIST

5)

FORM send_email  USING l_document   TYPE sodocchgi1

                        l_packlist   TYPE sopcklsti1_t

                        l_contents   TYPE srm_t_solisti1

                        l_recvlist   TYPE somlreci1_t

                        t_contents_bin TYPE  swftlisti1.

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

      document_data              = l_document

      put_in_outbox              = 'X'

      commit_work                = 'X'

    TABLES

      packing_list               = l_packlist

      contents_bin               = t_contents_bin

      contents_txt               = l_contents

      receivers                  = l_recvlist

    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.

ENDFORM.                    " SEND_EMAIL

0 Kudos

Hi Alessandro,

Thanks for your reply.

I am passing the same inputs to FM as in your code. the only difference is the way I am converting it to PDF. I am using below steps to convert to pdf.

CALL FUNCTION 'CONVERT_OTF'
          EXPORTING
            format                = lc_docty_pdf
          IMPORTING
            bin_filesize          = bin_filesize
            bin_file              = lv_binfile
          TABLES
            otf                   = lt_otf_final
            lines                 = lt_pdfdata[]
          EXCEPTIONS
            err_max_linewidth     = 1
            err_format            = 2
            err_conv_not_possible = 3
            err_bad_otf           = 4
            OTHERS                = 5.

*     Converting Binary File to PDF to solix type.
        CALL METHOD cl_bcs_convert=>xstring_to_solix
          EXPORTING
            iv_xstring = lv_binfile
          RECEIVING
            et_solix   = lt_pdf1[].

*     Changing the contents into solist1 since this is supported
*     for the standard Email function module.
        CALL FUNCTION 'SO_SOLIXTAB_TO_SOLITAB'
          EXPORTING
            ip_solixtab = lt_pdf1[]
          IMPORTING
            ep_solitab  = lt_pdf[].

is there any possibility of config missing or something ?

Regards

Nishant Jain

0 Kudos

HI,

try this:

CALL FUNCTION 'CONVERT_OTF_2_PDF'

       EXPORTING

         use_otf_mc_cmd         = ''

       IMPORTING

         bin_filesize           = bin_filesize

       TABLES

         otf                    = job_output_info-otfdata

         doctab_archive         = doctab_archive

         lines                  = pdf

       EXCEPTIONS

         err_conv_not_possible  = 1

         err_otf_mc_noendmarker = 2

         OTHERS                 = 3.

0 Kudos

Hi Alessandro,

I tried using the above FM. but still getting the same error.

Thanks

Nishant

Former Member
0 Kudos

Hi Nishant,

Can you show me complete code logic?

Also, refer below thread. I hope it will help you.

http://wiki.scn.sap.com/wiki/display/Snippets/Smartform+to+Mail+as+PDF+attachment

Regards,

Sudeesh Soni

0 Kudos

HI Sudeesh,

Now I am using the same logic as mentioned in the link provided. But still getting the same error. below is my code.

        CALL FUNCTION 'CONVERT_OTF'
          EXPORTING
            format                = 'PDF'
            max_linewidth         = 132
          IMPORTING
            bin_filesize          = bin_filesize

          TABLES
            otf                   = lt_otf_final
            lines                 = lt_pdfdata[]
          EXCEPTIONS
            err_max_linewidth     = 1
            err_format            = 2
            err_conv_not_possible = 3
            err_bad_otf           = 4
            OTHERS                = 5.


        LOOP AT lt_pdfdata INTO ls_data.
          TRANSLATE ls_data USING '~'.
          CONCATENATE wa_buffer ls_data INTO wa_buffer.
          CLEAR ls_data.
        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.
        lt_attachments[] = i_record[].
        DESCRIBE TABLE lt_attachments LINES lv_pdflines.
*     Document attributes
        ls_doc_attr-obj_name   = lc_objname.
        ls_doc_attr-obj_descr  = lv_str1.
        ls_doc_attr-obj_langu  = lc_english.
        ls_doc_attr-sensitivty = 'F'.      "functional message

*     Packing list for Email Text
        DESCRIBE TABLE lt_message LINES lv_bodytxt_lines.
        CLEAR ls_packing_list.
        ls_packing_list-head_start = 1.
        ls_packing_list-head_num   = 0.
        ls_packing_list-body_start = 1.
        ls_packing_list-body_num   = lv_bodytxt_lines.
        ls_packing_list-doc_type   = 'RAW'.
        APPEND ls_packing_list TO lt_packing_list.

*     Packing list for PDF
        CLEAR ls_packing_list.
        ls_packing_list-transf_bin = lc_flag_set.
        ls_packing_list-head_start = 1.
        ls_packing_list-head_num   = 0.
        ls_packing_list-body_start = 1.
        ls_packing_list-body_num   = lv_pdflines.
        ls_packing_list-doc_type   = 'PDF'
        ls_packing_list-obj_descr  = 'Test'.
        ls_packing_list-obj_name   = 'Test'.
        ls_packing_list-obj_langu  = 'E'.
        ls_packing_list-doc_size   = ls_packing_list-body_num * 255.
        APPEND ls_packing_list TO lt_packing_list.


        ls_email_to-rec_type = 'U'.
        ls_email_to-com_type = 'INT'.
        ls_email_to-receiver = lv_email_id
        APPEND ls_email_to TO lt_email_to.

*     Function Module to send external mail
        CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
          EXPORTING
            document_data              = ls_doc_attr
            put_in_outbox              = lc_flag_set
*           commit_work                = 'X'
          TABLES
            packing_list               = lt_packing_list
            contents_bin               = lt_attachments
            contents_txt               = lt_message
            receivers                  = lt_email_to
          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.

Please let me know.

Regards,

Nishant

Former Member
0 Kudos

hi Nishant,

i think first you convert smartform to OTF and then sent it as an pdf.

the code is correct but the if you include the convert_otf Fm then it will be better .

Regards

Shambuling

former_member196651
Contributor
0 Kudos

Hi Nishant,

Hope you had converted your SMARTFORM to OTF successfully. Once I had the same requirement and I wrote the following code, which is almost similar to your shared code. This worked for me. Please try this:

CALL FUNCTION 'CONVERT_OTF'

     EXPORTING

       format                = 'PDF'

       max_linewidth     = 132

     IMPORTING

       bin_filesize         = gv_line

     TABLES

       otf                     = gt_otf_final

       lines                  = gt_tline

     EXCEPTIONS

       err_max_linewidth        = 1

       err_format                   = 2

       err_conv_not_possible  = 3

       OTHERS                     = 4.

*   Fehlerhandling

   IF sy-subrc <> 0.

   ENDIF.


LOOP AT gt_tline INTO wa_tline.

     TRANSLATE wa_tline USING '~'.

     CONCATENATE wa_buffer wa_tline INTO wa_buffer.

  ENDLOOP.

   TRANSLATE wa_buffer USING '~'.

   DO.

      wa_record = wa_buffer.

      APPEND wa_record TO gt_record.

      SHIFT wa_buffer LEFT BY 255 PLACES.

      CLEAR wa_record.

      IF wa_buffer IS INITIAL.

        EXIT.

      ENDIF.

   ENDDO.

   CLEAR : gt_receivers, gt_obj_header, gt_objpack, gt_objtxt, gt_objbin.

   CLEAR : wa_receivers, wa_objpack, wa_objtxt, wa_objbin, wa_doc_data.

   "Getting mail id of the customer and populating fun. mod. parameter

   CLEAR wa_receivers.

   wa_receivers-receiver = wa_adr6-smtp_addr.

   wa_receivers-rec_type = 'U'.

   APPEND wa_receivers TO gt_receivers.

   CLEAR wa_objtxt.

   wa_objtxt-line  = 'Sir,'.

   APPEND wa_objtxt TO gt_objtxt.

   CLEAR wa_objtxt.

   wa_objtxt-line  = '                                             '.

   APPEND wa_objtxt TO gt_objtxt.

   CLEAR wa_objtxt.

   wa_objtxt-line  = '                                             '.

   APPEND wa_objtxt TO gt_objtxt.

   CLEAR wa_objtxt.

   wa_objtxt-line  = '***This is a SAP system generated mail. Please do not reply !***'.

   APPEND wa_objtxt TO gt_objtxt.

   CLEAR gv_line.

   DESCRIBE TABLE gt_objtxt LINES gv_line.

   CLEAR lv_subject.

   CONCATENATE 'Invoice for' gv_vbeln INTO lv_subject SEPARATED BY space.

   CLEAR wa_doc_data.

   wa_doc_data-obj_name    = 'SMARTFORM'.

   wa_doc_data-expiry_dat   = sy-datum + 10.

   wa_doc_data-obj_descr    = lv_subject.

   wa_doc_data-sensitivty    = 'F'.

   wa_doc_data-doc_size     = gv_line * 255.

   CLEAR wa_objpack.

   wa_objpack-transf_bin     = space.

   wa_objpack-head_start    = 1.

   wa_objpack-head_num    = 0.

   wa_objpack-body_start    = 1.

   wa_objpack-body_num    = gv_line.

   wa_objpack-doc_type      = 'RAW'.

   APPEND wa_objpack TO gt_objpack.

   gt_objbin = gt_record.

   DESCRIBE TABLE gt_objbin LINES gv_line_bin.

   wa_objpack-transf_bin    = 'X'.

   wa_objpack-head_start   = 1.

   wa_objpack-head_num   = 0.

   wa_objpack-body_start   = 1.

   wa_objpack-doc_size     = gv_line_bin * 255 .

   wa_objpack-body_num   = gv_line_bin.

   wa_objpack-doc_type     = 'PDF'.

   wa_objpack-obj_name    = 'SMART'.

   wa_objpack-obj_descr    = 'PDF ATTACHMENT'.

   APPEND wa_objpack TO gt_objpack.

   CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

     EXPORTING

       document_data              = wa_doc_data

       put_in_outbox                = 'X'

       commit_work                 = 'X'

     TABLES

       packing_list                   = gt_objpack

       object_header                = gt_obj_header

       contents_bin                  = gt_objbin

       contents_txt                   = gt_objtxt

       receivers                        = gt_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.

Hope that this will work.

Regards,

Abijith

thangam_perumal
Contributor
0 Kudos

Hi Nishant,

               Please refer my below code last week only i have implemented this logic.

call function 'CONVERT_OTF'
     exporting
       format                = 'PDF'
       max_linewidth         = 132
     importing
       bin_filesize          = w_bin_filesize
     tables
       otf                   = t_otf
       lines                 = t_pdf_tab
     exceptions
       err_max_linewidth     = 1
       err_format            = 2
       err_conv_not_possible = 3
       err_bad_otf           = 4.

pdf_output[] = t_pdf_tab[].



loop at pdf_output.
     translate pdf_output using ' ~'.
     concatenate gd_buffer pdf_output into gd_buffer.
   endloop.
   translate gd_buffer using '~ '.
   do.

     it_mess_att = gd_buffer.
     append it_mess_att.
     shift gd_buffer left by 255 places.
     if gd_buffer is initial.
       exit.
     endif.

   enddo.





   ld_email   = p_email.
   ld_mtitle = p_mtitle.
   ld_format              = p_format.
   ld_attdescription      = p_attdescription.
   ld_attfilename         = p_filename.
   ld_sender_address      = p_sender_address.
   ld_sender_address_type = p_sender_addres_type.

*#Fill the document data.
   w_doc_data-doc_size = 1.


*#Populate the subject/generic message attributes

   w_doc_data-obj_langu = sy-langu.
   w_doc_data-obj_name  = 'SAPRPT'.
   w_doc_data-obj_descr = ld_mtitle .
   w_doc_data-sensitivty = 'F'.


*#Fill the document data and get size of attachment

   clear w_doc_data.

   read table it_attach index w_cnt.
   w_doc_data-doc_size =
      ( w_cnt - 1 ) * 255 + strlen( it_attach ).
   w_doc_data-obj_langu  = sy-langu.
   w_doc_data-obj_name   = 'SAPRPT'.
   w_doc_data-obj_descr  = ld_mtitle.
   w_doc_data-sensitivty = 'F'.
   clear t_attachment.
   refresh t_attachment.
   free t_attachment.
   t_attachment[] = it_attach[].

  clear it_attach[].
  refresh  it_attach[].
  free  it_attach[].
*#Describe the body of the message

   clear t_packing_list.
   refresh t_packing_list.
   t_packing_list-transf_bin = space.
   t_packing_list-head_start = 1.
   t_packing_list-head_num = 0.
   t_packing_list-body_start = 1.
   describe table it_message lines t_packing_list-body_num.
   t_packing_list-doc_type = 'RAW'.
   append t_packing_list.

*#Create attachment notification

   t_packing_list-transf_bin = 'X'.
   t_packing_list-head_start = 1.
   t_packing_list-head_num   = 1.
   t_packing_list-body_start = 1.
   describe table t_attachment lines t_packing_list-body_num.
   t_packing_list-doc_type   ld_format.
   t_packing_list-obj_descr  ld_attdescription.
   t_packing_list-obj_name   ld_attfilename.
   t_packing_list-doc_size   t_packing_list-body_num * 255.
   append t_packing_list.

*#Add the recipients email address
   clear t_receivers.
   refresh t_receivers.
   free t_receivers.
   clear : email.
   select single usrid_long into email from pa0105 where pernr = wa_pernr-pernr
     and subty = '0010' and seqnr = ''.
   t_receivers-receiver = email.
   t_receivers-rec_type = 'U'.
   t_receivers-com_type = 'INT'.
   t_receivers-notif_del = 'X'.
   t_receivers-notif_ndel = 'X'.
   append t_receivers.

   ld_sender_address = 'HRD1'.
   ld_sender_address_type = 'B'.

   call function 'SO_DOCUMENT_SEND_API1'

        exporting
             document_data              = w_doc_data
             put_in_outbox              = 'X'
             sender_address             = ld_sender_address
             sender_address_type        = ld_sender_address_type
             commit_work                = 'X'
        importing
             sent_to_all                = w_sent_all
        tables
             packing_list               = t_packing_list
             contents_bin               = t_attachment
             contents_txt               = it_message
             receivers                  = t_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.

*#Populate zerror return code

   ld_error = sy-subrc.

*#Populate zreceiver return code

   loop at t_receivers.

     ld_receiver = t_receivers-retrn_code.

   endloop.




check it and Revert back .



Regards,

Thangam.P

nishant_jain3
Explorer
0 Kudos

Thanks Everyone.

Issue has been resolved. it was some BASIS issue, now it is working fine.

Regards,

Nishant Jain

0 Kudos

Hello nishant.jain3 ,

Hope you are doing well.
I'm having the same issue. Everything in my program is correct. I'm converting SMARTFORM to OTF and actually it has been working fine for last 1 year, suddenly it start giving this error. So I think in my case it has to be some BASIS issue so can you please share what is the issue on BASIS side , that I can tell my BASIS team to look into it and correct it.

Regards,
Rameez.