Coding Example

Use

The source code extract specified here only contains steps that are specified in Using the Document Viewer. Steps not considered are steps such as getting documents from BDS. It is prerequired that you display a document in an SAP Custom Container on screen 100 of a program. You would have to create the Custom Container area in the Screen Painter. We have called the container 'CONTAINER100'.

Data Declarations

You must declare the following data objects in your program:

DATA: custom_container TYPE REF TO cl_gui_custom_container,
document_viewer  TYPE REF TO i_oi_document_viewer.

Instantiating the Container and Document Viewer

This is best done in a PBO module. It must only happen once. You can ensure this by checking whether one of the controls (for example custom_container) is still initial, and only executing the following statements if it is.

IF custom_container IS INITIAL.
CREATE OBJECT custom_container
EXPORTING container_name = 'CONTAINER100'.

CALL METHOD C_OI_CONTAINER_CONTROL_CREATOR=>GET_DOCUMENT_VIEWER
IMPORTING viewer = document_viewer.

CALL METHOD document_viewer->init_viewer
EXPORTING parent = custom_container.

ENDIF.

Loading the Document

You can do this either in the PBO module or in the PAI event in reaction to a user action.

CALL METHOD document_viewer->view_document_from_url
EXPORTING document_url = <url of the document>
show_inplace = 'X'.

Destroying the Control

CALL METHOD document_viewer->destroy_viewer.
CALL METHOD custom_container->free.
FREE: document_viewer, custom_container.