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.

Populate a screen field without triggering PAI using FM DYNP_VALUES_UPDATE

This program demonstrates how to populate a screen field depending upon another field without triggering PAI using FM DYNP_VALUES_UPDATE.






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
*&---------------------------------------------------------------------*
*&Program: Z_TEST_PROGRAM
*&Creation Date: 26.07.2008 12:54:08
*&---------------------------------------------------------------------*
*& Test program for blog http://abap-explorer.blogspot.com/
*&---------------------------------------------------------------------*
REPORT z_test_program1.

PARAMETERS:
p_name TYPE uname,
p_ctry TYPE char2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_name.

PERFORM sub_populate_f4_help USING 'P_NAME'.

START-OF-SELECTION.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*& Form sub_populate_f4_help
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_RETFIELD text
*----------------------------------------------------------------------*
FORM sub_populate_f4_help USING p_retfield TYPE dynfnam.
TYPES:
BEGIN OF l_x_names,
uname TYPE uname,
END OF l_x_names.

DATA:
l_i_names TYPE STANDARD TABLE OF l_x_names INITIAL SIZE 0,
l_wa_names TYPE l_x_names,
l_i_field_tab TYPE STANDARD TABLE OF dfies INITIAL SIZE 0,
l_i_return_tab TYPE STANDARD TABLE OF ddshretval INITIAL SIZE 0,
l_wa_return_tab TYPE ddshretval,
l_i_dynpfld_mapping TYPE STANDARD TABLE OF dselc INITIAL SIZE 0.

l_wa_names-uname = 'TEST1'.
APPEND l_wa_names TO l_i_names.
l_wa_names-uname = 'TEST2'.
APPEND l_wa_names TO l_i_names.
l_wa_names-uname = 'TEST3'.
APPEND l_wa_names TO l_i_names.
l_wa_names-uname = 'TEST4'.
APPEND l_wa_names TO l_i_names.


CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'UNAME'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = p_retfield
value_org = 'S'
TABLES
value_tab = l_i_names
field_tab = l_i_field_tab
return_tab = l_i_return_tab
dynpfld_mapping = l_i_dynpfld_mapping
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc = 0.
READ TABLE l_i_return_tab INTO l_wa_return_tab INDEX 1.
p_name = l_wa_return_tab-fieldval.
ELSE.
MESSAGE e001(00) WITH 'Error while displaying F4 help'.
ENDIF.

DATA: l_i_dynpfields TYPE STANDARD TABLE OF dynpread INITIAL SIZE 0,
l_wa_dynpfields TYPE dynpread.
IF p_name = 'TEST1'.
l_wa_dynpfields-fieldname = 'P_CTRY'.
l_wa_dynpfields-fieldvalue = 'IN'.
APPEND l_wa_dynpfields TO l_i_dynpfields.
ELSE.
l_wa_dynpfields-fieldname = 'P_CTRY'.
CLEAR l_wa_dynpfields-fieldvalue.
APPEND l_wa_dynpfields TO l_i_dynpfields.
ENDIF.

CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname = sy-repid
dynumb = sy-dynnr
TABLES
dynpfields = l_i_dynpfields
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
undefind_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "sub_populate_f4_help

Get the entered value from a field on POV of another field using FM DYNP_VALUES_READ

Demo code on how to populate search help values dynamically depending upon values of another parameter on F4 button press. We have to use FM "DYNP_VALUES_READ".






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
*&---------------------------------------------------------------------*
*& Program : Z_TEST_PROGRAM
*& Created on : 23.07.2008 22:55:41
*&---------------------------------------------------------------------*
*& Test program for blog http://abap-explorer.blogspot.com/
*&---------------------------------------------------------------------*
REPORT z_test_program.

*Data Declaration
TYPES :
BEGIN OF x_spfli,
carrid TYPE s_carr_id,
connid TYPE s_conn_id,
END OF x_spfli.

DATA :
i_spfli TYPE STANDARD TABLE OF x_spfli INITIAL SIZE 0.
*Parameters
PARAMETERS:
p_carrid TYPE x_spfli-carrid OBLIGATORY,
p_connid TYPE x_spfli-connid.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_connid.

PERFORM sub_get_f4.

START-OF-SELECTION.

WRITE: / ' this is for testing'.
*&---------------------------------------------------------------------*
*& Form sub_get_f4
*&---------------------------------------------------------------------*
* Subroutine to populate F$ help
*----------------------------------------------------------------------*
FORM sub_get_f4 .
DATA:
l_i_dynpfields TYPE STANDARD TABLE OF dynpread INITIAL SIZE 0,
l_wa_dynpfields TYPE dynpread,
l_carrid TYPE s_carr_id.
*Populate the Parameter Name whoso value is required

l_wa_dynpfields-fieldname = 'P_CARRID'.
APPEND l_wa_dynpfields TO l_i_dynpfields.

*Call the FM to read that value
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-repid
dynumb = sy-dynnr
* TRANSLATE_TO_UPPER = ' '
* REQUEST = ' '
* PERFORM_CONVERSION_EXITS = ' '
* PERFORM_INPUT_CONVERSION = ' '
* DETERMINE_LOOP_INDEX = ' '
TABLES
dynpfields = l_i_dynpfields
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
invalid_parameter = 7
undefind_error = 8
double_conversion = 9
stepl_not_found = 10
OTHERS = 11
.
IF sy-subrc = 0.
*Get the value
READ TABLE l_i_dynpfields INTO l_wa_dynpfields
WITH KEY fieldname = 'P_CARRID'.
IF sy-subrc = 0.
l_carrid = l_wa_dynpfields-fieldvalue.

SELECT
carrid " Airline Code
connid " Flight Connection Number
FROM spfli " Flight schedule
INTO TABLE i_spfli WHERE carrid = l_carrid.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CONNID'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_CONNID'
value_org = 'S'
TABLES
value_tab = i_spfli.
ENDIF.
ENDIF.
ENDFORM. " sub_get_f4