Preview only show first 10 pages with watermark. For full document please download

Sending Smart Forms In Html Format

Descripción: Smart Forms in HTML

   EMBED


Share

Transcript

SENDING SMART FORMS IN THE FORM OF HTML FORMAT. Yeah there are already documents available on this topic. Only reason why i am posting this document is the difference in the code. There are some classes availabe, which will be very useful in the process of sending smart forms in the HTML format. this report program will give you an idea on how to convert smart form into html format and send it as an email along with the images(if smart form consists any ). There is no need of manipulating much on images content. All we need to do is just covert the image into binary content. There is a class in SAP CRM cl_crm_email_data , which has one method send_email, which will help us to make this process quite easy. We can easily embed the images in to the email content. Observe this class closely, may be you can get more ideas. Eventhough , i used appropriate comments in the program. It would be better if i tell you some importants points here only. There is some piece of code in the report program regarding image maniplation. the basic logic is , if there is one image in the smart form, then there will be one img tag in the converted html output. This img tag will have one attribute attribute called 'src'. The one possible value for this attribute attribute will be like this"cid:xxxxxx" .here 'xxxxxx' is image name. This image name and the value for content id, which we will send to one internal table(see the report program) , should be same. This will help the email client to find out the embedded image in the email. i have written this program assuming that smart form will wi ll have only one image.you can modify it according to your requirements. i hope users already have some basic knowledge on XSF format. please refere refere to below link if you want to know more about XSF fomrat and parameters we need to send to convert smart form into HTML format. http://help.sap.com/SAPHELP_NW04s/helpdata/EN/a5/28d3b6d26211d4b646006094192fe3/content.htm For the people, who want to investigate furhther on this topic. There is one report program available in SE38 transaction. SF_XSF_DEMO_MAIL. kindly check it. I hope it helps you. Any suggestions are welcome. Generated by Jive on 2014-12-19+01:00 1 SENDING SMART FORMS IN THE FORM OF HTML FORMAT. REPORT zsmartform_send_mail. TYPES: BEGIN OF ty_cmail_html_parser, part TYPE string, tag TYPE string, attributes TYPE tihttpnvp, is_end_tag TYPE xfeld, ref_tag_index TYPE i, END OF ty_cmail_html_parser. TYPES: lt_mail_html_parset TYPE STANDARD TABLE OF ty_cmail_html_parser. ***************************LOCAL INTERNAL TABLES***************************************************** DATA : lt_html_raw TYPE lt_archive TYPE lt_graphics TYPE lt_part TYPE lt_imgsrc tsfixml, "XML output information. tsfdara, "SAP Smart Forms: Table With Archive Indexes tsf_xsf_gr, "Image information lt_mail_html_parset, "parsed html information. TYPE TABLE OF string, lt_result TYPE lt_imageid "image source information. match_result_tab, "find stament result TYPE TABLE OF string, lt_mail_body "image ids TYPE crmt_email_mime_struc, lt_to TYPE crmt_email_recipients, "to email addresses lt_cc TYPE crmt_email_recipients. "CC email addresses. *****************local structure*********************************** DATA: ls_output_options TYPE ssfcompop, ls_xsfparam_line TYPE ssfxsfp, ls_job_output_info TYPE ssfcrescl, ls_xmloutput TYPE ssfxmlout, ls_control_parameters ls_part TYPE ssfctrlop, TYPE REF TO "output options. "parametes to get html format. "Joboutput information. "output information in XML format. "control parameters. ty_cmail_html_parser,"partsed html information Generated by Jive on 2014-12-19+01:00 2 SENDING SMART FORMS IN THE FORM OF HTML FORMAT. ls_graphic TYPE ssf_xsf_gr, ls_gr_raw TYPE bapiconten, "business service document file content ls_attribute TYPE REF TO ls_imgsrc LIKE LINE OF lt_imgsrc, ls_imageinfo ihttpnvp, "html tag attribute information. "image source information. TYPE LINE OF crmt_email_image, "image information. ls_result   "image information LIKE LINE OF lt_result, ls_mail_body "find result. LIKE LINE OF lt_mail_body, ls_recep LIKE LINE OF "message id. lt_to. "TO email addresses ****************local variables**************************************** DATA: lv_function_name lv_xstring TYPE TYPE lv_html_xstring rs38l_fnam, xstring, TYPE lo_conv lv_html_temp lv_len TYPE TYPE lv_img_src lv_activity cl_abap_conv_in_ce, "conversion class. i, TYPE "html data. "Length of the string. string, TYPE REF TO lv_imagename "Xstring data. string, TYPE lo_create_mail "Xstring data. xstring, TYPE REF TO "image source value. cl_crm_email_data, sysuuid_x, TYPE "Name of function module of smart form. "mail data object "activity guid string. ***************************constants************************************* DATA : lc_flag lc_outmode TYPE c VALUE 'X', "flag constant TYPE c VALUE 'A', "Application mode lc_graphics TYPE string lc_extract TYPE string VALUE 'GRAPHICS', VALUE 'EXTRACT', lc_contentid TYPE string VALUE 'CONTENT-ID', lc_enable VALUE 'ENABLE', lc_img lc_src TYPE string TYPE string TYPE string lc_text_html lc_body_html VALUE 'img', "parameter "Parameter "content id "enable "image tag VALUE 'src', "src property of image tag. TYPE string VALUE 'text/html', "body content type. TYPE string VALUE 'body.htm'. "body html . Generated by Jive on 2014-12-19+01:00 3 SENDING SMART FORMS IN THE FORM OF HTML FORMAT. PARAMETERS : lv_form TYPE tdsfname, lv_mail TYPE string. "smart form name. "email address "getting the smartform function module. CLEAR lv_function_name. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'   EXPORTING formname = lv_form   IMPORTING fm_name = lv_function_name   EXCEPTIONS no_form =1 no_function_module = 2 OTHERS = 3. IF sy-subrc IS INITIAL. "filling the necesary parameters to get the smartform data "in XSF (XML OUPUT FOR SMART FORMS) format. "(XML output for Smart Form) FORMAT. CLEAR ls_output_options. ls_output_options-xsf = lc_flag. " XSF Output active   ls_output_options-xsfcmode = lc_flag. " Get XSF params from program ls_output_options-xsfoutmode = lc_outmode. " A:Application   ls_output_options-xsfformat = lc_flag. ls_xsfparam_line-name = lc_graphics. ls_xsfparam_line-value = lc_extract. " Formatting ON "#EC NOTEXT "#EC NOTEXT APPEND ls_xsfparam_line TO ls_output_options-xsfpars. ls_xsfparam_line-name = lc_contentid. ls_xsfparam_line-value = lc_enable. "#EC NOTEXT "#EC NOTEXT APPEND ls_xsfparam_line TO ls_output_options-xsfpars. Generated by Jive on 2014-12-19+01:00 4 SENDING SMART FORMS IN THE FORM OF HTML FORMAT. "calling the smartform function module. CLEAR ls_control_parameters. CALL FUNCTION lv_function_name   EXPORTING control_parameters = ls_control_parameters output_options = ls_output_options user_settings =''   IMPORTING job_output_info = ls_job_output_info   EXCEPTIONS formatting_error = 1 internal_error =2 send_error =3 user_canceled OTHERS =4 = 5. check sy-subrc is initial. ls_xmloutput = ls_job_output_info-xmloutput.   lt_html_raw = ls_xmloutput-trfresult-content[]. "image information. lt_graphics[] = ls_job_output_info-xmloutput-xsfgr[]. "_____________getting the html format_______________________" CLEAR : lv_xstring,   lv_html_xstring. "converting from RAW fromat to XSTRING format. LOOP AT lt_html_raw INTO lv_xstring. CONCATENATE lv_html_xstring lv_xstring INTO lv_html_xstring IN BYTE MODE. Generated by Jive on 2014-12-19+01:00 5 SENDING SMART FORMS IN THE FORM OF HTML FORMAT.   ENDLOOP. "converting from XSTRING format to STRING format. lo_conv = cl_abap_conv_in_ce=>create( input = lv_html_xstring ). lo_conv->read( IMPORTING data = lv_html_temp ). "now we have our smart form data in the hmtl format . "we need to extract image information from the html string so that later "we can embed the image. "parse the html string tag by tag. CLEAR lt_part[]. CALL METHOD cl_crm_html_parser=>parse_html_string   EXPORTING iv_html = lv_html_temp iv_all_tags_lower_case = lc_flag   IMPORTING et_parts = lt_part. "finding the source property value of the image (IMG SRC) in the "html string. so later we can use it when embedding the   "image. CLEAR ls_part. LOOP AT lt_part REFERENCE INTO ls_part WHERE tag = lc_img. CLEAR ls_attribute. READ TABLE ls_part->attributes REFERENCE INTO ls_attribute WITH TABLE KEY name = lc_src. IF sy-subrc IS INITIAL. IF ls_attribute->value(1) = '"'. lv_len = STRLEN( ls_attribute->value ) - 2. lv_img_src = ls_attribute->value+1(lv_len).   ELSE. Generated by Jive on 2014-12-19+01:00 6 SENDING SMART FORMS IN THE FORM OF HTML FORMAT. lv_img_src = ls_attribute->value.   ENDIF. REPLACE ALL OCCURRENCES OF 'cid:' IN lv_img_src WITH space. APPEND lv_img_src TO lt_imgsrc.   ENDIF.   ENDLOOP. CLEAR lv_len. lv_len = 1. "converting each image content into binary format. LOOP AT lt_graphics INTO ls_graphic. CLEAR : ls_gr_raw,   lv_html_xstring. LOOP AT ls_graphic-content INTO ls_gr_raw. CONCATENATE lv_html_xstring ls_gr_raw-line INTO lv_html_xstring IN BYTE MODE. CLEAR ls_gr_raw.   ENDLOOP. CLEAR lv_imagename. CONCATENATE ls_graphic-graphics '.bmp' INTO lv_imagename. "embedding the images inside the body. "here content id which is there in the html string and content id that\  "we are sending in this internal table should be same. CLEAR ls_mail_body. ls_mail_body-is_attachment = lc_flag. ls_mail_body-content_bin = lv_html_xstring. CLEAR lv_img_src. READ TABLE lt_imgsrc INTO lv_img_src INDEX lv_len. Generated by Jive on 2014-12-19+01:00 7 SENDING SMART FORMS IN THE FORM OF HTML FORMAT. IF sy-subrc IS INITIAL. REPLACE FIRST OCCURRENCE OF lv_img_src IN lv_html_temp WITH lv_imagename.   ENDIF. ls_mail_body-content_id = lv_imagename. ls_mail_body-file_name = lv_imagename. ls_mail_body-mime_type = ls_graphic-httptype. APPEND ls_mail_body TO lt_mail_body. lv_len = lv_len + 1. clear lv_html_xstring.   ENDLOOP. "filling body of the mail. CLEAR ls_mail_body. ls_mail_body-content_ascii = lv_html_temp. ls_mail_body-mime_type = lc_text_html. ls_mail_body-file_name = lc_body_html. APPEND ls_mail_body TO lt_mail_body. "filling to email address CLEAR ls_recep. ls_recep-address = lv_mail . APPEND ls_recep TO lt_to. "create mail object. CREATE OBJECT lo_create_mail. "moving the subject. MOVE 'smart form as html mail' TO lo_create_mail->subject. "moving the body MOVE lt_mail_body TO lo_create_mail->body. Generated by Jive on 2014-12-19+01:00 8 SENDING SMART FORMS IN THE FORM OF HTML FORMAT. "moving to addresses MOVE lt_to TO lo_create_mail->to. "send the email. "calling method to send the email CALL METHOD cl_crm_email_utility_base=>send_email   EXPORTING iv_mail_data = lo_create_mail   RECEIVING ev_send_request_id = lv_activity. COMMIT WORK. ENDIF. Generated by Jive on 2014-12-19+01:00 9