Using Images from the SAP Graphical Framework in Smartforms
The SAP Graphical Framework (GFW) offers a lot of options to create customized graphs.However, using the generated Graph in a Smartforms Form is not directly supported.
Suppose we need to generate a printout like below printout with ABAP, you would generate each of the four graphs with the graphical framework but then you can not use it in Smartforms.
Smartforms can embed graphics that have been loaded before to the BusinessDocumentService (BDS, Transaction SE78). SAP has designed this to manually import graphics such as company logo and then use it in Smartforms but these graphics are permanently imported whereas a more dynamic approach is needed.
The solution for this problem seems quite simple:
- Generate Graph with GFW and export file in binary internal table as bitmap
- Import graphic files in BDS using a SAP function module
- Call the Smartform and pass the IDs within the Smartform interface (or use a naming convention so that Smartforms picks the correct graphs)
- Once printed and archived, delete the graphic files in BDS again
Before coming to the “But…”, here are the technical for those steps:
- Exporting a bitmap in GFW
- Importing bitmap in BDS
- Call Smartforms
- Delete bitmap from BDS
And here is the drawback:
Importing Files into BDS has a very poor performance. SAP knows about this but they did not yet find a solution for this as the whole BDS is not designed for “mass import”.
Without using any tricks, importing one graphic will at least take one minute which is not acceptable for certain requirements.
The performance is better for these types for bitmaps:
- the color depth is low
- the resolution/size is small
GFW has options to set the size of graphic but setting the color depth is not possible. The bitmap that is exported under 1) has always a very high color depth which will cause the poor performance.
The workaround for this problem is not very nice but is a stable solution:
A graphic converter needs to be installed on the SAP application server and let this converter change the color depth of bitmap before importing it in BDS. For this, the bmp is first downloaded to the application server via “Open Dataset” and then converted by a SM49 script. After that, it is re-imported.
A good converter is ImageMagick and is a commonly used software which is available for various operations systems.
It can be downloaded here: http://www.imagemagick.org.
Example SM49 script:
/usr/local/bin/convert & -white-threshold 65% -colors & -units PixelsPerInch -density & +dither &
First and Last Parameter are the import and export bitmaps. Second Parameter is the number of colours of the target bmp (e.g. 16) and third parameter is the image resolution (300×300)
Besides that, the white-threshold will make everything white that “looks like” white (SAP GFW is GUI dependant and does not always produce pure white)
After this, performance is improved by factor 6-10.
In addition to this, the whole conversion and BDS import can be placed in a function module that is called asynchronous (i.e. several bmp are converted in parallel at once)