一直以来用OO GRID的时候,i_structure_name参数都是在SE11中建立的结构,觉得非常不方便,后来发现和it_fieldcatalog配合使用可以很方便的解决这个问题。
REPORT ztest.
TABLES tdwst.
PARAMETERS p TYPE i.
DATA:BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE tdwst.
DATA:mark TYPE i,
END OF itab.
DATA:wa_fcat TYPE lvc_s_fcat,
it_fcat TYPE lvc_t_fcat,
init.
DATA:l_dock TYPE REF TO cl_gui_docking_container,
l_grid TYPE REF TO cl_gui_alv_grid.
AT SELECTION-SCREEN OUTPUT.
IF init IS INITIAL.
init = 'X'.
CREATE OBJECT l_dock
EXPORTING
side = 4
ratio = 80.
CREATE OBJECT l_grid
EXPORTING
i_parent = l_dock.
SELECT * INTO TABLE itab FROM tdwst UP TO 10 ROWS.
***不显示结构中某些字段
CLEAR wa_fcat.
wa_fcat-fieldname = 'CVLANG'.
wa_fcat-no_out = 'X'.
APPEND wa_fcat TO it_fcat.
***增加结构中没有的字段
CLEAR wa_fcat.
wa_fcat-fieldname = 'MARK'.
wa_fcat-coltext = 'MARK'.
wa_fcat-col_pos = 1.
wa_fcat-emphasize = 'C510'.
APPEND wa_fcat TO it_fcat.
CALL METHOD l_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'TDWST'
CHANGING
it_outtab = itab[]
it_fieldcatalog = it_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.
ENDIF.
阅读(807) | 评论(0) | 转发(0) |