ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ALV最常用的显示功能:颜色,超链接,ICON,Symbol,Checkbox

ALV最常用的显示功能:颜色,超链接,ICON,Symbol,Checkbox

原创 Linux操作系统 作者:SAP骑士 时间:2009-07-03 10:19:53 0 删除 编辑

ALV最常用的显示功能:颜色(行,列,单元格),超链接,ICONSymbol,异常状态,Checkbox

 

 

源代码:

INCLUDE .

INCLUDE .

 

TYPE-POOLS slis.

 

TABLES spfli.

 

TYPES: BEGIN OF ty_layout,

        exception(1),

        checkbox,

        icon TYPE icon_d,

        symbol TYPE icon_d,

        color(4),

        cell_color TYPE slis_t_specialcol_alv,

        hyperlink TYPE string,

        link_handle TYPE int4,

       END OF ty_layout.

TYPES BEGIN OF ty_spfli.

INCLUDE TYPE ty_layout.

INCLUDE TYPE spfli.

TYPES END OF ty_spfli.

TYPES ty_tab_spfli TYPE ty_spfli OCCURS 0.

 

PERFORM. f_main.

 

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

*&      Form  f_main

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

*       ALV display

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

FORM. f_main.

  DATA: lt_spfli TYPE ty_tab_spfli,

        lt_fieldcat TYPE slis_t_fieldcat_alv,

        ls_layout TYPE slis_layout_alv,

        lt_hyperlink TYPE lvc_t_hype,

        lt_add_fieldcat TYPE slis_t_add_fieldcat.

 

  PERFORM. get_data TABLES lt_spfli.

 

  PERFORM. set_catalog CHANGING lt_fieldcat.

 

  PERFORM. set_layout USING ls_layout.

 

  PERFORM. hyperlink_build TABLES lt_hyperlink.

 

  PERFORM. add_fieldcat_build TABLES lt_add_fieldcat.

 

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

      i_callback_program = sy-repid

      i_grid_title       = 'Xin''s ALV'

      it_fieldcat        = lt_fieldcat

      it_hyperlink       = lt_hyperlink

      is_layout          = ls_layout

      it_add_fieldcat    = lt_add_fieldcat

    TABLES

      t_outtab           = lt_spfli.

ENDFORM.                    "f_main

 

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

*&      Form  set_layout

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

*       text

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

*      -->P_LAYOUT   text

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

FORM. set_layout USING p_layout TYPE slis_layout_alv.

  p_layout-zebra = 'X'.

  p_layout-colwidth_optimize = 'X'.

  p_layout-window_titlebar = 'LinHuanXin''s ALV Demo'.

  p_layout-no_hline = 'X'.

  p_layout-no_vline = 'X'.

  p_layout-info_fieldname = 'COLOR'.

  p_layout-coltab_fieldname = 'CELL_COLOR'.

  p_layout-lights_fieldname = 'EXCEPTION'.

ENDFORM.                    "set_layout

 

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

*&      Form  get_data

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

*       Get the data for output

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

*      -->PT_SPFLI   data internal table

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

FORM. get_data TABLES pt_spfli TYPE ty_tab_spfli.

 

  DATA: lt_cell TYPE slis_t_specialcol_alv,

        ls_cell LIKE LINE OF lt_cell,

        lwa_spfli LIKE LINE OF pt_spfli.

 

  SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE pt_spfli.

 

  LOOP AT pt_spfli INTO lwa_spfli.

 

    IF lwa_spfli-distid = 'KM'.

      lwa_spfli-color = 'C610'.

    ENDIF.

    IF lwa_spfli-distance < 1000.

      CLEAR ls_cell.

      REFRESH lt_cell.

      ls_cell-fieldname = 'DISTANCE'.

      ls_cell-color-col = '4'.

      ls_cell-color-int = '1'.

      ls_cell-color-inv = '0'.

      ls_cell-nokeycol = 'X'.

      APPEND ls_cell TO lt_cell.

      lwa_spfli-cell_color = lt_cell.

      lwa_spfli-checkbox = 'X'.

      lwa_spfli-exception = '1'.

    ELSE.

      lwa_spfli-exception = '2'.

    ENDIF.

 

    lwa_spfli-link_handle = sy-tabix.

    lwa_spfli-hyperlink = 'www.163.com'.

    lwa_spfli-icon = icon_detail.

    lwa_spfli-symbol = sym_folder.

    MODIFY pt_spfli FROM lwa_spfli.

  ENDLOOP.

