gpt4 book ai didi

header - ALV 或任何其他网格布局中的两级列标题?

转载 作者:行者123 更新时间:2023-12-02 06:27:23 25 4
gpt4 key购买 nike

为了说明我想要的:

|         Category A            |         Category B            |  C  ||     A.A       |      A.B      |      A.A      |      A.B      |     || A.A.A | A.A.B | A.B.A | A.B.B | B.A.A | B.A.B | B.B.A | B.B.B |     |

我需要一个看起来有点像这样的标题,我想知道除了手动写入每一行之外是否还有其他方法可以做到这一点。 :D

最佳答案

内表mt_data[]cl_gui_alv_grid保存有关前端如何显示网格的信息。每个单元格都用以下字段表示在单独的行中: enter image description here

原来你可以设置mergehoriz (和 mergevert )为一个整数,定义有多少个相邻单元格将合并到单元格中。为了更改该表,我创建了一个子类 cl_gui_alv_grid并实现了方法redraw我就是这么做的。

这是我为此创建的演示报告。您需要一个带有自定义容器“CC”的 dynpro“100”和一个带有退出命令的状态“STATUS_0100”来运行它。

report zdemo_grid_merge.

call screen 100.

class cl_gui_alv_grid_merge definition inheriting from cl_gui_alv_grid.
public section.
methods redraw.
endclass.

class cl_gui_alv_grid_merge implementation.
method redraw.
field-symbols: <ms_data> type lvc_s_data.
loop at mt_data[] assigning <ms_data>.
case <ms_data>-row_pos.
when 1.
* The first row merges the first column with the next eight columns
* so it stretches for a total of nine columns
* It also merges the first row with the second row
if <ms_data>-col_pos = 1.
<ms_data>-mergehoriz = 8.
<ms_data>-mergevert = 1.
endif.

* Column ten in the first row is merged with the next five lines.
if <ms_data>-col_pos = 10.
<ms_data>-mergevert = 5.
endif.
when 3.
* Since line one and two are merged, row_pos 3 is the second line
* In the second line column one and five are extended by three columns
* to build two four column wide headers
if <ms_data>-col_pos = 1 or
<ms_data>-col_pos = 5.
<ms_data>-mergehoriz = 3.
endif.
when 4.
* Line three builds two column wide cells
if <ms_data>-col_pos = 1 or
<ms_data>-col_pos = 3 or
<ms_data>-col_pos = 5 or
<ms_data>-col_pos = 7.
<ms_data>-mergehoriz = 1.
endif.
when others.
* Everything else stays normal.
endcase.


endloop.

call method set_data_table
changing
data_table = mt_data[].

call method set_auto_redraw
exporting
enable = 1.
endmethod.
endclass.

data: go_cc type ref to cl_gui_custom_container.
data: go_grid type ref to cl_gui_alv_grid_merge.
types: begin of t_tab,
field01 type text255,
field02 type text255,
field03 type text255,
field04 type text255,
field05 type text255,
field06 type text255,
field07 type text255,
field08 type text255,
field09 type text255,
field10 type text255,
end of t_tab.
data: gt_tab type table of t_tab.


module status_0100 output.
perform init_grid.
set pf-status 'STATUS_0100'.
endmodule.

module user_command_0100_exit input.
set screen 0.
leave screen.
endmodule.

form init_grid.

data: lt_fcat type lvc_t_fcat.
data: ls_vari type disvariant.
data: ls_layo type lvc_s_layo.


if go_cc is not initial.
return.
endif.

create object go_cc
exporting
container_name = 'CC'
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.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.


create object go_grid
exporting
i_parent = go_cc
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

perform get_fcat changing lt_fcat.
ls_vari-report = sy-repid.
ls_vari-username = sy-uname.
ls_vari-handle = '0001'.
ls_layo-sel_mode = 'B'.
ls_layo-no_headers = 'X'.
ls_layo-zebra = 'X'.
ls_layo-no_toolbar = 'X'.

perform create_table.

call method go_grid->set_table_for_first_display
exporting
is_variant = ls_vari
i_save = 'A'
is_layout = ls_layo
changing
it_outtab = gt_tab
it_fieldcatalog = lt_fcat
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4.
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 go_grid->redraw.
endform.

form get_fcat changing ct_fcat type lvc_t_fcat.
data: ls_fcat type lvc_s_fcat.
data: lv_fname type lvc_fname.
data: lv_n(2) type n.

lv_fname = 'FIELD'.
do 10 times.
lv_n = sy-index.
ls_fcat-fieldname = lv_fname && lv_n.
ls_fcat-just = 'C'.
ls_fcat-outputlen = 20.
append ls_fcat to ct_fcat.
enddo.

endform.

form create_table.
data: ls_tab type t_tab.

clear ls_tab.
ls_tab-field01 = '------------- Double Line Header Stretching Over Four Cells -------------'.
ls_tab-field10 = 'Vertical Merge'.
append ls_tab to gt_tab.
append ls_tab to gt_tab.

clear ls_tab.
ls_tab-field01 = '--- Category A ---'.
ls_tab-field05 = '--- Category B ---'.
ls_tab-field09 = '--- Category C ---'.
append ls_tab to gt_tab.

clear ls_tab.
ls_tab-field01 = 'A.A'.
ls_tab-field03 = 'A.B'.
ls_tab-field05 = 'B.A'.
ls_tab-field07 = 'B.B'.
ls_tab-field09 = 'C.1'.
append ls_tab to gt_tab.

clear ls_tab.
ls_tab-field01 = 'A.A.A.1'.
ls_tab-field02 = 'A.A.B.1'.
ls_tab-field03 = 'A.B.A.1'.
ls_tab-field04 = 'A.B.B.1'.
ls_tab-field05 = 'B.A.A.1'.
ls_tab-field06 = 'B.A.B.1'.
ls_tab-field07 = 'B.B.A.1'.
ls_tab-field08 = 'B.B.B.1'.
ls_tab-field09 = 'C.2'.
append ls_tab to gt_tab.

clear ls_tab.
ls_tab-field01 = 'A.A.A.2'.
ls_tab-field02 = 'A.A.B.2'.
ls_tab-field03 = 'A.B.A.2'.
ls_tab-field04 = 'A.B.B.2'.
ls_tab-field05 = 'B.A.A.2'.
ls_tab-field06 = 'B.A.B.2'.
ls_tab-field07 = 'B.B.A.2'.
ls_tab-field08 = 'B.B.B.2'.
ls_tab-field09 = 'C.3'.
append ls_tab to gt_tab.

clear ls_tab.
append ls_tab to gt_tab.
append ls_tab to gt_tab.
endform.

为了完成 dynpro 100:

process before output.
module status_0100.

process after input.
module user_command_0100_exit at exit-command.

这是生成的网格: enter image description here

我调用redraw更改方法mt_data[]并用 set_data_table 保存到网格的实际数据表中。请注意调用refresh_table_display将摆脱这些更改,您必须调用 redraw 来跟进此操作之后每次。另外,工具栏功能会破坏合并,因此您也必须手动实现它们。

这显然离完美还很远,但我认为这是一个不错的基础。

关于header - ALV 或任何其他网格布局中的两级列标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3878386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com