More than 50 Character lengths in Email Subject with class CL_BCS
source link: https://blogs.sap.com/2023/05/03/more-than-50-character-lengths-in-email-subject-with-class-cl_bcs/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
More than 50 Character lengths in Email Subject with class CL_BCS
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_ref) = cl_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( ).
CALL METHOD 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 DEFAULT '[email protected]'.
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
CALL METHOD 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
CALL METHOD 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
CALL METHOD 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
CALL METHOD lo_send_request_ref->set_document( lo_document_ref ).
ENDIF.
* Set parameter to send e-mail immediately
CALL METHOD lo_send_request_ref->set_send_immediately
EXPORTING
i_send_immediately = abap_true.
* Send email
CALL METHOD lo_send_request_ref->send(
RECEIVING
result = DATA(lv_sent_to_all) ).
* 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.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK