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: 

Email format issue

former_member295881
Contributor
0 Kudos

Hello Experts,

I've a requirement where I need to attach an excel sheet in email and send it to user. I'm able to do it but the problem is that text does not wrap to next line and all the text displays in one line as shown below.

However, it should display as shown below.

Here is my code for reference.

-----------------------------------------------------------------------------------------------------------------------------------------------------

  data: lv_bname   like usr21-bname,

        lv_persnum like usr21-persnumber,

        lv_addrnum like usr21-addrnumber,

        lv_email   like adr6-smtp_addr,

        lv_string  type string,

        lv_row     type string,

        lv_new_amt type char10.

  data: i_packing     like sopcklsti1  occurs 0 with header line,

        i_objbin      like solisti1    occurs 0 with header line,

        i_reclist     like somlreci1   occurs 0 with header line,

        doc_chng      like sodocchgi1,

        l_tabix       like sy-tabix,

        l_lines       type i.

  if pemail1 is not initial.

    i_reclist-receiver = pemail1.

    i_reclist-rec_type = 'U'.

    append i_reclist.

  endif.

* Email header info

  doc_chng-obj_name  = c_subject.

  doc_chng-obj_descr = c_subject.

* Create the message packing data

  clear i_packing-transf_bin.

  i_packing-head_start   = 1.

  i_packing-head_num     = 0.

  i_packing-body_start   = 1.

  i_packing-body_num     = 0.

  i_packing-doc_type     = 'RAW'.

  append i_packing.

* Report Summary header

"concatenate text-001 sy-uname into lv_string separated by space.

  lv_string = text-001.

  append lv_string to i_objbin.

  "append text-002 to i_objbin.

  append cl_abap_char_utilities=>cr_lf to i_objbin.

  clear: lv_row.

  lv_row = text-002.

  append lv_row to i_objbin.

  clear: lv_row.

  loop at lt_output into lw_output.

     lv_new_amt = lw_output-new_amt.

    concatenate lw_output-zrerate "'|'

                lw_output-kunrg "'|'

                lw_output-name1 "'|'

                lw_output-auart "'|'

                lw_output-initiator "'|'

                lv_new_amt "'|'

                lw_output-waerk "'|'

                lw_output-erdat "'|'

                lw_output-idocnum "'|'

                lw_output-idocerror

                  into lv_row SEPARATED BY ','.

    append lv_row to i_objbin.

    clear: lv_new_amt, lv_row.

  lv_row = text-002.

  append lv_row to i_objbin.

  clear: lv_row.

  endloop.

  "append text-002 to i_objbin.

  append cl_abap_char_utilities=>cr_lf to i_objbin.

  append cl_abap_char_utilities=>cr_lf to i_objbin.

  describe table i_objbin lines l_lines.

* create the message packing data

  i_packing-transf_bin   = 'X '.

  i_packing-head_start   = 1.

  i_packing-head_num     = 1.

  i_packing-body_start   = 1.

  i_packing-body_num     = l_lines.

  i_packing-doc_type     = 'CSV'."'RAW'.

  i_packing-obj_name     = 'EMAIL'.

  i_packing-obj_descr    = 'Re-rating Rebill order update summary'. "'Z_CRAETE_RERATE_DOC_order_creation_summary'.

  i_packing-doc_size     = l_lines * 255.

  append i_packing.

* send email

  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    exporting

      document_data              = doc_chng

      put_in_outbox              = ''

      commit_work                = 'X'

    tables

      packing_list               = i_packing

      contents_bin               = i_objbin

      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.

    message e188(zcpc) with 'Error sending email'.

  endif.

-----------------------------------------------------------------------------------------------------------------------------------------------------

Can somebody see what is the problem with my code and how to rectify it, please.

Many thanks in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Why don't you move this line to inside the loop?

append cl_abap_char_utilities=>cr_lf to i_objbin.

4 REPLIES 4

Former Member
0 Kudos

Why don't you move this line to inside the loop?

append cl_abap_char_utilities=>cr_lf to i_objbin.

p244500
Active Contributor
0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi,

I have corrected code (see in bold letter) . Try this

lv_string = text-001.

concatenate lv_string cl_abap_char_utilities=>cr_lf into lv_string.


  *append lv_string to i_objbin.

  "append text-002 to i_objbin.

  *append cl_abap_char_utilities=>cr_lf to i_objbin.

  clear: lv_row.

  lv_row = text-002.

  append lv_row to i_objbin.

  clear: lv_row.

concatenate lv_string  lv_row cl_abap_char_utilities=>cr_lf into lv_string

.

  loop at lt_output into lw_output.

     lv_new_amt = lw_output-new_amt.

  

     concatenate lv_string  " If required use tab space

               lw_output-zrerate "'|'

                lw_output-kunrg "'|'

                lw_output-name1 "'|'

                lw_output-auart "'|'

                lw_output-initiator "'|'

                lv_new_amt "'|'

                lw_output-waerk "'|'

                lw_output-erdat "'|'

                lw_output-idocnum "'|'

                lw_output-idocerror

                 cl_abap_char_utilities=>cr_lf

                  into lv_string . "SEPARATED BY ','.

   * append lv_row to i_objbin.

    * clear: lv_new_amt, lv_row.

    *lv_row = text-002.

  *append lv_row to i_objbin.

  *clear: lv_row.

  endloop.

* Convert in Binary Data

      cl_bcs_convert=>string_to_solix(

         EXPORTING

           iv_string   = lv_string

           iv_codepage = '4103'  "for MS Excel,

           iv_add_bom  = 'X'

         IMPORTING

           et_solix  = i_objbin " Change type i_objbin

           ev_size   = size ).

* Use Table CONTENTS_HEX as CONTENTS_BIN is obsolete

* send email

  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    exporting

      document_data              = doc_chng

      put_in_outbox              = ''

      commit_work                = 'X'

    tables

      packing_list               = i_packing

* contents_bin               = i_objbin

      receivers                  = i_reclist

    CONTENTS_HEX   =  i_objbin

      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.

    message e188(zcpc) with 'Error sending email'.

  endif.

Thanks & Regards,

Arun

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

see here:

http://scn.sap.com/message/14309154#14309154

Using html ,cl_document_bcs.

Full source included.

Regards .