标签:nta syn 输出 http not sap href type 项目
使用REUSE_ALV_GRID_DISPLAY_LVC显示ALV时,如何将列、行或者具体的某个单元格设置成可编辑能输入状态?这个其实很简单,下面一一讲解:
只要将catalog中的字段edit设置成‘X‘,整列就变成能输入的了,LVC_S_FCAT-EDIT
代码:
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
|
REPORT ztest_alv_lvc_edit.
TYPES:BEGIN OF gty_ekko,
ebeln TYPE ekko-ebeln,
verkf TYPE ekko-verkf,
END OF gty_ekko.
DATA:git_ekko TYPE STANDARD TABLE OF gty_ekko.
DATA:git_fcat TYPE lvc_t_fcat,
gwa_fcat LIKE LINE OF git_fcat,
gwa_layout TYPE lvc_s_layo.
DATA:l_pos TYPE i VALUE 1.
START-OF-SELECTION.
SELECT ebeln
verkf
INTO TABLE git_ekko
FROM ekko
UP TO 10 ROWS.
CLEAR: l_pos.
l_pos = l_pos + 1.
gwa_fcat-coltext = ‘PO‘.
gwa_fcat-scrtext_l = ‘PO‘.
gwa_fcat-scrtext_m = ‘PO‘.
gwa_fcat-scrtext_s = ‘PO‘.
gwa_fcat-fieldname = ‘EBELN‘.
gwa_fcat-col_pos = l_pos.
gwa_fcat-outputlen = ‘10‘.
APPEND gwa_fcat TO git_fcat.
l_pos = l_pos + 1.
gwa_fcat-coltext = ‘PO item‘.
gwa_fcat-scrtext_l = ‘PO item‘.
gwa_fcat-scrtext_m = ‘PO item‘.
gwa_fcat-scrtext_s = ‘PO item‘.
gwa_fcat-fieldname = ‘VERKF‘.
gwa_fcat-col_pos = l_pos.
gwa_fcat-edit = ‘X‘. "设置列为可编辑状态
gwa_fcat-outputlen = ‘20‘.
APPEND gwa_fcat TO git_fcat.
gwa_layout-zebra = ‘X‘.
gwa_layout-sel_mode = ‘A‘.
gwa_layout-cwidth_opt = ‘X‘.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘
EXPORTING
i_callback_program = sy-repid
is_layout_lvc = gwa_layout
it_fieldcat_lvc = git_fcat
TABLES
t_outtab = git_ekko[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc = 0.
* BREAK-POINT.
ENDIF.
|
运行结果:
将layout中的EDIT字段赋值’X‘(LVC_S_LAYO-EDIT),就可以将整个ALV设置成可输入状态。
还有一种比较笨的办法就是将所有列都设置成可输入。
代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
gwa_layout-zebra = ‘X‘.
gwa_layout-sel_mode = ‘A‘.
gwa_layout-cwidth_opt = ‘X‘.
gwa_layout-edit = ‘X‘. "将整个ALV设置成可编辑
gwa_glay-edt_cll_cb = ‘X‘.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘
EXPORTING
i_callback_program = sy-repid
is_layout_lvc = gwa_layout
it_fieldcat_lvc = git_fcat
* i_grid_settings = gwa_glay
TABLES
t_outtab = git_ekko[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
|
如果要让单元格变成可输入,需要在alv输出内表中多定义一个保存单元格style的字段(类型:lvc_t_styl ),然后填入style属性(可编辑或者是不可编辑),最后还要在layout-stylefname中指定style的字段名。
代码如下:将EBELN设置成不可输入。
1
2
3
4
5
|
TYPES:BEGIN OF gty_ekko,
ebeln TYPE ekko-ebeln,
verkf TYPE ekko-verkf,
style TYPE lvc_t_styl, "将该字段设置为保存编辑状态的字段
END OF gty_ekko.
|
1
2
3
|
gwa_edit-fieldname = ‘EBELN‘.
gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled."设置为不可输入
INSERT gwa_edit INTO TABLE git_edit.
|
1
|
gwa_layout-stylefname = ‘STYLE‘. "指定保存编辑状态的字段名
|
style属性可以在类CL_GUI_ALV_GRID中可以找到:
MC_STYLE_DISABLED:禁止输入
MC_STYLE_ENABLED:可编辑,可输入。
需要注意的是:MC_STYLE_ENABLED输入性不能单独使用,一定在EDIT = ‘X‘(layout-edit 或者是catalog-edit)的场合下,才可以利用MC_STYLE_ENABLED进行不可编辑到编辑切换,也就是不设置edit = ‘X‘,MC_STYLE_ENABLED是不起作用的。
完整代码:
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
|
REPORT ztest_alv_lvc_edit.
TYPES:BEGIN OF gty_ekko,
ebeln TYPE ekko-ebeln,
verkf TYPE ekko-verkf,
style TYPE lvc_t_styl, "设置编辑状态字段
END OF gty_ekko.
DATA:git_ekko TYPE STANDARD TABLE OF gty_ekko,
gwa_ekko TYPE gty_ekko.
DATA:git_fcat TYPE lvc_t_fcat,
gwa_fcat LIKE LINE OF git_fcat,
gwa_layout TYPE lvc_s_layo,
gwa_glay TYPE lvc_s_glay.
DATA:gwa_edit TYPE lvc_s_styl,
git_edit TYPE lvc_t_styl.
START-OF-SELECTION.
SELECT ebeln
verkf
INTO CORRESPONDING FIELDS OF TABLE git_ekko
FROM ekko
UP TO 10 ROWS.
gwa_edit-fieldname = ‘VERKF‘.
gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled."设置为不可编辑
INSERT gwa_edit INTO TABLE git_edit.
INSERT LINES OF git_edit INTO TABLE gwa_ekko-style.
* 将除第三行的之外所有行的VERKF字段都设置成不能输入
DO 10 TIMES.
IF sy-index <> 3.
MODIFY git_ekko INDEX sy-index FROM gwa_ekko TRANSPORTING style.
ENDIF.
ENDDO.
PERFORM frm_set_catalog.
gwa_layout-zebra = ‘X‘.
gwa_layout-sel_mode = ‘A‘.
gwa_layout-cwidth_opt = ‘X‘.
gwa_layout-edit = ‘X‘. "将整个ALV设置成可编辑
gwa_layout-stylefname = ‘STYLE‘. "指定保存编辑状态的字段名
gwa_glay-edt_cll_cb = ‘X‘.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘
EXPORTING
i_callback_program = sy-repid
is_layout_lvc = gwa_layout
it_fieldcat_lvc = git_fcat
* i_grid_settings = gwa_glay
TABLES
t_outtab = git_ekko[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc = 0.
ENDIF.
*&---------------------------------------------------------------------*
*& Form FRM_SET_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_set_catalog .
DATA:l_pos TYPE i VALUE 1.
CLEAR: l_pos.
l_pos = l_pos + 1.
gwa_fcat-coltext = ‘PO‘.
gwa_fcat-scrtext_l = ‘PO‘.
gwa_fcat-scrtext_m = ‘PO‘.
gwa_fcat-scrtext_s = ‘PO‘.
gwa_fcat-fieldname = ‘EBELN‘.
gwa_fcat-col_pos = l_pos.
gwa_fcat-outputlen = ‘10‘.
APPEND gwa_fcat TO git_fcat.
l_pos = l_pos + 1.
gwa_fcat-coltext = ‘PO item‘.
gwa_fcat-scrtext_l = ‘PO item‘.
gwa_fcat-scrtext_m = ‘PO item‘.
gwa_fcat-scrtext_s = ‘PO item‘.
gwa_fcat-fieldname = ‘VERKF‘.
gwa_fcat-edit = ‘X‘. "将这列设置为可编辑
gwa_fcat-col_pos = l_pos.
gwa_fcat-outputlen = ‘20‘.
APPEND gwa_fcat TO git_fcat.
ENDFORM.
|
类似于单元格可编辑,只要将一行之外的所有行都变成不可输入,也就实现了行可编辑。逻辑如下:
1,通过layout-edit = ’X‘ 将整个行项目都变成可输入
2,将某行之外的所有行style设置成 cl_gui_alv_grid=>mc_style_disabled.
代码:
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
|
REPORT ztest_alv_lvc_edit.
TYPES:BEGIN OF gty_ekko,
ebeln TYPE ekko-ebeln,
verkf TYPE ekko-verkf,
style TYPE lvc_t_styl, "设置编辑状态字段
END OF gty_ekko.
DATA:git_ekko TYPE STANDARD TABLE OF gty_ekko,
gwa_ekko TYPE gty_ekko.
DATA:git_fcat TYPE lvc_t_fcat,
gwa_fcat LIKE LINE OF git_fcat,
gwa_layout TYPE lvc_s_layo,
gwa_glay TYPE lvc_s_glay.
DATA:gwa_edit TYPE lvc_s_styl,
git_edit TYPE lvc_t_styl.
START-OF-SELECTION.
SELECT ebeln
verkf
INTO CORRESPONDING FIELDS OF TABLE git_ekko
FROM ekko
UP TO 10 ROWS.
gwa_edit-fieldname = ‘EBELN‘.
gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT gwa_edit INTO TABLE git_edit.
gwa_edit-fieldname = ‘VERKF‘.
gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT gwa_edit INTO TABLE git_edit.
INSERT LINES OF git_edit INTO TABLE gwa_ekko-style.
* 将除第三行之外的所有行都设置成不能输入
DO 10 TIMES.
IF sy-index <> 3.
MODIFY git_ekko INDEX sy-index FROM gwa_ekko TRANSPORTING style.
ENDIF.
ENDDO.
PERFORM frm_set_catalog.
gwa_layout-zebra = ‘X‘.
gwa_layout-sel_mode = ‘A‘.
gwa_layout-cwidth_opt = ‘X‘.
gwa_layout-edit = ‘X‘. "将整个ALV设置成可编辑
gwa_layout-stylefname = ‘STYLE‘. "指定保存编辑状态的字段名
gwa_glay-edt_cll_cb = ‘X‘.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘
EXPORTING
i_callback_program = sy-repid
is_layout_lvc = gwa_layout
it_fieldcat_lvc = git_fcat
* i_grid_settings = gwa_glay
TABLES
t_outtab = git_ekko[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc = 0.
ENDIF.
*&---------------------------------------------------------------------*
*& Form FRM_SET_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_set_catalog .
DATA:l_pos TYPE i VALUE 1.
CLEAR: l_pos.
l_pos = l_pos + 1.
gwa_fcat-coltext = ‘PO‘.
gwa_fcat-scrtext_l = ‘PO‘.
gwa_fcat-scrtext_m = ‘PO‘.
gwa_fcat-scrtext_s = ‘PO‘.
gwa_fcat-fieldname = ‘EBELN‘.
gwa_fcat-col_pos = l_pos.
gwa_fcat-outputlen = ‘10‘.
APPEND gwa_fcat TO git_fcat.
l_pos = l_pos + 1.
gwa_fcat-coltext = ‘PO item‘.
gwa_fcat-scrtext_l = ‘PO item‘.
gwa_fcat-scrtext_m = ‘PO item‘.
gwa_fcat-scrtext_s = ‘PO item‘.
gwa_fcat-fieldname = ‘VERKF‘.
gwa_fcat-col_pos = l_pos.
gwa_fcat-outputlen = ‘20‘.
APPEND gwa_fcat TO git_fcat.
ENDFORM.
|
显示:
以上。
◆◆0REUSE_ALV_GRID_DISPLAY_LVC-可编辑单元格
标签:nta syn 输出 http not sap href type 项目
原文地址:https://www.cnblogs.com/lvdong18847870057/p/12539752.html