How to display a picture in a SAP screen

Step 1)Check what extensions are allowed in table "MIMITYPES".



Step 2)Modify the file extension of the picture from ".jpg" etc. to ".html"(any of the allowed MIME types from the previous step).





Step 3)Upload a picture through transaction SMW0 by creating a new "Z" object (you can save it in a transport if you want):







Step 4) Create a program as shown below with a Screen 0100, PF-STATUS "S0100" and Custom Container "CONT" . This program can be used to display any of the pictures uploaded through SMW0.

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
*&---------------------------------------------------------------------*
*& Report ZTEST_PICTURE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ztest_picture.
TYPE-POOLS: cndp.
DATA: ok_code TYPE syucomm,
container TYPE REF TO cl_gui_custom_container,
picture TYPE REF TO cl_gui_picture,
url TYPE cndp_url.


PARAMETERS: p_objid TYPE w3objid OBLIGATORY.

AT SELECTION-SCREEN.
SELECT COUNT(*) FROM wwwparams
WHERE objid = p_objid.
IF sy-subrc <> 0.
MESSAGE e001(00) WITH 'MIME Object not found'.
ENDIF.


START-OF-SELECTION.

IF container IS INITIAL.

CREATE OBJECT container
EXPORTING
container_name = 'CONT'
repid = 'ZTEST_PICTURE'
dynnr = '0100'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE i001(00) WITH 'Error while creating container'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
IF picture IS INITIAL.
CREATE OBJECT picture
EXPORTING
parent = container
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE i001(00) WITH 'Error while displaying picture'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
IF picture IS NOT INITIAL.

CALL FUNCTION 'DP_PUBLISH_WWW_URL'
EXPORTING
objid = p_objid
lifetime = cndp_lifetime_transaction
IMPORTING
url = url
EXCEPTIONS
OTHERS = 1.

IF sy-subrc = 0.
CALL METHOD picture->load_picture_from_url_async
EXPORTING
url = url.

CALL METHOD picture->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_fit.
ELSE.
MESSAGE i001(00) WITH 'Error while load picture'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.

CALL SCREEN 0100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'S0100'.
* SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK'.
SET SCREEN 00.
LEAVE SCREEN.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT


Test it :