ALV⾏选择及双击事件ALV功能总结Forwarded from:
⾏选择⽬前个⼈只知道两种⽅法:
W_LAYOUT    TYPE SLIS_LAYOUT_ALV,
1. 在输出内标加CHECK BOX 列类型:C(1)
*  W_STR_ALV-FIELDNAME    = 'CHECK'.            "列名
*  W_STR_ALV-EDIT          = 'X'.                                "可编辑
*  W_STR_ALV-CHECKBOX      = 'X'.                      "功能:CHECKBOX
更新ALV 判断CHECK是否为'x'.
2.在输出内标加CHECK  列,标识选中。⽤法同excel.变⾊即为选中。
W_LAYOUT-BOX_FIELDNAME = 'CHECK'.
W_layout-box_tabname = 'IT_DATA'.
其他同上。
双击事件:在定义ALV字段处:
W_STR_ALV-HOTSPOT      = 'X'.
则该列响应双击事件。
W_LAYOUT-F2CODE            = 'DIS'.    " SY-UCOMM 响应值。
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM                = SY-REPID
IT_FIELDCAT                      = W_IT_ALV
IS_LAYOUT                        = W_LAYOUT
I_CALLBACK_HTML_TOP_OF_PAGE      = 'ALV_TOP_OF_PAGE '
I_CALLBACK_USER_COMMAND          = 'USER_COMMAND'
I_CALLBACK_PF_STATUS_SET          = 'SET_PF_STATUS'
TABLES
T_OUTTAB                        = IT_DATA
EXCEPTIONS
PROGRAM_ERROR                    = 1
OTHERS                            = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ALV功能总结
⼀.关于FUNCTION 'REUSE_ALV_GRID_DISPLAY'常⽤参数说明及⽤法REPORT Z_ALV_TEST01
NO STANDARD PAGE HEADING
MESSAGE-ID ZX.
*** Global Data declear
INCLUDE Z_ALV_TEST01TOP.
INCLUDE Z_ALV_TEST01F01.
*** initial data
INITIALIZATION.
*** prepare report data
START-OF-SELECTION.
perform get_data.
perform alv_show.
*** output report
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&  Include          Z_ALV_TEST01TOP
*&---------------------------------------------------------------------*
TABLES:MARA,MBEW,EKPO,MAKT.
SELECT-OPTIONS:S_MATNR FOR MARA-MATNR.
DATA:BEGIN OF IT_MATNR OCCURS 0,
BOX TYPE C,"⽤来控制输出画⾯左测的可选择该⾏,如果选中某⾏,则该栏位值为‘X’    MATKL LIKE MARA-MATKL,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
MAKTX LIKE MAKT-MAKTX,
MEINS LIKE MARA-MEINS,
MBRSH LIKE MARA-MBRSH,
MENGE LIKE EKPO-MENGE,
END OF IT_MATNR.
TYPES:BEGIN OF WA_MATNR,
MATKL LIKE MARA-MATKL,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
MAKTX LIKE MAKT-MAKTX,
MEINS LIKE MARA-MEINS,
MBRSH LIKE MARA-MBRSH,
MENGE LIKE EKPO-MENGE,
END OF WA_MATNR.
DATA:IT_MATNR_OLD LIKE IT_MATNR OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS <MATNR> TYPE WA_MATNR.
TYPE-POOLS: slis.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
lt_sort    TYPE slis_t_sortinfo_alv WITH HEADER LINE,
it_events  TYPE slis_t_event,
lt_event_exit TYPE slis_t_event_exit,
ls_event_exit TYPE slis_event_exit,
pt_top_of_page TYPE slis_t_listheader,
gs_print TYPE slis_print_alv,
gs_layout  TYPE slis_layout_alv .
*&-------------------------------------------------------------------
*&  Include          Z_ALV_TEST01F01
*&-------------------------------------------------------------------
*&      Form  get_data
*&-------------------------------------------------------------------
FORM get_data .
SELECT *
INTO CORRESPONDING FIELDS OF TABLE IT_MATNR
FROM MARA
WHERE MATNR IN S_MATNR.
LOOP AT IT_MATNR.
SELECT SINGLE MENGE
INTO IT_MATNR-MENGE
FROM EKPO
WHERE MATNR = IT_MATNR-MATNR.
SELECT SINGLE MAKTX
INTO IT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = IT_MATNR-MATNR
AND  SPRAS = 'M'.
MODIFY IT_MATNR.
ENDLOOP.
IT_MATNR_OLD[] = IT_MATNR[].
ENDFORM.                    " get_data
*&-------------------------------------------------------------------
*&      Form  set_pf_status
*&-------------------------------------------------------------------
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ALV_PF_STATUS'.
ENDFORM. "Set_pf_status
此FORM的作⽤是在标准的ALV⼯具栏上添加⾃定义的按钮
该名称必须和FUNCTION 参数I_CALLBACK_PF_STATUS_SET  = 'SET_PF_STATUS'对应起来,即FORM的名称和变量名称要⼀样.
GUI STATUS 'ALV_PF_STATUS'是⾃⼰定义的,因为⾃定义后会把标准的ALV⼯具栏覆盖,所以还要把标准⼯具栏复制过来.
⽅法如下:
T-CODE :SE90  Program Library-- GUI Status
program name:SAPLKKBL GUI Status:STANDARD_FULLSCREEN 标准的ALV⼯具栏名称,F8运⾏,选择菜单栏GUI Status---COPY,最后输⼊你的程序名以及你⾃定义的GUI Status名,此例即为ALV_PF_STATUS,再添加按钮.
*&-------------------------------------------------------------------
*&      Form  ALV_USER_COMMAND
*&-------------------------------------------------------------------
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
form ALV_USER_COMMAND using r_ucomm like sy-ucomm
rs_selfield type slis_selfield. "响应ALV点击⾃定义按钮之后的事件
case r_ucomm.
when 'EXIT2'. "在set pf-status '9100'.的屏幕状态⾥⾯⾃定义的按钮名称
LEAVE TO SCREEN 0.
WHEN '&DATA_SAVE'.      "修改屏幕字段物料描述MAKTX,此时的&DATA_SAVE是标准GUI的参数,I_CALLBACK_PF_STATUS_SET 不要进⾏设置
LOOP AT IT_MATNR.
READ TABLE IT_MATNR_OLD ASSIGNING <MATNR>
WITH KEY MATNR = IT_MATNR-MATNR.
CHECK  IT_MATNR-MAKTX <> <matnr>-MAKTX.
UPDATE MAKT SET MAKTX = IT_MATNR-MAKTX WHERE MATNR = IT_MATNR-MATNR
AND SPRAS = 'M'.
ENDLOOP.
WHEN '&IC1'."表⽰双击
CHECK rs_selfield-tabindex > 0.
READ TABLE IT_MATNR INDEX rs_selfield-tabindex.
SET PARAMETER ID : 'MAT' FIELD IT_MATNR-MATNR.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
html实现用户注册登录代码
endcase.
rs_selfield-fieldname表⽰双击的字段名,有时候有⽤.
endform.                    "ALV_USER_COMMAND
*&---------------------------------------------------------------------*
*&      Form  alv_show
*&---------------------------------------------------------------------*
FORM alv_show .
PERFORM prepare_alv_field. "设置屏幕输出拦位的描述和格式
PERFORM eventtab_build USING it_events[].
"触发ALV事件,⽐如TOP_OF_PAGE, ALV_END_OF_LIST, ALV_END_OF_PAGE
PERFORM build_sortcat. "设置排序和分类汇总
PERFORM build_layout. "设置输出格式
PERFORM build_eventexit."设置ALV按钮增强功能
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program              = sy-cprog/SY-REPID  "程式名称
i_background_id                = 'ALV_BACKGROUND'
I_CALLBACK_PF_STATUS_SET        = 'SET_PF_STATUS'
"如果ALV使⽤⾃定义的⼯具栏,如果使⽤系统⼯具栏则忽略该⾏
I_CALLBACK_USER_COMMAND        = 'ALV_USER_COMMAND' "⾃定义⼯具栏的事件
*    I_CALLBACK_TOP_OF_PAGE        = GT_LIST_TOP_OF_PAGE[]
I_CALLBACK_HTML_TOP_OF_PAGE      = 'ALV_TOP_OF_PAGE'"⾃定义ALV表头
使⽤HTML语⾔对表头的输出格式进⾏控制,包括输出⽂字的⼤⼩,字体及颜⾊等,总之在HTML语⾔中能实现的在这⾥都能实现.具体实现见FORM ALV_TOP_OF_PAGE
当I_CALLBACK_TOP_OF_PAGE和I_CALLBACK_HTML_TOP_OF_PAGE同时设置时,只有I_CALLBACK_HTML_TOP_OF_PAGE起作⽤.
it_fieldcat                    = it_fieldcat[]"必须要设置的参数,设定输出⽬录
it_events                      = it_events[] "如果有事件触发
*    i_structure_name              = 'it_matnr'
i_save                          = 'A'          "保存样式
is_layout                      = gs_layout    "对输出样式的设定
is_print                        = gs_print
it_sort                        = lt_sort[]"如果有排序和分类汇总,需要该⾏
TABLES
t_outtab                        = it_matnr"ALV输出的内表
EXCEPTIONS
program_error                    = 1
OTHERS                            = 2.
ENDFORM.                    " alv_show
*&---------------------------------------------------------------------*
*&      Form  prepare_alv_field
*&---------------------------------------------------------------------*
FORM prepare_alv_field.
DEFINE m_fieldcat.
it_fieldcat-fieldname = &1."输出字段名,注意⼀定要是⼤写
it_fieldcat-reptext_ddic = &2. "输出显⽰的⽂字说明
*    it_fieldcat-col_pos = &3. "输出的位置,即第⼏列
*    it_fieldcat-outputlen = &4. "该显⽰⽂字所占的字长
it_fieldcat-emphasize = &3."设置输出的颜⾊
it_fieldcat-edit  = &4.    "设置为可编辑字段,可进⾏修改
append it_fieldcat.
END-OF-DEFINITION.
m_fieldcat 'MATKL' '物料組'      'C110' ''.
m_fieldcat 'MATNR' '物料'          'C210' ''.
m_fieldcat 'MTART' '物料类型'      'C310' ''.
m_fieldcat 'MBRSH' '⾏业领域'      'C410' ''.
m_fieldcat 'MEINS' '基本计量单位'  'C510' ''.
m_fieldcat 'MENGE' '数量'          'C610' ''.
m_fieldcat 'MAKTX' '物料描述'      ''    'X'.
ENDFORM.                    " prepare_alv_field
*&---------------------------------------------------------------------*
*&      Form  ALV_TOP_OF_PAGE
*&---------------------------------------------------------------------*
FORM alv_top_of_page USING cl_dd TYPE REF TO cl_dd_document.
DATA: m_p TYPE i.
DATA: m_buff TYPE string.
*表头其实完全可以是⼀个html⽂件,⾃⼰使⽤html语⾔进⾏格式控制
m_buff = '<html>'.
CALL METHOD cl_dd->html_insert
EXPORTING
contents = m_buff
CHANGING
position = m_p.
*m_buff = '<left><H2>配件报废品种汇总表</H2></left>'.
m_buff = '<H4>配件报废品种汇总</H4>'.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = m_buff
CHANGING
POSITION = m_p.
m_buff = sy-datum.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = m_buff
CHANGING
POSITION = m_p.
m_buff = '</html>'.
CALL METHOD cl_dd->html_insert
EXPORTING
contents = m_buff
CHANGING
position = m_p.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  build_sortcat
*&---------------------------------------------------------------------*
FORM build_sortcat .
CLEAR lt_sort. "此部分⽤于排序和分类汇总
MOVE 1 TO lt_sort-spos.
lt_sort-fieldname = 'MATKL'.  "表⽰按照该栏位名来汇总
lt_sort-up        = 'X'.  "表⽰按照上⾯栏位升序排列
lt_sort-subtot    = 'X'.
APPEND lt_sort.
CLEAR lt_sort.
lt_sort-spos = 1.
lt_sort-fieldname = 'MATNR'.
lt_sort-down        = 'X'.
lt_sort-subtot    = 'X'.
APPEND lt_sort.
ENDFORM.                    " build_sortcat
*&---------------------------------------------------------------------*
*&      Form  build_layout
*&---------------------------------------------------------------------*
FORM build_layout .
gs_layout-totals_text = 'totals'.
gs_layout-zebra                = 'X'.
gs_layout-no_vline            = 'X'.
gs_layout-colwidth_optimize    = 'X'."⾃动设置宽度
gs_layout-detail_popup        = 'X'.
gs_layout-detail_initial_lines = 'X'.
gs_layout-detail_titlebar      = 'Detail Title Bar'.
gs_layout-box_fieldname = 'BOX'. "⽤来控制输出画⾯左测的可选择该⾏,如果选中某⾏,
则该栏位值为‘X’
ENDFORM.                    " build_layout
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
FORM TOP_OF_PAGE.
DATA: ls_line TYPE slis_listheader.
CLEAR pt_top_of_page[].
CLEAR ls_line.
ls_line-typ  = 'H'.
SELECT SINGLE butxt INTO ls_line-info
FROM t001
WHERE bukrs = '3000'.
APPEND ls_line TO pt_top_of_page.
CLEAR ls_line.
ls_line-typ  = 'S'.
ls_line-key  = 'TITLE'.
ls_line-info = sy-title.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。