Toolbar for a Custom Container

This code demonstrates how we can create a toolbar for Custom Container...I've used a Docking Container.



















The Code:
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
*&---------------------------------------------------------------------*
*&Program: ZTEST_DOCKING
*&Creation Date: 20.08.2008 12:43:57
*&---------------------------------------------------------------------*
*& Demo Program for blog http://abap-explorer.blogspot.com/
*&---------------------------------------------------------------------*

REPORT ztest_docking.

TYPE-POOLS:icon.

DATA: docking TYPE REF TO cl_gui_docking_container,
splitter TYPE REF TO cl_gui_easy_splitter_container,
toolbar TYPE REF TO cl_gui_toolbar,
picture TYPE REF TO cl_gui_picture,
events TYPE cntl_simple_events,
event TYPE cntl_simple_event,
url TYPE cndp_url.

*----------------------------------------------------------------------*
* CLASS lcl_class DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*

CLASS lcl_class DEFINITION.

PUBLIC SECTION.

METHODS:handle_toolbar_selection

FOR EVENT function_selected OF cl_gui_toolbar
IMPORTING fcode .

ENDCLASS. "lcl_class DEFINITION

*----------------------------------------------------------------------*
* CLASS lcl_class IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*

CLASS lcl_class IMPLEMENTATION.

METHOD handle_toolbar_selection.

CASE fcode.

WHEN 'FIND'.

MESSAGE i001(00) WITH 'You have clicked "FIND" button'.

WHEN 'FINDNX'.

MESSAGE i001(00) WITH 'You have clicked "FINDNX" button'.

WHEN OTHERS.

ENDCASE.
ENDMETHOD. "handle_toolbar_selection
ENDCLASS. "lcl_class IMPLEMENTATION

PARAMETERS : p_para TYPE c LENGTH 1.
DATA:oref TYPE REF TO lcl_class.

AT SELECTION-SCREEN OUTPUT.

IF docking IS NOT BOUND.

CREATE OBJECT docking
EXPORTING
* parent =
repid = sy-repid
dynnr = sy-dynnr
side = docking->dock_at_left
extension = 1000
* style =
* lifetime = lifetime_default
* caption =
* metric = 0
* ratio =
* no_autodef_progid_dynnr =
* name =
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.

CREATE OBJECT splitter
EXPORTING
* link_dynnr =
* link_repid =
* metric = cntl_metric_dynpro
parent = docking
* orientation = 0
sash_position = 4
* with_border = 1
* name =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3
.
IF sy-subrc = 0.

CREATE OBJECT toolbar
EXPORTING
parent = splitter->top_left_container
* shellstyle =
* lifetime =
* display_mode = m_mode_horizontal
* name =
EXCEPTIONS
cntl_install_error = 1
cntl_error = 2
cntb_wrong_version = 3
OTHERS = 4
.

IF sy-subrc = 0.

DATA: l_quickinfo TYPE iconquick.

l_quickinfo = 'Find'.
CALL METHOD toolbar->add_button
EXPORTING
fcode = 'FIND'
icon = icon_search
quickinfo = l_quickinfo
butn_type = cntb_btype_button.


l_quickinfo = 'Find next'.

CALL METHOD toolbar->add_button
EXPORTING
fcode = 'FINDNX'
icon = icon_search_next
quickinfo = l_quickinfo
butn_type = cntb_btype_button.

CLEAR event.
REFRESH events.

event-eventid = toolbar->m_id_function_selected.
event-appl_event = space. " system event

APPEND event TO events.

CALL METHOD toolbar->set_registered_events
EXPORTING
events = events.

CREATE OBJECT oref.
SET HANDLER oref->handle_toolbar_selection
FOR toolbar.

IF picture IS NOT BOUND.
CREATE OBJECT picture
EXPORTING
* lifetime =
* shellstyle =
parent = splitter->bottom_right_container
* name =
EXCEPTIONS
error = 1
OTHERS = 2
.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CALL METHOD picture->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_normal
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CALL FUNCTION 'DP_PUBLISH_WWW_URL'
EXPORTING
objid = 'DOCFINDER_LOGO'
lifetime = cndp_lifetime_transaction
IMPORTING
url = url
EXCEPTIONS
dp_invalid_parameters = 1
no_object = 2
dp_error_publish = 3
OTHERS = 4.
IF sy-subrc = 0.
CALL METHOD picture->load_picture_from_url_async
EXPORTING
url = url
EXCEPTIONS
error = 1
OTHERS = 2.

IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.

1 comment:

  1. Why your programm can not run in SAP 46C?

    ReplyDelete