Skip to Content
Author's profile photo Riccardo Escher

Pep Up Your ChaRM – Part 3: Turn Cinderella PDF-Mails into Pretty&Usefull Ones


The history of this blog series:
Pep Up Your ChaRM – Part 1: HowTo Create a Smart e-Mail Action
Pep Up Your ChaRM – Part 2: a CRMD_ORDER Slimming Cure

Back again from my vacation, I will go on in the implementation of our ZROL transaction type for authority role transports.

You can code how many working lists you like, users will always prefer to react to e-mail notifications. Did I say prefer? Users react solely to e-mails. All other tools you give them will be diligently overseen.

But normal PPF customizing will create only ugly text-only or bulky PDF messages, depending upon your SAPConnect customizing (transaction SCOT, selection of node SMTP, in the group “Supported address types” select “Internet” and press the “Set” button). Here you can choose the output format for SmartForms. Obviously you would like to select “HTM”, but this is not offered for SmartForms).

My users have many additional wishes (users without wishes are probably ill – wishes are like pigeons: the more you feed them, the more they come):

  1. the e-mail notification should come as elegant html mail which can already be viewed in the preview without need of double-clicking the PDF document and sand-glass meditation while the reader is starting
  2. the e-mail notification should have an attachment with a SAP Gui for Windows short cut that opens the right transaction (why isn’t there a solution also for the Java Gui?)
  3. when the transaction passes from the security team to the tester (status change “To Be Tested”) the role administrator wants also to be informed as CC:

I love to be a good Santa to my users, so I coded these wishes for them. Here I will show you how. The last two blogs did have much pictures, this one will carry a heavy abap load.

This is the mail notification that is sent to the tester when the security team gives it’s approval as an example of the result:


You can see that it’s a nice html-mail, that the role administrator is inserted as CC and that the recipient can open CRMD_ORDER with the right transaction number by double-clicking on the attachment.

But let’s begin!


For the SAP Gui shortcut to open the right business transaction number we need a dedicated transaction. First we create a mini report to open CRMD_ORDER with the right business transaction number:

By the way, these coding text areas look best when viewd with firefox under linux because in this environmen they are displayed with a fixed font, so all formatting is well preserved.

Then create with SE93 a “Program and screen (dialog transaction)” which calls this report:

Now we are ready to code a Gui Shortcut attachment (see later).

PPF SmartForm Mail Methods

The main method

We will now code the main static method which has to be inserted into the PPF-Customizing as Processing Method of the Smartform Action (please see Part 1 of this series). We call it EXEC_SMARTFORMS_ZROL_MAIL because it has a special status handling that is unique for this ZROL transaction type.

For this method we exploited two other methods which can be both found in the standard class CL_DOC_PROCESSING_CRM_ORDER:

  • CRM_SRVORDER_EXEC_SMART_FORM for the service order handling and
  • CRM_ISA_AUCTION_SMART_FORM for the conversion to html and the e-mail handling (there is also a Blog of Pavan Bayyapu which shows exactly the same coding with the same bugs (Sending HTML Email from SAP CRM/ERP but without quoting this source 🙂 ).

Further we adopted the technique explained in SAP Note 616383 to dynamically call the active smart form.

The coding of  CRM_ISA_AUCTION_SMART_FORM has a little drawback: when your Smartform contains graphics, some stupid mail agents implementing a proprietary version of the standard (RFC 2387) will display the html mail as an attachment and not inline as defined in the mail header (see SAP notes 730534, 810594, 927439), which dismantles the poor e-mail notification. Our solution will be to simply avoid the parameter “filename” when creating the MIME part (see down, method set_main_html).

We have also streamlined the smartform and it’s corresponding function and thrown out all useless crmd_order parameters.

Our coding doesn’t use customer tables or dictionary objects, so it should be correct as is. You have only to create with SE80 the checkpoint group ZOG_CHARM_OUT, which is useful for debugging (switch on with transaction SAAB)

At first we have to create with the class builder (SE24) our class  \ ZCL_IM_SV2I_OG_SMARTFORMS_MAIL inheriting from CL_SF_PROCESSING_PPF:


Then we insert these needed local types (see screen shot above how to find the right place):

We need some macros, too:

Now we are ready to create the static public method EXEC_SMARTFORMS_ZROL_MAIL; instead of screen shots of the signature I have copied the signature coding from the public or private sections as a commentary into the method itself, you will have to insert them without the explanation mark into the method definiton of the class builder:


I have done some re-engineering of the original method and eliminated some bugs. I hope that the in-line comments are enough explanation.

The helper methods

To enhance the readability of the coding I have sourced out some of it into dedicated private (static) methods.

First we need the method PARTNER_MAIL_ADDRESS_GET to determine a) the address of the root org because we want to use it’s generic mail address as sender instead of the user which is logged into and, when needed, also b) the address of the role administrator:

