Showing posts with label Useful Function Modules. Show all posts
Showing posts with label Useful Function Modules. Show all posts

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

Call Maintenance View from a program using FM VIEW_MAINTENANCE_CALL

This code demonstrates how to call function module VIEW_MAINTENANCE_CALL to call a table maintenance view from any program.







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
*&---------------------------------------------------------------------*
*& Report Z_TEST_PROGRAM
*&---------------------------------------------------------------------*
*& Demo program for blog http://abap-explorer.blogspot.com/
*&---------------------------------------------------------------------*
REPORT z_test_program.
DATA:
i_sellist TYPE STANDARD TABLE OF vimsellist INITIAL SIZE 0,
i_header TYPE STANDARD TABLE OF vimdesc INITIAL SIZE 0,
i_namtab TYPE STANDARD TABLE OF vimnamtab INITIAL SIZE 0.

PARAMETERS: p_view TYPE viewname MATCHCODE OBJECT viewmaint OBLIGATORY.

AT SELECTION-SCREEN.

CALL FUNCTION 'VIEW_GET_DDIC_INFO'
EXPORTING
viewname = p_view
* VARIANT_FOR_SELECTION = ' '
TABLES
sellist = i_sellist
x_header = i_header
x_namtab = i_namtab
EXCEPTIONS
no_tvdir_entry = 1
table_not_found = 2
OTHERS = 3
.
IF sy-subrc <> 0.
data: l_message type NATXT.
CONCATENATE 'Table/View' p_view
INTO l_message SEPARATED BY space.
MESSAGE e001(00) WITH l_message ' not in the Dictonary'.
ENDIF.

START-OF-SELECTION.

CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
action = 'S'
view_name = p_view
EXCEPTIONS
client_reference = 1
foreign_lock = 2
invalid_action = 3
no_clientindependent_auth = 4
no_database_function = 5
no_editor_function = 6
no_show_auth = 7
no_tvdir_entry = 8
no_upd_auth = 9
only_show_allowed = 10
system_failure = 11
unknown_field_in_dba_sellist = 12
view_not_found = 13
maintenance_prohibited = 14
OTHERS = 15
.

IF sy-subrc <> 0.
MESSAGE i001(00) WITH 'Error while calling the view'.
LEAVE LIST-PROCESSING.
ENDIF.