Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
RiccardoEscher
Active Participant

Preamble

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!

Preparation

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.

  DATA:
    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.
  ENDLOOP.

* Determine code page:
  CALL FUNCTION 'SCP_CODEPAGE_FOR_LANGUAGE'
    EXPORTING
      language    = sy-langu
    IMPORTING
      codepage    = lv_codepage
    EXCEPTIONS
      no_codepage = 1
      OTHERS      = 2.
  IF sy-subrc <> 0.
    lv_codepage    = 1100.
  ELSE.
    CALL FUNCTION 'SCP_GET_CODEPAGE_PROPERTIES'
      EXPORTING
        codepage         = lv_codepage
      IMPORTING
        can_unicode      = lv_is_unicode
      EXCEPTIONS
        codepage_unknown = 1.
    IF sy-subrc    = 0.
      IF lv_is_unicode EQ 'X'.
        lv_codepage          = 4110.                        "#EC NOTEXT
      ENDIF.
    ENDIF.
  ENDIF.

* transcode to the front end code page
  lv_html_xstr = lv_html_xstr(ps_html-length).
  CALL FUNCTION 'SCP_TRANSLATE_CHARS'                       "#EC NOTEXT
    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
  REPLACE ALL OCCURRENCES OF '&lt;IMG'
    IN lv_html_str      WITH '<IMG'       IGNORING CASE.    "#EC NOTEXT
  REPLACE ALL OCCURRENCES OF '/&gt;'
    IN lv_html_str      WITH '/>'         IGNORING CASE.    "#EC NOTEXT
  REPLACE ALL OCCURRENCES OF '&lt;/A&gt;'
    IN lv_html_str      WITH '</A>'       IGNORING CASE.    "#EC NOTEXT
  REPLACE ALL OCCURRENCES OF '&lt;'
    IN lv_html_str      WITH '<'          IGNORING CASE.    "#EC NOTEXT
  REPLACE ALL OCCURRENCES OF '&gt;'
    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).
    ELSE.
      ls_soli-line = lv_html_str+lv_offset(lv_diff).
    ENDIF.
    APPEND ls_soli TO pt_soli.
    ADD lv_length  TO lv_offset.

  ENDWHILE.

ENDMETHOD.

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.

Epilogue

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.

8 Comments