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 :



10 comments:

  1. thnx for the descriptive tutorial...saved me a lot of time :)

    ReplyDelete
  2. Hello! Thanks for your tutorial, they have all been helping me a lot... but with this one, though, I get the following message:

    "Screen does not exist"... Do you know why is this so?
    What I need to do is a report with a client's information as well as displaying the client's photo. Any information will be well received. Thanks!
    cgyst@hotmail.com

    ReplyDelete
  3. "Screen does not exist"... Do you know why is this so?

    answer:
    you firt must create the Dynpro 100 and next
    you need create a container called 'CONT' in the Dynpro 0100.

    ReplyDelete
  4. great post , helped a lot

    ReplyDelete
  5. Great post yaar. Thank you very much

    ReplyDelete
  6. really good piece of information, I had come to know about your site from my friend shubodh, kolkatta,i have read atleast nine posts of yours by now, and let me tell you, your site gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanks a lot once again, Regards, sap

    ReplyDelete
  7. Thank you!! Very useful to replace obsolete function WWW_GET_MIME_OBJECT

    ReplyDelete
  8. hi I have question, because the picture will also move if we scroll up/down. Can I ask you I can fix it? My problem is, I want the picture stay base on the position I set. Thanks

    ReplyDelete
  9. Thank you so much for your clear explanation with screenshots really nice - swathi

    ReplyDelete