Function实现ALV Table 三:功能设计

ALV默认提供了一些标准的功能选择供我们来操作ALV列表,但是这些功能有可能某些是我们不需要用的,想把它隐藏掉,或者某些功能无法做到,就得自定义功能按钮。

 

一、 去掉不必要的功能按钮

REUSE_ALV_GRID_DISPLAY提供了一个参数it_exculding来去掉你不想要的ALV功能。

FORM set_func_exculding TABLES pt_extab TYPE slis_t_extab.

  DATA lwa_extab LIKE LINE OF pt_extab.

 

  lwa_extab-fcode = '%SL'.

  APPEND lwa_extab TO pt_extab.

ENDFORM.                    "set_status_exculding

 

二、 自定义功能按钮

REUSE_ALV_GRID_DISPLAY有一个参数i_callback_pf_status_set用来设置ALV列表指定的GUI Status。还有一个参数i_callback_user_command用来设置用户自定义的功能动作。

1.       首先要自己创建一个GUI Status,并设置好自定义按钮

Function实现ALV Table 三:功能设计_第1张图片

2.       设置ALV使用自己创建的GUI Status

FORM set_pf_status USING rt_extab TYPE slis_t_extab.

  SET PF-STATUS 'SLVC_FULLSCREEN' EXCLUDING rt_extab.

ENDFORM.                    "set_pf_status

3.       设置用户点击自定义的功能按钮之后的动作。

FORM user_command USING r_ucomm TYPE sy-ucomm

                        rs_selfield TYPE slis_selfield.

  DATA l_message TYPE string.

  CASE r_ucomm.

    WHEN 'FUNCTION'.

      MESSAGE i000(ytest) WITH 'You Click Button ''My Func'''.

    WHEN '&IC1'.

      l_message = rs_selfield-tabindex.

      CONCATENATE 'Double Click,'

                   'Row:'

                   l_message

                   'Value:'

                   rs_selfield-value

                   'Fieldname:'

                   rs_selfield-fieldname

      INTO l_message

      SEPARATED BY space.

      MESSAGE i000(ytest) WITH l_message.

  ENDCASE.

ENDFORM.                    "user_command

 

下面是效果图

 


源代码

TYPE-POOLS slis.

 

PERFORM f_main.

 

*&---------------------------------------------------------------------*

*&      Form  f_main

*&---------------------------------------------------------------------*

*       ALV display

*----------------------------------------------------------------------*

FORM f_main.

  DATA: lt_spfli TYPE TABLE OF spfli,

        lt_fieldcat TYPE slis_t_fieldcat_alv,

        lt_extab TYPE slis_t_extab.

 

  PERFORM get_data TABLES lt_spfli.

 

  PERFORM set_catalog CHANGING lt_fieldcat.

 

  PERFORM set_func_exculding TABLES lt_extab.

 

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

      i_callback_program       = sy-repid

      it_fieldcat              = lt_fieldcat

      it_excluding             = lt_extab

      i_callback_pf_status_set = 'SET_PF_STATUS'

      i_callback_user_command  = 'USER_COMMAND'

    TABLES

      t_outtab                 = lt_spfli.

ENDFORM.                    "f_main

 

 

*&---------------------------------------------------------------------*

*&      Form  set_func_exculding

*&---------------------------------------------------------------------*

*       set function exculding

*----------------------------------------------------------------------*

*      -->PT_EXTAB   the function code which will be exculded

*----------------------------------------------------------------------*

FORM set_func_exculding TABLES pt_extab TYPE slis_t_extab.

  DATA lwa_extab LIKE LINE OF pt_extab.

 

  lwa_extab-fcode = '%SL'.

  APPEND lwa_extab TO pt_extab.

ENDFORM.                    "set_status_exculding

 

 

*&---------------------------------------------------------------------*

*&      Form  set_pf_status

*&---------------------------------------------------------------------*

*       set GUI stauts

*----------------------------------------------------------------------*

*      -->RT_EXTAB   the function code which will be exculded

*----------------------------------------------------------------------*

FORM set_pf_status USING rt_extab TYPE slis_t_extab.

  SET PF-STATUS 'SLVC_FULLSCREEN' EXCLUDING rt_extab.

ENDFORM.                    "set_pf_status

 

*&---------------------------------------------------------------------*

*&      Form  user_command

*&---------------------------------------------------------------------*

*       user command

*----------------------------------------------------------------------*

*      -->R_UCOMM      function code

*      -->RS_SELFIELD  select field structure

*----------------------------------------------------------------------*

FORM user_command USING r_ucomm TYPE sy-ucomm

                        rs_selfield TYPE slis_selfield.

  DATA l_message TYPE string.

  CASE r_ucomm.

    WHEN 'FUNCTION'.

      MESSAGE i000(ytest) WITH 'You Click Button ''My Func'''.

    WHEN '&IC1'.

      l_message = rs_selfield-tabindex.

      CONCATENATE 'Double Click,'

                   'Row:'

                   l_message

                   'Value:'

                   rs_selfield-value

                   'Fieldname:'

                   rs_selfield-fieldname

      INTO l_message

      SEPARATED BY space.

      MESSAGE i000(ytest) WITH l_message.

  ENDCASE.

ENDFORM.                    "user_command

 

*&---------------------------------------------------------------------*

*&      Form  get_data

*&---------------------------------------------------------------------*

*       Get the data for output

*----------------------------------------------------------------------*

*      -->PT_SPFLI   data internal table

*----------------------------------------------------------------------*

FORM get_data TABLES pt_spfli.

  SELECT * FROM spfli INTO TABLE pt_spfli.

ENDFORM.                    "get_data

 

 

*&---------------------------------------------------------------------*

*&      Form  set_catalog

*&---------------------------------------------------------------------*

*       set fieldcatalog for alv output

*----------------------------------------------------------------------*

FORM set_catalog CHANGING pt_fieldcat TYPE slis_t_fieldcat_alv.

  DATA lwa_fieldcat TYPE slis_fieldcat_alv.

 

  "macro

  DEFINE add_field.

    clear lwa_fieldcat.

    lwa_fieldcat-col_pos   = &1.

    lwa_fieldcat-fieldname = &2.

    lwa_fieldcat-seltext_l = &3.

    append lwa_fieldcat to pt_fieldcat.

  END-OF-DEFINITION.

 

  "add field catalog

  add_field 1  'MANDT'     'Client'.

  add_field 2  'CARRID'    'Airline Code'.

  add_field 3  'CONNID'    'Fight Number'.

  add_field 4  'COUNTRYFR' 'Country From'.

  add_field 5  'CITYFROM'  'City From'.

  add_field 6  'AIRPFROM'  'Airpart From'.

  add_field 7  'COUNTRYTO' 'Country To'.

  add_field 8  'CITYTO'    'City To'.

  add_field 9  'AIRPTO'    'Airpart To'.

  add_field 10 'FLTIME'    'Fly Time'.

  add_field 11 'DEPTIME'   'Dept Time'.

  add_field 12 'ARRTIME'   'Arrive Time'.

  add_field 13 'DISTANCE'  'Distance'.

  add_field 14 'DISTID'    'Mass unit of distance'.

  add_field 15 'FLTYPE'    'Flight type'.

  add_field 16 'PERIOD'    'Arrival n day(s) later'.

 

ENDFORM.                    "set_catalog

 

你可能感兴趣的:(function,command,table,callback,behavior,distance)