2014 Aug 16 8:13 AM
Hi Experts,
Here i have one requirements for mailing Scenario in Z program. So i have created the custom screen as mentioned below
when i entering the messages in body
when i debugging it all the enter (space) is showing # symbol.
my requirement is i need to send what am typing in Text control.
so please suggest me any some other method is available to get my requirements?
Regards,
Thangam.P
2014 Aug 19 10:19 AM
Hi,
I created a program similar to what you have done .
Note the use of:
REPLACE
ALL OCCURRENCES OF
cl_abap_char_utilities=>cr_lf IN my_string WITH '<BR>'
So the mail will be sent as HTML .
I use cl_bcs to send the mail .
Here is the PAI:
FORM at_pai .
DATA: it_soli TYPE soli_tab.
CALL METHOD ob_gui_textedit->get_text_as_stream
IMPORTING
text = it_soli
EXCEPTIONS
OTHERS = 1.
DATA: my_string TYPE string .
CALL METHOD cl_bcs_convert=>txt_to_string
EXPORTING
it_soli = it_soli
RECEIVING
ev_string = my_string.
REPLACE
ALL OCCURRENCES OF
cl_abap_char_utilities=>cr_lf IN my_string WITH '<BR>' .
CALL METHOD cl_bcs_convert=>string_to_soli
EXPORTING
iv_string = my_string
RECEIVING
et_soli = it_soli.
DATA: ob_document_bcs TYPE REF TO cl_document_bcs.
CALL METHOD cl_document_bcs=>create_document
EXPORTING
i_type = 'HTM'
i_subject = sos33-objdes
i_text = it_soli
RECEIVING
result = ob_document_bcs.
DATA: ob_bcs TYPE REF TO cl_bcs.
DATA: ob_cam_address_bcs TYPE REF TO cl_cam_address_bcs .
ob_bcs = cl_bcs=>create_persistent( ).
CALL METHOD ob_bcs->set_document( ob_document_bcs ).
ob_cam_address_bcs = cl_cam_address_bcs=>create_internet_address( sos04-s_snd_nam ).
CALL METHOD ob_bcs->set_sender
EXPORTING
i_sender = ob_cam_address_bcs.
ob_cam_address_bcs = cl_cam_address_bcs=>create_internet_address( sos04-l_adr_name ).
CALL METHOD ob_bcs->add_recipient
EXPORTING
i_recipient = ob_cam_address_bcs.
DATA: result TYPE abap_bool .
CALL METHOD ob_bcs->send
EXPORTING
i_with_error_screen = abap_true
RECEIVING
result = result.
COMMIT WORK .
ENDFORM . "at_pai
Regards.
2014 Aug 16 8:26 AM
Hi,
imho what you are doing is OK .
Those # might be line feed etc.
Try:
DATA: it_text TYPE soli_tab.
CALL METHOD ob_gui_textedit->get_text_as_r3table
IMPORTING
table = it_text
EXCEPTIONS
OTHERS = 1.
Use CL_BCS for mail .
See BCS_EXAMPLE_1
Regards.
2014 Aug 16 9:11 AM
Hi Eitan,
First of all thanks for your valuable reply. actually which type is referring ob_gui_textedit.?
could you please elaborate little bit?
Regards,
Thangam.P
2014 Aug 16 9:17 AM
2014 Aug 16 9:24 AM
2014 Aug 16 9:33 AM
2014 Aug 17 8:33 AM
2014 Aug 19 10:19 AM
Hi,
I created a program similar to what you have done .
Note the use of:
REPLACE
ALL OCCURRENCES OF
cl_abap_char_utilities=>cr_lf IN my_string WITH '<BR>'
So the mail will be sent as HTML .
I use cl_bcs to send the mail .
Here is the PAI:
FORM at_pai .
DATA: it_soli TYPE soli_tab.
CALL METHOD ob_gui_textedit->get_text_as_stream
IMPORTING
text = it_soli
EXCEPTIONS
OTHERS = 1.
DATA: my_string TYPE string .
CALL METHOD cl_bcs_convert=>txt_to_string
EXPORTING
it_soli = it_soli
RECEIVING
ev_string = my_string.
REPLACE
ALL OCCURRENCES OF
cl_abap_char_utilities=>cr_lf IN my_string WITH '<BR>' .
CALL METHOD cl_bcs_convert=>string_to_soli
EXPORTING
iv_string = my_string
RECEIVING
et_soli = it_soli.
DATA: ob_document_bcs TYPE REF TO cl_document_bcs.
CALL METHOD cl_document_bcs=>create_document
EXPORTING
i_type = 'HTM'
i_subject = sos33-objdes
i_text = it_soli
RECEIVING
result = ob_document_bcs.
DATA: ob_bcs TYPE REF TO cl_bcs.
DATA: ob_cam_address_bcs TYPE REF TO cl_cam_address_bcs .
ob_bcs = cl_bcs=>create_persistent( ).
CALL METHOD ob_bcs->set_document( ob_document_bcs ).
ob_cam_address_bcs = cl_cam_address_bcs=>create_internet_address( sos04-s_snd_nam ).
CALL METHOD ob_bcs->set_sender
EXPORTING
i_sender = ob_cam_address_bcs.
ob_cam_address_bcs = cl_cam_address_bcs=>create_internet_address( sos04-l_adr_name ).
CALL METHOD ob_bcs->add_recipient
EXPORTING
i_recipient = ob_cam_address_bcs.
DATA: result TYPE abap_bool .
CALL METHOD ob_bcs->send
EXPORTING
i_with_error_screen = abap_true
RECEIVING
result = result.
COMMIT WORK .
ENDFORM . "at_pai
Regards.
2014 Aug 19 11:50 AM
Hi Eitan,
First of all sorry for late reply. my requirement is got working with your suggestion , one more suggestion is i need to set some Default value in PBO of Text Editor. what are all the steps involves to achieve it.
When i calling the body of the custom container should have some text.
i was tried to append directly to
DATA Text type soli_tab.
text-row = 1.
text-line = 'Dear Sir'.
append text.
text-row = 2.
text-line = 'Sales Order Not valid'.
append text.
but it is not suitable.
Please suggest me.
Regards,
Thangam.P
2014 Aug 19 12:04 PM
Hi,
At PBO:
FORM at_pbo .
DATA: title TYPE sytitle .
title = sy-title .
SET TITLEBAR 'TITLE_COMMON' WITH title .
IF ob_gui_custom_container IS INITIAL .
CREATE OBJECT ob_gui_custom_container
EXPORTING
container_name = 'OB_GUI_CUSTOM_CONTAINER'.
CREATE OBJECT ob_gui_textedit
EXPORTING
parent = ob_gui_custom_container.
DATA: it_soli TYPE soli_tab.
APPEND ' ' TO it_soli .
APPEND 'Dear Sir' TO it_soli .
APPEND ' ' TO it_soli .
APPEND 'Sales Order Not valid' TO it_soli .
CALL METHOD ob_gui_textedit->set_text_as_r3table
EXPORTING
table = it_soli
EXCEPTIONS
error_dp = 1
error_dp_create = 2
OTHERS = 3.
ENDIF .
SET PF-STATUS 'STATUS_COMMON' .
ENDFORM. "at_pbo
Regards.
Full source included .
2014 Aug 19 2:36 PM
Hi Eitan,
Really nice contribution,my requirement got fulfilled . thanks for your Help.
Regards,
Thangam.P
2014 Aug 19 5:52 PM
2014 Aug 23 2:33 PM
Hi Eitan,
Again facing one problem on my Requirements,
Consider i have one radio button,
first on for Sales Order Valid
second for Sales order invalid.
If i select first body of the msg should be "Sales Order valid".
but in this condition working well.
if i select the Second radio button
the body of the msg Showing "Sales Order valid" instead of "Sales Order invalid".
but i cleared Text table . kindly advice me where i need to change the coding ?
Regards,
Thangam.P
2014 Aug 23 2:52 PM
2014 Aug 25 8:08 AM
Hi ,
Go through the Below Code.
Here perform mail is triggering before the Mail Screen (400).
*&---------------------------------------------------------------------*
*& Form MAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form mail .
data user_email type adr6-smtp_addr.
loop at g_zcostingl_tab_itab into g_zcostingl_tab_wa where sel = 'X'.
endloop.
if sy-subrc ne 0.
message 'Select atleast one item ' type 'E' display like 'W'.
else.
* getting To Mail
select single zbpmalerts~e_mail into to from zbpmalerts inner join zbpmh
on zbpmh~styid = zbpmalerts~styid where zbpmh~vbeln = vbeln and zbpmalerts~occurence = '1'.
*getting CC mail
select single smtp_addr into user_email from adr6
inner join usr21 on usr21~addrnumber = adr6~addrnumber
and usr21~persnumber = adr6~persnumber where bname = sy-uname.
cc = user_email.
clear: text,temp_text1,temp_text.
append 'Dear Sir/Madam,' to text.
append '' to text.
concatenate ' Costing Not Ok for Sales Order - ' vbeln ' . 'into temp_text.
append temp_text to text.
call function 'ISP_CONVERT_FIRSTCHARS_TOUPPER'
exporting
input_string = g_zcostingl_tab_wa-maktx
importing
output_string = g_zcostingl_tab_wa-maktx.
append '' to text.
concatenate 'Material - ' g_zcostingl_tab_wa-matnr ' -'
'' g_zcostingl_tab_wa-maktx '.'into temp_text.
append temp_text to text.
append '' to text.
append '' to text.
append '' to text.
append 'Regard''s' to text.
call function 'ISP_CONVERT_FIRSTCHARS_TOUPPER'
exporting
input_string = sy-uname
importing
output_string = temp_text1.
append temp_text1 to text.
call screen '0400'.
endif.
endform. " MAIL
*&---------------------------------------------------------------------*
*& Module STATUS_0400 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_0400 output.
set pf-status 'STATUS_400'.
data: line_length type i value 254,
editor_container type ref to cl_gui_custom_container,
texteditor type ref to cl_gui_textedit.
data : bcc type string.
data : subject type so_obj_des value 'Costing Not Ok'.
data ob_gui_textedit type ref to cl_gui_textedit..
clear :editor_container,texteditor.
* SET TITLEBAR 'xxx'.
create object editor_container
exporting
container_name = 'TEXTEDITOR'.
create object texteditor
exporting
parent = editor_container.
call method texteditor->set_text_as_r3table
exporting
table = text
exceptions
others = 1.
call method texteditor->set_toolbar_mode
exporting
toolbar_mode = cl_gui_textedit=>true.
call method texteditor->set_statusbar_mode
exporting
statusbar_mode = cl_gui_textedit=>false.
endmodule. " STATUS_0400 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0400 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_0400 input.
case sy-ucomm.
when 'BACK' or 'EXIT' .
call screen '0100'.
when 'MAIL' or 'SAVE'.
perform mail_send.
endcase.
endmodule. " USER_COMMAND_0400 INPUT
*&---------------------------------------------------------------------*
*& Form MAIL_SEND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form mail_send .
call method texteditor->get_text_as_r3table
importing
table = text
exceptions
others = 1.
data: send_request type ref to cl_bcs,
document type ref to cl_document_bcs,
sender type ref to cl_sapuser_bcs,
recipient type ref to if_recipient_bcs,
xirecipient type ref to cl_xi_mail_recipient,
bcs_exception type ref to cx_bcs,
sent_to_all type os_boolean,
uname type xubname,
state type alautoemail,
r3syst type sysysid,
dest type ad_symbdst,
client type ad_umand,
nrecip type i,
t_hex type solix_tab,
t_hex2 type solix_tab.
data: begin of html_data,
line type string ,
end of html_data.
data lf_sender type ref to if_sender_bcs.
data: xhtml_string type xstring,
p_ttext2 type bcsy_text,
p_ttext like standard table of html_data,
sep_mail.
data : begin of wa_email,
e_mail like adr6-smtp_addr,
cc ,
bcc,
end of wa_email.
data : itab_mail like wa_email occurs 0.
data : mail like wa_email occurs 0.
split to at ',' into table mail.
loop at mail into wa_email.
append wa_email to itab_mail.
endloop.
split cc at ',' into table mail.
clear:wa_email.
loop at mail into wa_email.
wa_email-cc = 'X'.
append wa_email to itab_mail.
endloop.
split bcc at ',' into table mail.
clear:wa_email.
loop at mail into wa_email.
wa_email-bcc = 'X'.
append wa_email to itab_mail.
endloop.
data wa like line of text.
if itab_mail is not initial.
else.
message 'Please specify at least one recipient.' type 'I'.
exit.
endif.
if text is not initial .
loop at text into wa.
move wa-line to html_data-line.
append html_data to p_ttext.
move '<br/>' to html_data-line.
append html_data to p_ttext.
endloop.
else.
message 'Body Message can''t be Empty' type 'I' display like 'E'.
exit.
endif.
loop at p_ttext into html_data.
call function 'SCMS_STRING_TO_XSTRING'
exporting
text = html_data-line
importing
buffer = xhtml_string
exceptions
failed = 1
others = 2.
call function 'SCMS_XSTRING_TO_BINARY'
exporting
buffer = xhtml_string
tables
binary_tab = t_hex.
append lines of t_hex to t_hex2.
endloop.
data sender_name type adr6-smtp_addr.
try.
*--- create and set document
document = cl_document_bcs=>create_document(
i_type = 'HTM' "see table TSOTD
i_importance = '1' "1 = high,5 = normal,9 = low
i_subject = subject
i_hex = t_hex2 ).
* clear: t_hex2,t_hex2[].
*--- prevent dumps due to empty document
if document is initial.
exit.
endif.
*--- create persistent send request
send_request = cl_bcs=>create_persistent( ).
*--- add document to send request
send_request->set_document( document ).
*--- set sender
* sender = cl_sapuser_bcs=>create( 'DDIC' ).
try .
lf_sender = cl_cam_address_bcs=>create_internet_address(
i_address_string = user_email
i_address_name = sender_name ). "Display name
send_request->set_sender( sender ).
catch cx_bcs into bcs_exception..
endtry.
send_request->set_sender( lf_sender ).
loop at itab_mail into wa_email .
if wa_email-cc = 'X'.
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = wa_email-e_mail ).
send_request->add_recipient( i_recipient = recipient
i_copy = 'X'
i_express = 'X' ) .
elseif wa_email-bcc = 'X'.
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = wa_email-e_mail ).
send_request->add_recipient( i_recipient = recipient
i_blind_copy = 'X'
i_express = 'X' ) .
elseif wa_email-cc = '' and wa_email-bcc = ''.
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = wa_email-e_mail ).
send_request->add_recipient( i_recipient = recipient
i_express = 'X' ) .
endif.
endloop.
*--- send document
sent_to_all = send_request->send( ).
if sent_to_all <> 'X'. "not ok
exit.
endif.
commit work. "!!!
*---exception handling
catch cx_bcs into bcs_exception.
write bcs_exception->error_type.
exit.
endtry.
wait up to 2 seconds.
message 'Message has been sent Successfully' type 'I'.
call screen '0100'.
endform. " MAIL_SEND
Regards,
Thangam.P
2014 Aug 25 8:36 AM
Hi,
I am not in a position to go through the full code but
I noticed that you are using "call screen" even when you return to previous screen .
if you came to screen 400 using CALL SCREEN Please use LEAVE TO SCREEN 0 to return to the caller .
See http://help.sap.com/abapdocu_740/en/
read about CALL SCREEN , LEAVE TO SCREEN , SET SCREEN .
Regards.