Using Floe to generate multi-UI reports

floe

Many times over the years customers have asked for reports to be sent in Excel format, and of course there are various approaches for generating such files. Traditionally, however, it has always been a bit painful to generate beautifully formatted reports for Word or Excel. In this blog I will explain how Floe can be used to generate reports that can be consumed by many different applications and devices.
Floe is an email generator, so not the obvious choice as a reporting tool. But using Floe you can easily generate files for emails or for other documents using a simple html template.
Let’s consider a simple example.
Here is an HTML template for a simple report:

We’ll return to the styling later, but you can see this consists of a table with a heading row, and then a row with 5 fields.
In Floe we build a simple email type, and use an HTML template for the output styling, and an email data user-exit for the data selection.
Firstly we define an email type based on 3 html blocks:
Top section:

<!DOCUMENT>
<html>
<head>
<style>
th {color:#FFFFFF; background-color:#305496; font-family: "Segoe UI", "Open Sans", "Helvetica"; text-align: left; padding: 5px;}
td {font-family: "Segoe UI", "Open Sans", "Helvetica"; font-weight:200; padding: 1px 5px 1px 5px; border-bottom: 1px solid #ddd;}
</style>
</head>
<body>
<table>
<tr height="40">
<th bgcolor="#305496" align="left" width="100"><font color="white">Form Type</font></th>
<th bgcolor="#305496" align="left" width="80"><font color="white">Option</font></th>
<th bgcolor="#305496" align="left" width="80"><font color="white">Version</font></th>
<th bgcolor="#305496" align="left" width="400"><font color="white">Name</font></th>
<th bgcolor="#305496" align="left" width="100"><font color="white">Category</font></th>
</tr>

Middle section (repeats):

<tr>
<td>&FTYPE&</td>
<td>&FLANG&</td>
<td>&FVER&</td>
<td>&FNAME_L&</td>
<td>&FCAT_CODE&</td>
</tr>

Bottom section:

</table>
</body>
</html>

Then we add some code in the email data user-exit:

*---------------------------------------------------------------------------*
* <<< Start of Customer Code >>> *
*---------------------------------------------------------------------------*

DATA: ls_variables TYPE /floe/vars_s,
lt_variables TYPE /floe/vars_t,
lt_ftype TYPE TABLE OF /flm/ftype.

SELECT * FROM /flm/ftype INTO TABLE lt_ftype WHERE fcat_code NE 'INST'.

CALL METHOD /floe/core=>get_data_from_table
EXPORTING
im_table = lt_ftype
IMPORTING
ex_vars = ch_variables.

*---------------------------------------------------------------------------*
* <<< End of Customer Code >>> *
*---------------------------------------------------------------------------*

Here we perform the database selection into an internal table, and then convert that table into Floe variables using method /floe/core=>get_data_from_table.
Now we’re ready to start testing.
Firstly we can see the report in the SAPGUI transaction ‘Test Email Trigger’ (/FLOE/TEST_TRIGGER), by selecting the ‘Preview’ selection flag:


Report in SAPGUI

 
If we send the email, then the report can be viewed in the email client – it works on any mobile device, web-based client, or in Outlook:


Report in Outlook

 
Since the Floe API can be called easily, it can be triggered from many different places. It’s particularly easy to see the output in a Fiori app, if Stelo is installed alongside Floe.


Report embedded in a Fiori app

 
We can also use turn the Floe report output into a document. The easiest way to do this is to define a second Floe email type, and use the ‘Attachment’ user-exit for the document generation.
Here we call the Floe API function, with the preview flag set, and then convert the output to an xstring, then append this to the attachments parameter:

*---------------------------------------------------------------------------*
* <<< Start of Customer Code >>> *
*---------------------------------------------------------------------------*

DATA: l_body TYPE string,
lx_body TYPE xstring,
ls_attachment TYPE /floe/att_s.

CALL FUNCTION '/FLOE/EMAIL_OUT'
EXPORTING
im_etype = 'EX01'
im_elang = im_elang
im_rec_emails = im_recipients
im_preview = 'X'
IMPORTING
ex_ebody = l_body.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = l_body
IMPORTING
buffer = lx_body.

ls_attachment-att_filename = 'FormType.htm'.
ls_attachment-att_description = 'Form Types'.
ls_attachment-att_data = lx_body.
APPEND ls_attachment TO ch_attachments.
*---------------------------------------------------------------------------*
* <<< End of Customer Code >>> *
*---------------------------------------------------------------------------*

Attachment User-exit

 
Now when we trigger Floe to send the email, the first email appears as an attached document within the second email:


Floe email with attachment

 
Double-click on the attachment to open it using the default browser. This will work on any device:


Report opened on iPad

 
If you save the attachment locally it can be opened (and freely edited) in Excel and Word:


Report in Excel
 

Report in Word

 
So, for an email generator, Floe is remarkably versatile! A simple email, which took 15 minutes to develop, can create a report that can be seamlessly consumed from:

  • SAPGUI
  • Fiori
  • Any email client
  • Any browser
  • Excel
  • Word

The trick lies in the styling in the html template.
Some styling is used by browers:

th {color:#FFFFFF; background-color:#305496; font-family: "Segoe UI", "Open Sans", "Helvetica"; text-align: left; padding: 5px;}
td {font-family: "Segoe UI", "Open Sans", "Helvetica"; font-weight:200; padding: 1px 5px 1px 5px; border-bottom: 1px solid #ddd;}

Much of that, however, is not understood by Excel, and so the in-line styling must also be added:

<th bgcolor="#305496" align="left" width="100"><font color="white">Form Type</font></th>

By defining the styling twice, we cater for a myriad of different methods to consume the report.