ABAP ALV显示例子

 

 

REPORT  ZTEST_QY.

*ALV用到的类库
TYPE-POOLS:slis.

DATA: wa_alv_filed TYPE slis_fieldcat_alv, "列描述
      wa_alv_filedcat TYPE slis_t_fieldcat_alv."列描述内表,列清单

*定义工作区
DATA: wa type spfli,

*定义内表
itab_wa LIKE TABLE OF wa WITH HEADER LINE.

data: begin of wa_spfli ,
      carrid type spfli-carrid,
      connid type spfli-connid,
      cityfrom type spfli-cityfrom,
      airpfrom type spfli-airpfrom,
      cityto type spfli-cityto,
      airpto type spfli-airpto,
      end of wa_spfli,
      it_spfli like table of wa_spfli with header line.

data: g_qiqi like sy-datum,
      g_zhiqi like sy-datum.
SELECT-OPTIONS: gs_qiqi FOR g_qiqi,
                gs_zhiqi FOR g_zhiqi.

*查询数据放到工作区,工作区处理后放到内表
SELECT carrid connid cityfrom airpfrom cityto airpto
FROM spfli INTO table it_spfli up to 5 rows .

*定义列信息
wa_alv_filed-col_pos = 1.
wa_alv_filed-fieldname = 'CARRID'.  " 对应的内表中的字段名称
wa_alv_filed-seltext_m = '航线承运人ID'. "ALV中显示的标题
"wa_alv_filed-outputlen = 20. " 列的显示宽度,可以不设置
APPEND wa_alv_filed TO wa_alv_filedcat.

wa_alv_filed-col_pos = 2.
wa_alv_filed-fieldname = 'CONNID'.
wa_alv_filed-seltext_m = '航班连接Id'.
APPEND wa_alv_filed TO wa_alv_filedcat.

WA_ALV_FILED-COL_POS = 3.
WA_ALV_FILED-FIELDNAME = 'CITYFROM'.
WA_ALV_FILED-SELTEXT_M = '起飞城市'.
APPEND WA_ALV_FILED TO WA_ALV_FILEDCAT.

WA_ALV_FILED-COL_POS = 4.
WA_ALV_FILED-FIELDNAME = 'AIRPFROM'.
WA_ALV_FILED-SELTEXT_M = '起飞机场'.
APPEND WA_ALV_FILED TO WA_ALV_FILEDCAT.

WA_ALV_FILED-COL_POS = 5.
WA_ALV_FILED-FIELDNAME = 'CITYTO'.
WA_ALV_FILED-SELTEXT_M = '目标城市'.
APPEND WA_ALV_FILED TO WA_ALV_FILEDCAT.

WA_ALV_FILED-COL_POS = 6.
WA_ALV_FILED-FIELDNAME = 'AIRPTO'.
WA_ALV_FILED-SELTEXT_M = '目的机场'.
APPEND WA_ALV_FILED TO WA_ALV_FILEDCAT.

*调用ALV显示表单数据
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    it_fieldcat = wa_alv_filedcat
  TABLES
    t_outtab    = it_spfli.

你可能感兴趣的:(职场,abap,休闲,alv)