cancel
Showing results for 
Search instead for 
Did you mean: 

E mail body for smartform as attachment not using Function module

Former Member
0 Kudos

Hi All,

  I am sending smartform as email attachments. I am not using any function module to send smartform as attachment. Below is my code for reference.

control_parameters-device = 'MAIL'.

output_options-tdtitle = v_title.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING
      formname                 = 'ZSD_STANDARD_INVOICE'
*     VARIANT                  = ' '
*     DIRECT_CALL              = ' '
   IMPORTING
     fm_name                  fm_name
   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 fm_name
    EXPORTING
*   ARCHIVE_INDEX              =
*   ARCHIVE_INDEX_TAB          =
*   ARCHIVE_PARAMETERS         =
   control_parameters         = control_parameters
*   MAIL_APPL_OBJ              =
   MAIL_RECIPIENT             = LVS_RECIPIENT
   MAIL_SENDER                = LVS_SENDER
   output_options             output_options
   user_settings              = 'X'
      is_nast                    = nast
      vbak                       = zvbak
      vbdkr                      = vbdkr
      zpayer                     = zpayer
      zorder                     = zorder
      komk                       = komk
      zvbak                      = zvbak
      komvd                      = komvd
*      wk_dimensions              = wk_dimensions
*      wk_spec                    =  wk_spec
*    IMPORTING
*       document_output_info      =  l_document_output_info
*       job_output_info           = l_job_output_info " job_output
*       job_output_options        =  l_job_output_options
    TABLES
      it_vbdpr                   = tvbdpr
      it_tkomvd                  it_tkomvd
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.

But, Here I am getting smartform as e email attachment but I need to give some 2 lines of email body also.

How to achieve this.

Thanks,

Sreelakshmi.B

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member213851
Active Contributor
0 Kudos

Hi Vishnu.

It is always better to use class CL_DOCUMENT_BCS  for sending mails using the attatchment.

Please follow the below Code :

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

CLASS cl_bcs DEFINITION LOAD.

DATA:  lo_send_request TYPE REF TO cl_bcs

      ,lo_document     TYPE REF TO cl_document_bcs

      ,lo_sender       TYPE REF TO if_sender_bcs

      ,lo_recipient    TYPE REF TO if_recipient_bcs      ,lt_message_body TYPE bcsy_text

      ,lx_document_bcs TYPE REF TO cx_document_bcs

      ,lv_send         TYPE ad_smtpadr VALUE 'xyz@gmail.com'

      ,lv_sent_to_all  TYPE os_boolean     .

"create send request

lo_send_request = cl_bcs=>create_persistent( ).

"create message body and subject

APPEND 'Dear Vendor,' TO lt_message_body.

APPEND INITIAL LINE to lt_message_body.

APPEND 'Please fill the attached .' TO lt_message_body.

APPEND INITIAL LINE to lt_message_body.

APPEND 'Thank You,' TO lt_message_body.

"put your text into the document

lo_document = cl_document_bcs=>create_document(

                 i_type = 'RAW'

                 i_text = lt_message_body

                 i_subject = 'Vendor Payment Form' ).

TRY.

  lo_document->add_attachment(

    EXPORTING

      i_attachment_type = 'PDF'

      i_attachment_subject = 'Form'

      i_att_content_hex = lt_att_content_hex ).

  CATCH cx_document_bcs INTO lx_document_bcs.

ENDTRY.

* Add attachment

* Pass the document to send request

lo_send_request->set_document( lo_document ).

"Create sender

lo_sender = cl_cam_address_bcs=>create_internet_address( l_send ).

"Set sender

lo_send_request->set_sender( lo_sender ).

"Create recipient

lo_recipient = cl_sapuser_bcs=>create( sy-uname ).

*Set recipient

lo_send_request->add_recipient(

     EXPORTING

       i_recipient = lo_recipient i_express = 'X' ).

lo_send_request->add_recipient( lo_recipient ).

* Send email

lo_send_request->send(

  EXPORTING

    i_with_error_screen = 'X'

  RECEIVING

    result = lv_sent_to_all ).

COMMIT WORK.

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

Regards,

Sachin

Former Member
0 Kudos

Hi,

Check this link.

https://scn.sap.com/thread/1866200

Regards

Haritha