基础ALV显示

*&---------------------------------------------------------------------*
*& Report Z_ALV_182701
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_ALV_182701.
TYPE-POOLS:SLIS.
 
TYPES:
  BEGIN OF TYP_DATA,
    CARRID TYPE SFLIGHT-CARRID,
    CONNID TYPE SFLIGHT-CONNID,
    FLDATE TYPE SFLIGHT-FLDATE,
    PRICE  TYPE SFLIGHT-PRICE,
  END OF TYP_DATA.
 
DATA:ST_SFLIGHT TYPE SFLIGHT.
DATA:TD_SFLIGHT TYPE TABLE OF TYP_DATA.

DATA: ST_FIELDCAT TYPE SLIS_FIELDCAT_ALV,    "列表字段 (綁定FIELD)
      TD_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
      ST_LAYOUT   TYPE SLIS_LAYOUT_ALV.
 
PARAMETERS: P_CARRID TYPE SFLIGHT-CARRID.
SELECT-OPTIONS:S_CONNID FOR ST_SFLIGHT-CONNID.
SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-001.
  PARAMETERS:PRICE TYPE SFLIGHT-PRICE.
SELECTION-SCREEN END OF BLOCK BL1.
 
START-OF-SELECTION.
  PERFORM FRM_FIELD_SET.
  PERFORM FRM_LAYOUT.
  PERFORM FRM_GET_DATA.
  PERFORM FRM_ALV_DISPLAY.

FORM FRM_FIELD_SET.  "设置标题栏字段
  "定義四FIELDCAT信息
     ST_FIELDCAT-COL_POS = 1.         "ALV列索引
     ST_FIELDCAT-FIELDNAME = 'CARRID'."ALV绑定字段
     ST_FIELDCAT-SELTEXT_M = '航班承運人'.  "ALV表头显示的文字
     APPEND ST_FIELDCAT TO TD_FIELDCAT. "內表賦值
 
     ST_FIELDCAT-COL_POS = 2.
     ST_FIELDCAT-FIELDNAME = 'CONNID'.
     ST_FIELDCAT-SELTEXT_M = '航班數量'.
     APPEND ST_FIELDCAT TO TD_FIELDCAT.
 
     ST_FIELDCAT-COL_POS = 3.
     ST_FIELDCAT-FIELDNAME = 'FLDATE'.
     ST_FIELDCAT-SELTEXT_M = '航行时间'.
     APPEND ST_FIELDCAT TO TD_FIELDCAT.
 
     ST_FIELDCAT-COL_POS = 4.
     ST_FIELDCAT-FIELDNAME = 'PRICE'.
     ST_FIELDCAT-SELTEXT_M = '航班价格'.
     APPEND ST_FIELDCAT TO TD_FIELDCAT.
ENDFORM.
 
FORM FRM_GET_DATA.  "获取数据
  SELECT CARRID
         CONNID
         FLDATE
         PRICE
    FROM SFLIGHT
    INTO TABLE TD_SFLIGHT
   WHERE SFLIGHT~CARRID = P_CARRID
     AND SFLIGHT~CONNID IN S_CONNID.
ENDFORM.
 
FORM FRM_LAYOUT."设置ALV样式
  ST_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
  ST_LAYOUT-ZEBRA = 'X'.                     "隔行的颜色相同
 " ST_LAYOUT-EDIT = 'X'. "可以修改所有ALV列的数据,左边也会出来选择行的按钮,
  ST_LAYOUT-INFO_FIELDNAME = 'ROW_COLOR'.    "OUTTAB中保存颜色代码的字段名
  ST_LAYOUT-F2CODE = '&ETA'.                 "双击触发的FUNCTION CODE
ENDFORM.
 
