10-24-2014 9:32 PM
Hi,
Searching for other posts suggested the use of cl_bcs class set_message_subject method to insert a title email with more than 50 characters. I used the code below, but the title of the email is empity in SOST transaction. can help me?
*&---------------------------------------------------------------------*
*& Report ZSAPN_SEND_EMAIL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zsapn_send_email.
DATA: lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
CLASS cl_bcs DEFINITION LOAD.
DATA: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL. "document object
DATA : i_text TYPE bcsy_text. "Table for body
DATA : w_text LIKE LINE OF i_text. "work area for message body
DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL. "sender
DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL. "recipient
* data: send_request type ref to cl_bcs.
**Selection screen
PARAMETERS : p_email TYPE adr6-smtp_addr. "Emai input
PARAMETERS: p_sub TYPE string." "email subject
PARAMETERS : p_send AS CHECKBOX. "send immediatly flag
START-OF-SELECTION.
lo_send_request = cl_bcs=>create_persistent( ).
* Message body and subject
*Set body
w_text-line = 'This is the first tutorial of sending email using SAP ABAP programming by SAPNuts.com'.
APPEND w_text TO i_text.
CLEAR w_text.
w_text-line = 'SAPNuts.com is the best SAP ABAP learning portal'.
APPEND w_text TO i_text.
CLEAR w_text.
lo_document = cl_document_bcs=>create_document( "create document
i_type = 'TXT' "Type of document HTM, TXT etc TXT
i_text = i_text "email body internal table
* i_length = '12'
i_subject = ' ' ). "email subject here p_sub input parameter p_sub
* Pass the document to send request
lo_send_request->set_document( lo_document ).
data t_sub TYPE string.
t_sub = p_sub.
CALL METHOD lo_send_request->set_message_subject
EXPORTING
ip_subject = t_sub.
TRY.
lo_sender = cl_sapuser_bcs=>create( sy-uname ). "sender is the logged in user
* Set sender to send request
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
* CATCH CX_ADDRESS_BCS.
****Catch exception here
ENDTRY.
**Set recipient
lo_recipient = cl_cam_address_bcs=>create_internet_address( p_email ). "Here Recipient is email input p_email
TRY.
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
* CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .
**Catch exception here
ENDTRY.
TRY.
CALL METHOD lo_send_request->set_send_immediately
EXPORTING
i_send_immediately = p_send. "here selection screen input p_send
* CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .
**Catch exception here
ENDTRY.
TRY.
** Send email
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X' ).
COMMIT WORK.
IF sy-subrc = 0. "mail sent successfully
WRITE :/ 'Mail sent successfully'.
ENDIF.
* CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .
*catch exception here
ENDTRY.
10-26-2014 5:49 AM
Hi,
and http://scn.sap.com/people/ravi%4002 are right.
Code fragment:
PARAMETERS: p_sbjct TYPE so_obj_des .
DATA: ob_document_bcs TYPE REF TO cl_document_bcs.
DATA: ob_bcs TYPE REF TO cl_bcs.
CALL METHOD cl_document_bcs=>create_document
EXPORTING
i_type = 'HTM'
i_subject = p_sbjct
i_text = it_soli
RECEIVING
result = ob_document_bcs.
* Generate a subject up to 255 byte long
* Not visible in sost .
DATA: ip_subject TYPE string .
ip_subject = p_sbjct .
DATA: counter TYPE n LENGTH 2 .
DO 50 TIMES .
counter = sy-index .
CONCATENATE ip_subject ' long message:' counter INTO ip_subject RESPECTING BLANKS .
ENDDO .
CALL METHOD ob_bcs->set_message_subject
EXPORTING
ip_subject = ip_subject.
Result(SOST):
Result(OutLook):
Regards.
10-25-2014 7:48 AM
You've got
i_subject = ' ' ). "email subject here p_sub input parameter p_sub
wouldn't you want
i_subject = p_sub ).
10-25-2014 11:51 AM
Hi Matthev,
If we send the subject i_subject = p_sub it will come in the SOST but we can set the subject more than 50 lines.
In this following class method they are checking that subject is initial than only subject will set otherwise it wont set the subject.
CALL METHOD lo_send_request->set_message_subject
EXPORTING
ip_subject = t_sub.
Regards,
Ravi Shankar.L
10-25-2014 7:59 AM
Hi,
In SOST it can hold only 50 characters,If you want to pass more than 50 we need to pass it as empty for SOST parametet.If you send it to mail for sure it will come more than 50 characters in subject line.
But I think it is not possible to print that subject in SOST.One good news you will receive it in mail
Regards,
Ravi Shankar.L
10-26-2014 5:49 AM
Hi,
and http://scn.sap.com/people/ravi%4002 are right.
Code fragment:
PARAMETERS: p_sbjct TYPE so_obj_des .
DATA: ob_document_bcs TYPE REF TO cl_document_bcs.
DATA: ob_bcs TYPE REF TO cl_bcs.
CALL METHOD cl_document_bcs=>create_document
EXPORTING
i_type = 'HTM'
i_subject = p_sbjct
i_text = it_soli
RECEIVING
result = ob_document_bcs.
* Generate a subject up to 255 byte long
* Not visible in sost .
DATA: ip_subject TYPE string .
ip_subject = p_sbjct .
DATA: counter TYPE n LENGTH 2 .
DO 50 TIMES .
counter = sy-index .
CONCATENATE ip_subject ' long message:' counter INTO ip_subject RESPECTING BLANKS .
ENDDO .
CALL METHOD ob_bcs->set_message_subject
EXPORTING
ip_subject = ip_subject.
Result(SOST):
Result(OutLook):
Regards.
10-26-2014 6:49 AM
SAP - the workarounds company. The company that believes dispassionately - re-factoring code does not create value, keeping "R/1" code intact - does
cheers
Jānis
10-26-2014 7:18 AM
Hi,
There is some hope in that.
We still needs a multi line header in ALV (cl_gui_alv_grid etc.)
Our only hope is that a new client (A BIG multi billion company) will come along and ask for it,
They will put it in and all the rest of us will call it innovation....
Regards.
10-27-2014 4:06 PM