Hi Friends,

                        Am happy to share few things, what i have learned from ABAP and also it is My first blog too.

Below I have mentioned how to send mail from SAP to some other platforms  in HTML format. Here there is no need to  know about HTML language. If anyone  aware of HTML means please skip the below  3 steps.

Step1:

       Please create the format of output in Microsoft Word .

This is the format I created.

Step 2:

    Please Save it as type web Page Shown in Below Screen Shots,

Step 3:

   Just do open with note Pad. It will generates the HTML coding for our designed output.

It shows many unwanted coding please select the color code,column width , size from generated HTML Coding.

Step 4 :

Please create the ABAP program as your requirements..

Below Just am mentioning my coding.

DATA : BEGIN OF wa,
SNO
(8),
MATNR
TYPE maktMATNR,
MAKTX 
TYPE maktMAKTX,
MAKTg 
TYPE maktMAKTG,
END OF wa.
data : itab like wa OCCURS 0 .
*DATA : wa LIKE LINE OF itab.
data  color(10).
DATA : i TYPE i.

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:  xhtml_string       type xstring,
p_ttext2           
type bcsy_text,
p_ttext           
like standard table of html_data,
sep_mail.

data:
subject
type so_obj_des,
e_mail
(50).
data  flag.
data  plant type pa0001werks.
data  : begin of wa_email,
e_mail
like adr6smtp_addr,
end of wa_email.
data : itab_email like wa_email occurs 0.

data  lf_sender type ref to if_sender_bcs.

SELECT * FROM makt Into CORRESPONDING FIELDS OF TABLE itab UP TO 10 ROWS.

wa_emaile_mail = ‘abc@xyz.in‘. “ Designation Address ,here we can can add N number of mail ID to Send.
append wa_email to itab_email.

concatenate ‘<html>’
into html_dataline separated by space.
append html_data to p_ttext.

concatenate ‘<h3><span style=”font-size:20.0pt;line-height:115%;color:#548DD4″>         ‘
‘      The following materials are present in MAKT table ‘
‘</span></h3>’ into html_dataline separated by space.
append html_data to p_ttext.

concatenate ‘<table cellspacing=0 cellpadding=0 style=”border-color:WHITE”>’ ”
into html_dataline separated by space.
append html_data to p_ttext.
concatenate  ‘<tr> <td width=50 valign=top style=”color:white;’
‘background-color:#92CDDC;border:solid WHITE 1.0pt;”>’
‘<b> S.no</b></td>’ ”
into html_dataline separated by space.
append html_data to p_ttext.

concatenate  ‘<td width=50 valign=top style=”color:white;’
‘background-color:#92CDDC;border:solid WHITE 1.0pt;”>’
‘<b>Material</b></td>’ ”
into html_dataline separated by space.
append html_data to p_ttext.

concatenate  ‘<td width=250 valign=top style=”color:white;’
‘background-color:#92CDDC;border:solid WHITE 1.0pt;”>’
‘<b>Desc </b></td>’ ”
into html_dataline separated by space.
append html_data to p_ttext.

concatenate  ‘<td width=250 valign=top style=”color:white;’
‘background-color:#92CDDC;border:solid WHITE 1.0pt;”>’
‘<b>DESC in Captial </b></td>’ ”
into html_dataline separated by space.
append html_data to p_ttext.

i = 0.
loop at itab into wa.

i = i + 1.
wa
sno = i .

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_OUTPUT’
EXPORTING
INPUT         = wamatnr
IMPORTING
OUTPUT        = wamatnr
.

if sytabix mod 2 = 1.
color = ‘#B6DDE8’.
else.
color = ‘#DAEEF3’.
endif.

concatenate ‘<tr><td width=50 valign=top style=”‘
‘background-color:’ color‘  ;border:solid WHITE 1.0pt;”>’ ” into html_dataline separated by space.
append html_data to p_ttext.
concatenate ‘ ‘
wa
sno ‘</td>’ into html_dataline separated by space.
append html_data to p_ttext.

concatenate ‘ <td width=50 valign=top style=” ‘
‘background-color:’ color‘ ;border:solid WHITE 1.0pt;”>’
into html_dataline separated by space.
append html_data to p_ttext.
concatenate ‘ ‘
wa
matnr ‘</td>’ into html_dataline separated by space.
append html_data to p_ttext.

concatenate ‘ <td width=250 valign=top style=” ‘
‘background-color: ‘ color‘ ;border:solid WHITE 1.0pt;”>’
into html_dataline separated by space.
append html_data to p_ttext.
concatenate
wa
maktx ‘</td>’ into html_dataline separated by space.
append html_data to p_ttext.

concatenate ‘ <td width=250 valign=top style=” ‘
‘background-color:’  color ‘;border:solid WHITE 1.0pt;”>’
into html_dataline separated by space.
append html_data to p_ttext.
concatenate
wa
maktg ‘</td>’ into html_dataline separated by space.
append html_data to p_ttext.

endloop.

concatenate ‘</table><p class=MsoNormal> </p>’
‘</div></html>’ into html_dataline separated by space.
append html_data to p_ttext.
move ‘<strong>Regards,</strong><br/>’ to html_dataline.
append html_data to p_ttext.
move ‘<strong>  MM TEAM,</strong>’ to html_dataline.
append html_data to p_ttext.

loop at itab_email into wa_email.
loop at p_ttext into html_data.

call function ‘SCMS_STRING_TO_XSTRING’
exporting
text     = html_dataline
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.

try.

*— create and set document
document
= cl_document_bcs=>create_document(
i_type         
= ‘HTM’  “see table TSOTD
i_subject      
= ‘Material ‘
i_importance   
= ‘1’ “1 = high,5 = normal,9 = low
”       i_sensitivity   = ‘0’  “standard
”       i_text          = p_ttext
i_hex          
= t_hex2
*                     I_HEADER        =
*                     I_SENDER        =
).
*          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
= ‘123@sap.com‘ “ with help of in this mail only it will send the mail

i_address_name   = ‘DDIC’ ).  “Display name
send_request
->set_sender( sender ).

catch cx_bcs into bcs_exception..

endtry.

send_request->set_sender( lf_sender ).

recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string    
= wa_emaile_mail   ).
*i_address_NAME     = ‘DDIC’ ).

send_request->add_recipient( i_recipient = recipient
i_express  
= ‘X’ ) .

*— 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.
*    endloop.
clear: html_data ,xhtml_string, t_hex[], t_hex2[].
endloop.

Like this you can code as per your requirements. .

Here am just created the simple basic layout . we can create different format and different color coding .

We can execute this as background and foreground.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Tudor Riscutia

    Hi Thangam,

    This is a good post, but it’s not really something new  🙂

    My suggestion would be when you save the .docx file as .html, try using save as “Web Page Filtered”. This is basically the same .html, but without all the Office CSS.

    I’ve used the same thing in the past, but I chose to upload the .html on the SAP content server and later load it as the body of the email. This is optimum as you can always edit the Word and save it again. While if you have the html hard-coded inside your ABAP report, when you want to make changes (and you will) it will be quite difficult. Also, you can use tags like &&MATNR&& for dynamic values. Another nice feature is to define the table header and layout in the Word file and parse it in ABAP to replace the tags and add extra rows, but this is a little more complicated.

    Hope I gave you some good hints!

    Tudor

    (0) 
  2. Thangam Perumal Post author

    Hi Sathiskumar,

                            thanks for reading my post and Feedback next time i ll correct it.

    Regards,

            Thangam.P

    (0) 

Leave a Reply