With the method PREPARE_HTML we transform the Smartform output so that it can be used as multipart MIME (we have only Unicode, so I can’t test if the coding works also in non unicode environments):

*class-methods PREPARE_HTML
*    importing
*      !PS_HTML type TRFRESULT
*    returning
*      value(PT_SOLI) type SOLI_TAB .
METHOD prepare_html.

    ls_html_data         TYPE trfresult,                    "#EC NEEDED
    ls_html_raw          LIKE LINE OF ls_html_data-content,
    lv_html_xstr         TYPE xstring,
    lv_codepage          TYPE cpcodepage,
    lv_is_unicode        TYPE rststype-sel_ok,
    lv_html_str          TYPE string,
    lv_html_len          TYPE i,
    lv_offset            TYPE i,
    lv_length            TYPE i,
    lv_diff              TYPE i,
    ls_soli              TYPE soli.

* transform the html content into a binary string
  CLEAR lv_html_xstr.
  LOOP AT ps_html-content   INTO ls_html_raw.
    CONCATENATE lv_html_xstr ls_html_raw
                            INTO lv_html_xstr IN BYTE MODE.

* Determine code page:
      language    = sy-langu
      codepage    = lv_codepage
      no_codepage = 1
      OTHERS      = 2.
  IF sy-subrc <> 0.
    lv_codepage    = 1100.
        codepage         = lv_codepage
        can_unicode      = lv_is_unicode
        codepage_unknown = 1.
    IF sy-subrc    = 0.
      IF lv_is_unicode EQ 'X'.
        lv_codepage          = 4110.                        "#EC NOTEXT

* transcode to the front end code page
  lv_html_xstr = lv_html_xstr(ps_html-length).
    EXPORTING  inbuff        = lv_html_xstr
               incode        = lv_codepage
*              OUTCODE       = '0000'       " ACTUAL CODEPAGE
               csubst        = 'X'                          "#EC NOTEXT
               substc_space  = 'X'                          "#EC NOTEXT
    IMPORTING  outbuff       = lv_html_str
               outused       = lv_html_len
    EXCEPTIONS OTHERS        = 1.

* hack the html code generated by smartform to make the
* external images appear as &lt;IMG&gt; tag in html
    IN lv_html_str      WITH '<IMG'       IGNORING CASE.    "#EC NOTEXT
    IN lv_html_str      WITH '/>'         IGNORING CASE.    "#EC NOTEXT
    IN lv_html_str      WITH '</A>'       IGNORING CASE.    "#EC NOTEXT
    IN lv_html_str      WITH '<'          IGNORING CASE.    "#EC NOTEXT
    IN lv_html_str      WITH '>'          IGNORING CASE.    "#EC NOTEXT

  lv_html_len      = STRLEN( lv_html_str ).

  lv_offset        = 0.
  lv_length        = 255.

  WHILE lv_offset  &lt; lv_html_len.

    lv_diff        = lv_html_len - lv_offset.
    IF lv_diff &gt; lv_length.
      ls_soli-line = lv_html_str+lv_offset(lv_length).
      ls_soli-line = lv_html_str+lv_offset(lv_diff).
    APPEND ls_soli TO pt_soli.
    ADD lv_length  TO lv_offset.



The wysiwyg editor of this blog is too intelligent, so he destroys the html hack coding when inserted as text area. So we had to insert the coding as preformatted inline.

With the  method PREPARE_GRAPHICS we do the same for the graphical elements which might be part of the smartform:

