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: 

Sending EMAIL using so10 text in HTML format

Former Member
0 Kudos

Dear SAPGurus,

Currently we are sending emails using so10 text & currently we are testing in development system, so we are testing with sost tcode to check the email is getting triggered & we are not testing with outlook.

Our requirement is to see the HTML formatted email in sost  using so10 text.

Regards,

Rumeshbabu S

1 REPLY 1

shaik_sajid
Active Contributor
0 Kudos

Hi,

Following is the HTML Code for Emails.

  DATA: ls_receivers    TYPE somlreci1,
        ls_contents     TYPE solisti1,
        ls_packing_list TYPE sopcklsti1,
        ls_doc_data     TYPE sodocchgi1.

  DATA: lt_contents     TYPE STANDARD TABLE OF solisti1,
        lt_receivers    TYPE STANDARD TABLE OF somlreci1,
        lt_packing_list TYPE STANDARD TABLE OF sopcklsti1.

***************** Receivers ***********************

  ls_doc_data-obj_langu  =  sy-langu.
  ls_doc_data-obj_name   = 'INS_DOC1'.
  ls_doc_data-obj_descr  = gv_subject.
  ls_doc_data-obj_prio   = '1'.
  ls_doc_data-sensitivty = 'F'.

  if p_to1 is NOT INITIAL.
    ls_receivers-receiver   = p_to1.
    ls_receivers-rec_type   = 'U'.
    ls_receivers-com_type   = 'INT'.
    APPEND ls_receivers TO lt_receivers.
  ENDIF.


***************** Contents ***********************
  data: lv_counter TYPE i,
        lv_counter_char TYPE char6,
        lv_po_value TYPE char20.

  clear : ls_contents.
  ls_contents-line = '<html> <body>'.
  APPEND ls_contents TO lt_contents.

  ls_contents-line = '<p> Hello, </p>'.
  APPEND ls_contents TO lt_contents.

  ls_contents-line = '<p>  </p>'.
  APPEND ls_contents TO lt_contents.

  clear : ls_contents.
  CONCATENATE '<p> ' 'Following are the Purchase Orders Released '
             'in Last 1 Week'  '</p>'
                              INTO ls_contents-line
                              SEPARATED BY space.

  APPEND ls_contents TO lt_contents.
  clear : ls_contents.
  ls_contents-line = '<p>  </p>'.
  APPEND ls_contents TO lt_contents.

*   table display
  ls_contents-line = '<table style="MARGIN: 10px" bordercolor="#90EE90" '.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = ' cellspacing="0" cellpadding="3" width="1500"'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = ' border="1"><tbody><tr>'.
  APPEND ls_contents TO lt_contents.

*   table header
  ls_contents-line = '<th bgcolor="#F7864E">S.No.</th>'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<th bgcolor="#F7864E">Purchase Order</th>'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<th bgcolor="#F7864E">Category</th>'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<th bgcolor="#F7864E">Supplier Country</th>'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<th bgcolor="#F7864E">Destination</th>'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<th bgcolor="#F7864E">PO Value</th>'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<th bgcolor="#F7864E">Currency</th>'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<th bgcolor="#F7864E">Delivery Terms</th></tr>'.
  APPEND ls_contents TO lt_contents.

  loop at gt_final_status INTO gs_final_status
            where status eq 1.
    clear ls_contents.
    READ TABLE gt_output INTO gs_output
            with KEY ebeln = gs_final_status-ebeln.
    if sy-subrc eq 0.
      lv_counter = lv_counter + 1.
      lv_counter_char = lv_counter.
      lv_po_value = gs_output-RLWRT.
      clear ls_contents.
      CONCATENATE '<tr style="background-color:#eeeeee;"><td>'lv_counter_char'</td>'
             INTO ls_contents-line RESPECTING BLANKS
             SEPARATED BY space.
      APPEND ls_contents TO lt_contents.

      clear ls_contents.
      CONCATENATE '<td>'gs_output-ebeln'</td>'
             INTO ls_contents-line RESPECTING BLANKS
             SEPARATED BY space.
      APPEND ls_contents TO lt_contents.

      clear ls_contents.
      CONCATENATE '<td>'gs_output-category'</td>'
             INTO ls_contents-line RESPECTING BLANKS
             SEPARATED BY space.
      APPEND ls_contents TO lt_contents.

      clear ls_contents.
      CONCATENATE '<td>'gs_output-supplier_country'</td>'
             INTO ls_contents-line RESPECTING BLANKS
             SEPARATED BY space.
      APPEND ls_contents TO lt_contents.

      clear ls_contents.
      CONCATENATE '<td>'gs_output-to_country'</td>'
             INTO ls_contents-line RESPECTING BLANKS
             SEPARATED BY space.
      APPEND ls_contents TO lt_contents.

      clear ls_contents.
      CONCATENATE '<td>'lv_po_value'</td>'
             INTO ls_contents-line RESPECTING BLANKS
             SEPARATED BY space.
      APPEND ls_contents TO lt_contents.

      clear ls_contents.
      CONCATENATE '<td>'gs_output-WAERS'</td>'
             INTO ls_contents-line RESPECTING BLANKS
             SEPARATED BY space.
      APPEND ls_contents TO lt_contents.

      clear ls_contents.
      CONCATENATE '<td>'gs_output-inco2'</td></tr>'
             INTO ls_contents-line RESPECTING BLANKS
             SEPARATED BY space.
      APPEND ls_contents TO lt_contents.
    ENDIF.
  ENDLOOP.

  ls_contents-line = '</tbody> </table>'.
  APPEND ls_contents TO lt_contents.

  ls_contents-line = '<br> <br>'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<p>This is Auto Generated Email by SAP System.'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<br><br>'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<p>Regards,</p>'.
  APPEND ls_contents TO lt_contents.
  ls_contents-line = '<p>SAP System</p>'.
  APPEND ls_contents TO lt_contents.

*   HTML close
  ls_contents-line = '</body> </html> '.
  APPEND ls_contents TO lt_contents.

***************** Packing List  ***********************

  ls_packing_list-transf_bin = space.
  ls_packing_list-head_start = 1.
  ls_packing_list-head_num   = 0.
  ls_packing_list-body_start = 1.
  ls_packing_list-doc_type   = 'HTML'.
  DESCRIBE TABLE lt_contents LINES ls_packing_list-body_num.
  APPEND  ls_packing_list TO lt_packing_list.

*****************Function Module***********************

  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = ls_doc_data
      commit_work                = 'X'
    TABLES
      packing_list               = lt_packing_list
      contents_txt               = lt_contents
      receivers                  = lt_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 EQ 0.
    Write:/ 'Mail Sent for Option 1'.
  ENDIF.

Regards

Shaik