FORM FRM_TOP_OF_PAGE.  "设置ALV表头
  DATA:
        LTH_LISTHEADER TYPE SLIS_LISTHEADER,
        LTD_LISTHEADER TYPE SLIS_T_LISTHEADER.
  CLEAR: LTH_LISTHEADER, LTD_LISTHEADER.
 
  LTH_LISTHEADER-TYP = 'H'.
  LTH_LISTHEADER-INFO = 'TEST_ALV'.
  APPEND LTH_LISTHEADER TO LTD_LISTHEADER.
 
  CLEAR LTH_LISTHEADER.
  LTH_LISTHEADER-TYP = 'S'.
  LTH_LISTHEADER-KEY = '用户:'.
  LTH_LISTHEADER-INFO = SY-UNAME.
  APPEND LTH_LISTHEADER TO LTD_LISTHEADER.
 
  CLEAR LTH_LISTHEADER.
  LTH_LISTHEADER-TYP = 'S'.
  LTH_LISTHEADER-KEY = '日期:'.
  LTH_LISTHEADER-INFO = SY-DATUM.
  APPEND LTH_LISTHEADER TO LTD_LISTHEADER.
 
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
  EXPORTING
    IT_LIST_COMMENTARY       = LTD_LISTHEADER
    I_LOGO                   = 'ENJOYSAP_LOGO'. "ENJOYSAP_LOGO
ENDFORM.
 
FORM FRM_SET_STATUS USING I_EXTAB TYPE SLIS_T_EXTAB.
  SET PF-STATUS '1000' EXCLUDING I_EXTAB.
  "SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'. "标准状态栏
ENDFORM.
 
FORM FRM_USER_COMMAND USING I_UCOMM    TYPE SY-UCOMM  "工具栏的处理
                            I_SELFIELD TYPE SLIS_SELFIELD.
  CASE I_UCOMM.
  WHEN 'DEL'.
*   選択行削除
    LEAVE TO SCREEN 0.
  WHEN '&F03'.
*   前画面処理
    LEAVE TO SCREEN 0.
  WHEN 'BACK'.
*   前画面処理
    LEAVE TO SCREEN 0.
  WHEN 'CANCEL'.
*   前画面処理
    LEAVE TO SCREEN 0.
  WHEN OTHERS.
  ENDCASE.
ENDFORM.
 
FORM FRM_ALV_DISPLAY.   "ALV显示
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
*     I_INTERFACE_CHECK                 = ' '
*     I_BYPASSING_BUFFER                = ' '
*     I_BUFFER_ACTIVE                   = ' '
      I_CALLBACK_PROGRAM                = SY-REPID
      I_CALLBACK_PF_STATUS_SET          = 'FRM_SET_STATUS'
*     I_CALLBACK_USER_COMMAND           = ' '
      I_CALLBACK_TOP_OF_PAGE            = 'FRM_TOP_OF_PAGE'
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*     I_CALLBACK_HTML_END_OF_LIST       = ' '
"      I_STRUCTURE_NAME                  = 'SPFLI'
*     I_BACKGROUND_ID                   = ' '
*     I_GRID_TITLE                      =
*     I_GRID_SETTINGS                   =
      IS_LAYOUT                         = ST_LAYOUT
      IT_FIELDCAT                       = TD_FIELDCAT
*     IT_EXCLUDING                      =
*     IT_SPECIAL_GROUPS                 =
*     IT_SORT                           =
*     IT_FILTER                         =
*     IS_SEL_HIDE                       =
*     I_DEFAULT                         = 'X'
*     I_SAVE                            = ' '
*     IS_VARIANT                        =
*     IT_EVENTS                         =
*     IT_EVENT_EXIT                     =
*     IS_PRINT                          =
*     IS_REPREP_ID                      =
*     I_SCREEN_START_COLUMN             = 0
*     I_SCREEN_START_LINE               = 0
*     I_SCREEN_END_COLUMN               = 0
*     I_SCREEN_END_LINE                 = 0
*     I_HTML_HEIGHT_TOP                 = 0
*     I_HTML_HEIGHT_END                 = 0
*     IT_ALV_GRAPHICS                   =
*     IT_HYPERLINK                      =
*     IT_ADD_FIELDCAT                   =
*     IT_EXCEPT_QINFO                   =
*     IR_SALV_FULLSCREEN_ADAPTER        =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER           =
*     ES_EXIT_CAUSED_BY_USER            =
    TABLES
      T_OUTTAB                          = TD_SFLIGHT
    EXCEPTIONS
      PROGRAM_ERROR                     = 1
      OTHERS                            = 2
            .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
ENDFORM.

posted on 2018-08-28 15:11  阳光旅人  阅读(220)  评论(0编辑  收藏  举报

导航