Dynamic Documents in ABAP Objects
Dynamic documents in ABAP Objects are HTML documents that are generated during runtime using ABAP code.
Dynamic documents enable developers to give totally a new look and feel to ABAP screens and report outputs (provided screens are used in the report output). Many features that are not possible in the traditional ABAP programming are available in dynamic documents. Why we are saying a new look and feel is it uses SAP HTML Viewer internally to bring HTML web page kind of look and feel to screens.
Dynamic documents may contain Forms and Tables, which intern can contain elements like input fields, push buttons, dropdown lists, texts, icons and pictures in different sizes. Of course some of these features are also available in ALV reports with limited usage, but not like in dynamic documents.
Figure 1: Dynamic document can contain above elements
The below mentioned are some of the features of dynamic documents.
- Large font sizes and more colour options than traditional ABAP/4 (There are some limitations also)
- ICONS and pictures in different sizes
- Input fields
- Dropdown list boxes
- Tables with row span and with column span
- Tables with frames and without frames
- Tables with buttons, icons, pictures, input elements and texts in it
The following are some SAP screen-shots, which show these features.
Figure 2: Dynamic documents with various text styles
Figure 3: Dynamic documents with Pictures
Figure 4: Dynamic documents with various types of table designs
Steps for using dynamic documents in ABAP program:
For using dynamic documents, all that we need is a screen and a custom control in that.
The following steps need to be done in the program in order to display a dynamic document in a screen.
Create a screen and a custom control in that using Screen Painter (This step is not required if we already have a screen and custom control in the program)
- Define an object reference to the class CL_DD_DOCUMENT and instantiate it.
DATA: OBJ_DD TYPE REF TO CL_DD_DOCUMENT.
CREATE OBJECT OBJ_DD.
- Dynamic document is ready now for including elements in that. The below are few methods, which we can use for adding elements to the dynamic document.
Method Description NEW_LINE To generate a line break UNDERLINE To draw a horizontal line across the full width of the document ADD_GAP To place a gap in a line ADD_TEXT To add a text ADD_PICTURE To add a picture ADD_ICON To add a SAP icon ADD_TABLE To add a table ADD_FORM To add a form area
DATA: OBJ_TABLE TYPE REF TO CL_DD_TABLE_ELEMENT.
CALL METHOD OBJ_DD->ADD_TABLE
NO_OF_COLUMNS = 2
WIDTH = 100%
TABLE = OBJ_TABLE.
- Once all the elements are included, all these elements need to be merged into a single dynamic document. This can be done using method MERGE_DOCUMENT.
For example: CALL METHOD OBJ_DD->MERGE_DOCUMENT.
Dynamic document is now ready for display/print/export.
Method DISPLAY_DOCUMENT can be used to display document in the screen. Here it is possible to display dynamic document in an existing container or in the existing document also.
Method PRINT_DOCUMENT can be used to print the dynamic document. Here system enables local printing.
Method EXPORT_DOCUMENT can be used to export the document as a HTML file into PC.
In case of the dynamic document need to be refreshed based on the user action, one should first call the method INITIALIZE_DOCUMENT to clear the dynamic document contents. This method does not clear the dynamic document object reference. So it is possible to include another set of elements in the same dynamic document.
After displaying the document, any user action can be handled in the event RESOURCES_CHANGED of the class CL_GUI_RESOURCES. For example refreshing the document contents, displaying new contents on the same document etc
Event RESOURCES_CHANGED can be triggered explicitly using the method ON_RESOURCES_CHANGED of the class CL_GUI_RESOURCES.
For showing a dynamic document in a report, a screen with custom control in it must be called from the program.
SAP provided a complete set of example programs (Package: SDYNAMICDOCUMENTS), which explain all the features mentioned in this weblog.
|DD_ADD_FORM_BUTTON||Buttons on Forms|
|DD_ADD_FORM_INPPUT||Interactive Elements: Forms with buttons|
|DD_ADD_LINK||Interactive Elements: Links|
|DD_ADD_PICTURE||SAP icons and pictures stored in BDS(transaction OAOR)|
|ADD_PICTURE||To add a picture|
|DD_SPLIT_DOCUMENT||Distribution of areas on dynamic documents|
|DD_STYLE_TABLE||Style types & list colours|
The following SAP library links contains very good documentation on dynamic documents.
The following is the performance note given in the SAP library.
Dynamic documents use the SAP HTML Viewer control. SAP does not have its own web browser, but provides a global ABAP class that provides access to the functions exposed by the underlying browser. Consequently, when you load a dynamic document, the SAP HTML Viewer control is also instantiated, and this starts a browser instance on your frontend. The consequence of this for dynamic documents is that the performance overhead associated with starting these processes may not be justified for very small documents (consisting of maybe just one or two items).
The interface of the SAP HTML Viewer is the same for all platforms, but its functions will depend on the underlying HTML browser. Under SAPGUI for Windows, it uses Microsoft Internet Explorer 4.0 (or higher) as an external browser. Under SAPGUI for Java, it uses the Ice Browser, which is installed with the GUI.
Since dynamic documents use SAP HTML Viewer control internally, whatever limitations exist for SAP HTML Viewer, same limitations hold good for dynamic documents also.
Fixed number of font sizes are only available.
SAP Library contains very good documentation and examples on this topic. My only aim on this weblog is to make you aware of such a good area in ABAP/4 OO programming.