I created an OO ALV which has a dropdown list column, for new custom screen. But the dropdown lists should be filled dynamically not statically. So I did a little research on the internet and no result :) Some people even says, it does not seem possible. I made and want to share :)
I used demo tables SFLIGHT and SBOOK. The program lists flights and customers for the each flight but in dropdown list. Look at the screenshots you will get it what i try to explain.
|
Dinamik Dropdown List 1 |
|
Dinamik Dropdown List 2 |
|
Dinamik Dropdown List 3 |
It is easier to unterstand code by runnig than by reading. Because of that reason, I wrote the sample code as copy, past and run code. Dont forget to create Screen 0100 and Container CONT0100.
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
| REPORT z_xxxx.
"Extended version of sflight table. results for the dropdown values and keyc for the differention of the values
DATA: BEGIN OF gt_flights_extended OCCURS 0.
INCLUDE STRUCTURE sflight.
DATA: result(15).
DATA: keyc TYPE int4,
END OF gt_flights_extended.
*Container definitions
DATA: r_container100 TYPE REF TO cl_gui_custom_container,
r_grid100 TYPE REF TO cl_gui_alv_grid.
*table for the dropdown data
DATA: gt_dropdown TYPE lvc_t_drop,
gs_dropdown TYPE lvc_s_drop.
*variable as a counter. it helps to differentiate
DATA: gv_counter TYPE int4 VALUE 0.
*Catalog/layout
DATA: gt_fieldcat TYPE lvc_t_fcat WITH HEADER LINE,
gs_layout TYPE lvc_s_layo.
INITIALIZATION.
PERFORM retrieve_data.
PERFORM create_catalog.
PERFORM show_alv_and_screen.
*&---------------------------------------------------------------------*
*& Form retrieve_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM retrieve_data.
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF gt_flights_extended UP TO 50 ROWS.
*use counter for each row
gv_counter = gv_counter + 1.
gt_flights_extended-keyc = gv_counter.
APPEND gt_flights_extended.
*retrieve customer id for each row
SELECT customid FROM sbook INTO (gs_dropdown-value) UP TO 10 ROWS
WHERE carrid = gt_flights_extended-carrid AND connid = gt_flights_extended-connid AND fldate = gt_flights_extended-fldate.
*use counter while saving customerid for coupling
gs_dropdown-handle = gv_counter.
APPEND gs_dropdown TO gt_dropdown.
ENDSELECT.
ENDSELECT.
ENDFORM. "retrieve_data
*&---------------------------------------------------------------------*
*& Form create_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM create_catalog.
gt_fieldcat-fieldname = 'CARRID'.
gt_fieldcat-coltext = 'CARRID'.
APPEND gt_fieldcat .
gt_fieldcat-fieldname = 'CONNID'.
gt_fieldcat-coltext = 'CONNID'.
APPEND gt_fieldcat .
gt_fieldcat-fieldname = 'FLDATE'.
gt_fieldcat-coltext = 'DATE'.
APPEND gt_fieldcat .
*Dropdown list tanımı böyle yapılmalı
gt_fieldcat-fieldname = 'RESULT'.
gt_fieldcat-coltext = 'Results'.
gt_fieldcat-checktable = '!'.
gt_fieldcat-edit = 'X'.
gt_fieldcat-drdn_hndl = 1.
gt_fieldcat-drdn_field = 'KEYC'.
APPEND gt_fieldcat .
gs_layout-zebra = 'X'.
gs_layout-no_toolbar = 'X'.
ENDFORM. "create_catalog
FORM show_alv_and_screen.
CREATE OBJECT r_container100
EXPORTING
container_name = 'CONT100'.
CREATE OBJECT r_grid100
EXPORTING
i_parent = r_container100.
*we let it know we will use this table for dropdown list
CALL METHOD r_grid100->set_drop_down_table
EXPORTING
it_drop_down = gt_dropdown.
CALL METHOD r_grid100->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
CALL METHOD r_grid100->set_table_for_first_display
EXPORTING
i_structure_name = 'GT_FLIGHTS_EXTENDED'
is_layout = gs_layout
CHANGING
it_outtab = gt_flights_extended[]
it_fieldcatalog = gt_fieldcat[].
CALL SCREEN '0100'.
ENDFORM.
|
Hiç yorum yok:
Yorum Gönder
Heyyyy !!!!
Merhabalar,
Blogumu ziyaret edip, yazımı okuduktan sonra yorum yazmanıza çok sevindim ancak lütfen kırıcı, ayrımcı, ırkçı davranmayın siyasi ve dini tartışmalara girmeyin.