ENDFORM.                    "get_data

 

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

*&      Form  add_fieldcat_build

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

*       text

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

*      -->PT_FIELDCAT  text

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

FORM. add_fieldcat_build TABLES pt_fieldcat TYPE slis_t_add_fieldcat.

  DATA lwa_fieldcat LIKE LINE OF pt_fieldcat.

 

  lwa_fieldcat-fieldname = 'HYPERLINK'.

  lwa_fieldcat-web_field = 'LINK_HANDLE'.

  APPEND lwa_fieldcat TO pt_fieldcat.

ENDFORM.                    "get_data

 

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

*&      Form  hyperlink_build

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

*       text

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

*      -->PT_HYPERLINK  text

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

FORM. hyperlink_build TABLES pt_hyperlink TYPE lvc_t_hype.

  DATA lwa_hyperlink LIKE LINE OF pt_hyperlink.

 

  DO 13 TIMES.

    lwa_hyperlink-handle = sy-index.

    lwa_hyperlink-href   = 'www.sina.com.cn'.

    APPEND lwa_hyperlink TO pt_hyperlink.

  ENDDO.

  DO 13 TIMES.

    lwa_hyperlink-handle = 13 + sy-index.

    lwa_hyperlink-href   = 'www.163.com'.

    APPEND lwa_hyperlink TO pt_hyperlink.

  ENDDO.

 

ENDFORM.                    "hyperlink_build

 

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

*&      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-fieldname = &1.

    lwa_fieldcat-seltext_l = &2.

    lwa_fieldcat-emphasize = &3.

    lwa_fieldcat-key = &4.

    lwa_fieldcat-fix_column = &4.

    append lwa_fieldcat to pt_fieldcat.

  END-OF-DEFINITION.

 

  "add field catalog

  add_field 'MANDT'     'Client'                 ''     'X'.

  add_field 'CARRID'    'Airline Code'           ''     'X'.

  add_field 'CONNID'    'Fight Number'           ''     'X'.

  add_field 'COUNTRYFR' 'Country From'           ''     ''.

  add_field 'CITYFROM'  'City From'              ''     ''.

  add_field 'AIRPFROM'  'Airpart From'           ''     ''.

  add_field 'COUNTRYTO' 'Country To'             'C510' ''.

  add_field 'CITYTO'    'City To'                ''     ''.

  add_field 'AIRPTO'    'Airpart To'             ''     ''.

  add_field 'FLTIME'    'Fly Time'               ''     ''.

  add_field 'DEPTIME'   'Dept Time'              ''     ''.

  add_field 'ARRTIME'   'Arrive Time'            ''     ''.

  add_field 'DISTANCE'  'Distance'               ''     ''.

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

  add_field 'FLTYPE'    'Flight type'            ''     ''.

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

  add_field 'HYPERLINK' 'HYPERLINK'              ''     ''.

 

  "checkbox

  CLEAR lwa_fieldcat.

  lwa_fieldcat-fieldname = 'CHECKBOX'.

  lwa_fieldcat-seltext_l = 'Checkbox'.

  lwa_fieldcat-checkbox = 'X'.

  lwa_fieldcat-fix_column = 'X'.

  APPEND lwa_fieldcat TO pt_fieldcat.

 

  "icon

  CLEAR lwa_fieldcat.

  lwa_fieldcat-fieldname = 'ICON'.

  lwa_fieldcat-seltext_l = 'Icon'.

  lwa_fieldcat-icon = 'X'.

  APPEND lwa_fieldcat TO pt_fieldcat.

 

  "symbol

  CLEAR lwa_fieldcat.

  lwa_fieldcat-fieldname = 'SYMBOL'.

  lwa_fieldcat-seltext_l = 'Symbol'.

  lwa_fieldcat-symbol = 'X'.

  APPEND lwa_fieldcat TO pt_fieldcat.

 

ENDFORM.                    "set_catalog

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17204926/viewspace-608226/,如需转载,请注明出处,否则将追究法律责任。

下一篇: ABAP面试题目
请登录后发表评论 登录
全部评论

注册时间:2009-01-01

  • 博文量
    59
  • 访问量
    311498