CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
yashoratna
Participant
Introduction: In SAP, the email subject line is limited to 50 characters only, but there may be circumstances where we need to have the subject line more than that.

In this article, I'd cover how we can get rid of this restriction.

If we use the CL_BCS class to build email functionality, we have the importing parameter (I_SUBJECT) with the data element SO_OBJ_DES (which is 50 characters long and can be used up to that limit) when creating a document (Method CREATE_DOCUMENT of class CL_DOCUMENT_BCS).
DATA(lo_document_ref) = cl_document_bcs=>create_document(
i_type = lc_doc_type
i_text = lt_content_txt
i_subject = lv_subject ).



When we trigger an e-mail, the subject will get truncated in SAP.


And same issue will be outside SAP too.


To extend the e-mail subject by more than 50 characters, we can leverage the method SET_MESSAGE_SUBJECT of class CL_BCS.

And need to pass a blank( space ) in the mandatory importing parameter (I_SUBJECT) when creating the document reference.

DATA(lo_document_refcl_document_bcs=>create_document(
i_type    lc_doc_type
i_text    lt_content_txt
 i_subject space ).
DATA(lo_send_request_ref) = cl_bcs=>create_persistent( ).

lo_send_request_ref->set_message_subject(
EXPORTING
ip_subject = CONV string( lv_subject ) ).

Though there is no Doc. Title in the SAP


But outside of SAP, we can see a subject line in its entirety and uncut.


Please refer to the detailed code logic below.
PARAMETERS : p_email TYPE ad_smtpadr.    "abc@gmail.com

DATA: lv_subject TYPE char100 VALUE
'Action Required: Check if you can put more than 50 characters'.

DATA(lo_send_request_ref) = cl_bcs=>create_persistent( ).

*Populate sender name
DATA(lo_sender_ref) = cl_sapuser_bcs=>create( sy-uname ).
IF lo_send_request_ref IS BOUND.

IF lo_sender_ref IS BOUND.
*Add sender to send request
lo_send_request_ref->set_sender(
EXPORTING
i_sender = lo_sender_ref ).

* If need to send more than 50 characters in length as a subject line
* Then set message in cl_bcs->set_message_subject
* else populate it in method cl_document_bcs=>create_document
lo_send_request_ref->set_message_subject(
EXPORTING
ip_subject = CONV string( lv_subject ) ).
ENDIF.
ENDIF.

DATA(lo_recipient_ref) = cl_cam_address_bcs=>create_internet_address( p_email ).
IF lo_recipient_ref IS BOUND.
*Add recipient to send request
lo_send_request_ref->add_recipient(
EXPORTING
i_recipient = lo_recipient_ref
i_express = abap_true ).
ENDIF.

DATA(lt_content_txt) = VALUE soli_tab( ( line = 'Hello Team,' )
( line = 'This e-mail has been automatically generated. Please do not reply to this e-mail.' )
( line = 'Thank You!' ) ).

* Create document for e-mail content
DATA(lo_document_ref) = cl_document_bcs=>create_document(
i_type = 'TXT'
i_text = lt_content_txt
* i_subject = CONV so_obj_des( lv_subject ) ).
i_subject = space ).

IF lo_document_ref IS BOUND.
* Add document to send request
lo_send_request_ref->set_document( lo_document_ref ).
ENDIF.

* Set parameter to send e-mail immediately
lo_send_request_ref->set_send_immediately(
EXPORTING
i_send_immediately = abap_true ).

* Send email
DATA(lv_sent_to_all) = lo_send_request_ref->send( ).

* If e-mail is successful then do commit work
IF lv_sent_to_all = abap_true.
COMMIT WORK AND WAIT.
ENDIF.

This concludes the functionality.

Thank you for reading the article. I hope you found it interesting. Please feel free to share your insightful observations and suggestions.
6 Comments