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: 

cl_document_bcs=>create_document( ) - Creating the attachment

Former Member
0 Kudos

Hi Experts,

cl_document_bcs=>create_document() is creating the body of the email as an attachment whereas i need it as an email body.

data : t_html type soli_tab

Created the body of the email in HTML format with html tag.

v_document = cl_document_bcs=>create_document( i_type = „HTM‟ i_importance = „5‟ i_text = t_html i_subject = lv_sub ).

Please let me know where i am going wrong?

Thanks

Laxmi

Will definitely reward if i find it fruitful.

4 REPLIES 4

Former Member
0 Kudos

Hi Laxmi,

What is your issue? The email body part is coming wrong? Or the mail is not going?

If the body part is coming wrong paste the screenshot of the mail body and the HTML code that you have used.

R

former_member188458
Active Participant
0 Kudos

Hi Laxmi ,

Only if your code has below method call, it will add an attachment to the mail document

lo_document->add_attachment

Or you may follow the below code:

***Prepare your mail body if you wanto have the body as html

IF iv_html EQ abap_true.

     lv_mail_type = 'HTM'.

     LOOP AT lt_msgbody ASSIGNING <ls_msgbody> WHERE table_line IS NOT INITIAL.

       CONCATENATE '<p>' <ls_msgbody> '</p>'

        INTO <ls_msgbody>.

     ENDLOOP.

     UNASSIGN <ls_msgbody>.

   ELSE.

     lv_mail_type = 'RAW'.

   ENDIF.

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

   TRY.

       "create send request

       lo_send_request = cl_bcs=>create_persistent( ).

       " type cast to char 50 as it's a

       lv_subject = iv_subject. " mandatory parameter for

       "place text into the document

       lo_document = cl_document_bcs=>create_document(

                        i_type     = lv_mail_type

                        i_text     = lt_msgbody

                        i_subject  = lv_subject ).

       " overwrite subject to GT char50 subject

       IF iv_subject IS NOT INITIAL.

         lo_send_request->set_message_subject( ip_subject = iv_subject ).

       ENDIF.

       "Pass the document to send request

       lo_send_request->set_document( lo_document ).

       "Create sender (SAP User ID)

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

       "Set sender

       lo_send_request->set_sender( lo_sender ).

***---Create recipients--------------------------------------

         " set user's SAP Inbox as recipient

         lo_recipient = cl_sapuser_bcs=>create( ls_recipients-userid ).

         lo_send_request->add_recipient(

              EXPORTING

                i_recipient = lo_recipient ).

         " add user's external ID as recipient

         lo_recipient = cl_cam_address_bcs=>create_internet_address( ls_recipients-emailid ).

         "add recipients to send request

         lo_send_request->add_recipient(

              EXPORTING

                i_recipient = lo_recipient ).

       " Send email

       lo_send_request->send(

         EXPORTING

           i_with_error_screen = abap_true

         RECEIVING

           result = lv_sent_to_all ).


Regards,

Rini

0 Kudos

Hi lakshmi,

use like this

       L_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                      I_TYPE       = C_HTM               " C_HTM = 'HTM'
                      I_TEXT       = GT_CONTENTS    " DATA
                      I_LENGTH     = L_DOC_LEN     " lenght of document
                      I_SUBJECT    = L_SUB            " subject
                      I_LANGUAGE   = SY-LANGU
                      I_IMPORTANCE = '5' ).


Regards,

Kartik

former_member185414
Active Contributor
0 Kudos

Hi,

As mentioned by Rini, if you have made a call to the attachment method then only E-mail will have an attachment.

data :     lv_sent_to_all             TYPE boole_d,

             lref_request               TYPE REF TO cl_bcs,

              lref_recipient             TYPE REF TO if_recipient_bcs,

             lref_document              TYPE REF TO cl_document_bcs.


*--Create persistent send request

             lref_request = cl_bcs=>create_persistent( ).

*----Create document from internal table with text

             lref_document = cl_document_bcs=>create_document(

                             i_type    = lc_htm                 " Document Type - HTML

                             i_text    = lt_mailtxt              " The E-Mail Body

                             i_subject = ls_maildata-obj_descr ). " The subject of E-Mail


*----Add document to send request

             CALL METHOD lref_request->set_document( lref_document ).


lref_recipient = cl_cam_address_bcs=>create_internet_address( "abc@gmail.com" ). "Receivers Email

*----Add recipient with its respective attributes to send request

               CALL METHOD lref_request->add_recipient

                 EXPORTING

                   i_recipient = lref_recipient.


**-- API to send emails

             CALL METHOD lref_request->send(

               RECEIVING

                 result = lv_sent_to_all ).



BR.