Showing posts with label Module Pool. Show all posts
Showing posts with label Module Pool. Show all posts

HTML through ABAP

This code demonstrates how to write HTML code and raise SAP event in ABAP.






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
*&---------------------------------------------------------------------*
*&Program: Z_TEST_SOURAV_HTML
*&Creation Date: 20.08.2008 22:08:32
*&---------------------------------------------------------------------*
*& Demo Program for blog http://abap-explorer.blogspot.com/
*&---------------------------------------------------------------------*
REPORT z_test_sourav_html.
*----------------------------------------------------------------------*
* CLASS lcl_class DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_class DEFINITION.
PUBLIC SECTION.
METHODS:
main,
on_html_event FOR EVENT sapevent OF cl_gui_html_viewer
IMPORTING action frame getdata.
PROTECTED SECTION.

PRIVATE SECTION.
DATA oref TYPE REF TO cl_gui_html_viewer.
ENDCLASS. "lcl_class DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_class IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_class IMPLEMENTATION.
METHOD main.
DATA oref_lcl TYPE REF TO lcl_class.
DATA html TYPE w3htmltab.
DATA url TYPE c LENGTH 255.
CREATE OBJECT oref
EXPORTING
parent = cl_gui_container=>screen0.

DATA events TYPE cntl_simple_events.
DATA event TYPE cntl_simple_event.

event-eventid = oref->m_id_sapevent.
event-appl_event = 'X'.
APPEND event TO events.

CALL METHOD oref->set_registered_events
EXPORTING
events = events.
SET HANDLER me->on_html_event FOR oref.

APPEND '<html>' TO html.
APPEND '<body bgcolor= "#FFFFCC">' TO html.
APPEND '<font face="arial" size="2">' TO html.
APPEND '<b>Header</b>' TO html.
APPEND '<br>' TO html.
APPEND 'Text' TO html.
APPEND '</font>' TO html.
APPEND '<form name= "form1" action="SAPEVENT:save">' TO html.
APPEND 'First name:' TO html.
APPEND '<input type="text" name="firstname">' TO html.
APPEND '<br>' TO html.
APPEND 'Last name: ' TO html.
APPEND '<input type="text" name="lastname">' TO html.
APPEND '<br>' TO html.
APPEND '<input type="submit" value="Submit">' TO html.
APPEND '</form>' TO html.
APPEND '</body>' TO html.
APPEND '</html>' TO html.
oref->load_data( IMPORTING assigned_url = url
CHANGING data_table = html ).
oref->show_url( url = url ).
ENDMETHOD. "main
METHOD on_html_event.
DATA:l_string TYPE string.
l_string = getdata.

MESSAGE i001(00) WITH l_string.
ENDMETHOD. "on_html_event
ENDCLASS. "lcl_class IMPLEMENTATION

PARAMETERS: p_dummy TYPE c LENGTH 1.
AT SELECTION-SCREEN OUTPUT.
DATA:lcl_oref TYPE REF TO lcl_class.
IF lcl_oref IS NOT BOUND.
CREATE OBJECT lcl_oref.
CALL METHOD lcl_oref->main.
ENDIF.

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.

Create a SELECT-OPTIONS in a module pool screen

Create a SELECT-OPTIONS in module pool screen using two methods as shown.

Method 1

a) Create a subscreen area in your screen layout where you want to create the select options.
b) In the top include of your module pool program declare a selection screen as a subscreen e.g.

1
2
3
4
5
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.

select-options s_matnr for mara-matnr.

SELECTION-SCREEN END OF SCREEN.

c) In the PBO and PAI of the main screen where the select options needs to be created do a call subscreen of the above screen (100).

CALL SUBCREEN sub_area INCLUDING <program> <screen>

This CALL SUBSCREEN statement is necessary for transport of values between screen and program.

Note: All validations of the selection screen fields e.g. the s_matnr field created above should be done in selection screen events like AT SELECTION-SCREEN etc and not in PAI. These selection screen validations etc should be done in the top include only.

Method 2

a) Create 2 separate fields in your screen layout - one for the low value and one for the high value. Insert an icon beside the high value which will call the multiple selections popup screen on user command. Use function module COMPLEX_SELECTIONS_DIALOG to achieve this.

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
struc_tab_and_field-fieldname = con_cust.  " 'KUNNR'
struc_tab_and_field-tablename = con_kna1. " 'KNA1'.

CALL FUNCTION 'COMPLEX_SELECTIONS_DIALOG'
EXPORTING
* TITLE = ' '
text = g_titl1 " 'Customers'
tab_and_field = struc_tab_and_field
TABLES
RANGE = rng_kunnr
EXCEPTIONS
NO_RANGE_TAB = 1
CANCELLED = 2
INTERNAL_ERROR = 3
INVALID_FIELDNAME = 4
OTHERS = 5.

IF NOT rng_kunnr[] IS INITIAL.

* Read the very first entry of the range table and pass it to
* dynpro screen field

READ TABLE rng_kunnr INDEX 1.
IF sy-subrc = 0.
g_cust = rng_kunnr-low.
ENDIF.
ENDIF.


You can use the return table rng_kunnr to populate your own internal range table with the values entered by the user. Basically here you are just simulating the work of a select-options parameter by module pool screen elements.