Using Floe to read Aquiller letter content

Aquiller letter content can be included within Floe e-mails using a variable to store the entire Aquiller letter.

This sample function reads Aquiller content and transforms to email-ready HTML:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
FUNCTION Z_AQUILLER_LETTER_TO_EMAIL.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(IM_CTYPE) TYPE  /FLMCG/CTYPE_CODE
*"  EXPORTING
*"     REFERENCE(EX_RETURN) TYPE  BAPIRET2
*"     REFERENCE(EX_VALUE) TYPE  STRING
*"----------------------------------------------------------------------
* Reads paragraph content and transforms to email-ready HTML
* CGS Feb 2016
*"----------------------------------------------------------------------
  DATA: ls_fragments TYPE /flmcg/frag_child,
        lt_fragments TYPE /flmcg/frag_child_t,
        l_source     TYPE string,
        l_result     TYPE string.
*
* Read letter content
  CALL FUNCTION '/FLMCG/LETTER_OUT'
    EXPORTING
      IM_CTYPE                           = im_ctype
    IMPORTING
      EX_XML                             = l_source
      ex_mess                            = ex_return.

  IF sy-subrc <> 0 or ex_return-type = 'E'.
     return.
  ENDIF.

* Handle XML encoded characters
 replace all OCCURRENCES OF '&gt;' in l_source with '>'.
 replace all OCCURRENCES OF '&lt;' in l_source with '<'.
 replace all OCCURRENCES OF '&amp;' in l_source with '&'.

* Transform XML to HTML content
    CALL TRANSFORMATION z_aquiller_letter_to_email
      OPTIONS XML_HEADER = 'no'
      SOURCE XML  l_source
      RESULT XML  l_result.
*
* Remove initial tag
    shift l_result LEFT by 6 places.

* Handle embedded tags
    replace all OCCURRENCES OF '&lt;' in l_result with '<'.
    replace all OCCURRENCES OF '&gt;' in l_result with '>'.
    replace all OCCURRENCES OF '&quot;' in l_result with '"'.
    replace all OCCURRENCES OF '&apos;' in l_result with ''''.
    replace all OCCURRENCES OF '&amp;' in l_result with '&'.

    EX_VALUE = l_result.
*
ENDFUNCTION.

The function relies on an XSLT transformation as follows:

The function can be called from the Floe data user-exit. Logic must be added to determine the Aquiller letter type. (For example, a single Floe e-mail type might be used to send many Aquiller letter types.  One option is to use a Floe variable to pass in the Aquiller letter type as an import parameter when Floe is triggered.

In this example we have created a mapping between the Floe e-mail type and the Aquiller letter type in the Aquiller letter type description, so we determine the Aquiller letter type from the Floe e-mail type without the need for any custom tables.

The function can be called from the Floe user-exit as follows:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
  DATA: ls_variables   TYPE /floe/vars_s,
        lt_variables   TYPE /floe/vars_t,
        lt_return      TYPE bapiret2,
        lt_lett        TYPE TABLE OF /flmcg/lett_h,
        ls_lett        TYPE /flmcg/lett_h,
        lv_ctype_found type flag.
*
* Determine letter type
*
  clear lv_ctype_found.
  SELECT  * FROM /flmcg/lett_h INTO TABLE lt_lett.
  LOOP AT lt_lett INTO ls_lett.
    CHECK ls_lett-cdesc IS NOT INITIAL.
    IF ls_lett-cdesc+0(4) = im_etype.
      lv_ctype_found = 'X'.
      EXIT.
    ENDIF.
  ENDLOOP.
*
 check lv_ctype_found = 'X'.
*
*
* Determine e-mail title
*
  ls_variables-var_code = 'TITLE'.
  ls_variables-value = ls_lett-ctitle.
  APPEND ls_variables TO ch_variables.
*
* Get letter content from Aquiller
*
  CALL FUNCTION 'Z_AQUILLER_LETTER_TO_EMAIL'
    EXPORTING
      im_ctype  = ls_lett-ctype
    IMPORTING
      ex_return = lt_return                            "Not currently used
      ex_value  = ls_variables-value.

  ls_variables-var_code = 'AQUILLER_BODY'.
  APPEND ls_variables TO ch_variables.

See YouTube video to show the result