With the method CHARM_CREATE_GUI_SHORTCUT we create the SAP Gui shortcut that will jump into the transaction:

Finally with the method SMARTFORM_MAIL_SEND we build the MIME e-mail, attach the Gui Shortcut and send it to one or more recipients:

Usually I insert constants like ‘MYGRAPHICS/’ as class attributes, so I can find all references where they are used. But for this blog I have left them in the coding to make this blog more readable.


Hopefully the magic done to the e-mail notifications  will boost the acceptance of the ChaRM also in your company! Enjoy! And hoist some of you solutions in the SDN too, to share them brotherly.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      Hi Riccardo,
      thanks for the blog. It helped me a great deal in sending smartforms as a HTML document.
      I also used the info from the blog of Pavan to get my solution in place.

      But i run into the problem that the HTML body of the mail contains XHTML, and that is not supported by MS outlook 2007. Instead of nice lokking e-mail i now see a mail that is looking awefull.

      Is there a way of sending the e-mails as smartforms that do not contain XHTML but 'normal' HTML. Normal HTML is supported by Outlook 2007.

      Hope you know the answer.


      Bas Heikens

      Author's profile photo Riccardo Escher
      Riccardo Escher
      Blog Post Author
      Hello Bas,

      I'am sorry, but we (luckily, it seems) still avoid MS Office 2007, so I have no experience and at the moment no time to dig it.

      May be someone else knows how to tell the Smartform subsystem to generate old quirks html code.

      Best regards
      Riccardo Escher

      Deep-draw sigh:
      When will the day come where we will be rescued from this source of bad and poor software?
      It's funny that you title "No support for outlook 2007" as if Outlook would be the rule and all have to support it's brain dead oddities.
      The contrary is true: Outlook 2007 has lost support for normal XHTML and evidently has only support for the really very old and poor quirks html.
      I don't know the reason of this amputation, but it's bad, bad, bad!
      You might also ask Microsoft to reimplement support for the new html standards  (or may be there is a plugin?).
      Why should we all face the music of a nasty software company?
      Yes, I know, it's not an answer to your question, but sometimes I am really upset about this fountain of artificial problems...

      Author's profile photo Former Member
      Former Member
      Hi Riccardo,
      thanks for your reply.
      Your Deep-draw sigh really made us laugh but the message is you give is making us sad 🙁


      Bsa Heikens

      Author's profile photo Riccardo Escher
      Riccardo Escher
      Blog Post Author
      Just a small hint.

      If you don't succeed in convincing the darth vader company to reimplement the XHTML support which was already in Outlook 2003 and which is a common standard, you might try to manipulate the html conding.

      XHTML is somehow a more strict form of the older html 4, may be it's enough to replace the doctype string and possibly some constructs in the body.

      If you have a solution for this, please publish it here, it might be useful for others too.

      Author's profile photo Dariusz Dojutrek
      Dariusz Dojutrek
      How can I get such mail subject as at the first screenshot?
      Author's profile photo Riccardo Escher
      Riccardo Escher
      Blog Post Author

      you can find it in this blog in the coding for method EXEC_SMARTFORMS_ZROL_MAIL:
      * Set mail title; use constant strings and insert also the description
        CONCATENATE 'ZROL ' ls_orderadm_h-object_id ': '
           INTO lv_string RESPECTING BLANKS.
        MOVE lv_string                  TO ls_output_options-tdtitle.

      There is also  Note 876540 - PPF: Setting the title of a Smart Form document (mail)

      Author's profile photo Joyca Vervinckt
      Joyca Vervinckt

      Is it just me, or is a part of this blog missing?

      At my screen, it stops after the sentence "At first we have to create with the class builder (*SE24*) our class  *ZCL_IM_SV2I_OG_SMARTFORMS_MAIL* inheriting from *CL_SF_PROCESSING_PPF*:" and then a screenshot.

      I am really interested in the part to add someone in CC.

      Author's profile photo Riccardo Escher
      Riccardo Escher
      Blog Post Author


      yes, pitifully the migration to the new scn platform distroyed my blog entry. I have inserted it into the missing blog list ( but since August nobody takes care about 🙁