ABAP ALV详细教程(一)

一曲冷凌霜 提交于 2019-12-17 17:14:27

ABAP ALV详细教程(一)


第一步:第一步申明变量

TYPE-POOLS:slis.
       DATA : lt_fieldcat TYPE slis_t_fieldcat_alv,
              wt_fieldcat TYPE slis_fieldcat_alv,
              ls_layout TYPE slis_layout_alv.
              

第二步:定义内表

TYPES:BEGIN OF lt_xs,
  vbeln TYPE vbak-vbeln,
  matnr TYPE vbap-matnr,
  END OF lt_xs.
  DATA :gw_xs TYPE lt_xs,
        gt_xs TYPE TABLE OF lt_xs.

第三步:读取数据

SELECT vbak~vbeln matnr FROM vbak
      LEFT JOIN vbap
      on vbak~vbeln = vbap~vbeln
      INTO TABLE gt_xs.
      

第四步:ALV格式控制

  ls_layout-zebra = 'X'.
  ls_layout-detail_popup = 'X'.
  ls_layout-detail_titlebar = '详细信息'.
  ls_layout-f2code = '&ETA'.
  ls_layout-colwidth_optimize = 'X'.
   
  wt_fieldcat-fieldname = 'VBELN'.
  wt_fieldcat-col_pos  = '1'.
  wt_fieldcat-key = 'X'.
  wt_fieldcat-datatype = 'CHAR'.
  wt_fieldcat-outputlen = '10'.
  wt_fieldcat-seltext_m = '销售凭证'.
  APPEND wt_fieldcat TO lt_fieldcat.

  wt_fieldcat-fieldname = 'MATNR'.
  wt_fieldcat-col_pos  = '2'.
  wt_fieldcat-key = 'X'.
  wt_fieldcat-datatype = 'CHAR'.
  wt_fieldcat-outputlen = '18'.
  wt_fieldcat-seltext_m = '物料号'.
  APPEND wt_fieldcat TO lt_fieldcat.

第五步:ALV数据
显示

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
*     I_INTERFACE_CHECK                 = ' '
*     I_BYPASSING_BUFFER                = ' '
*     I_BUFFER_ACTIVE                   = ' '
*     I_CALLBACK_PROGRAM                = ' '
*     I_CALLBACK_PF_STATUS_SET          = ' '
*     I_CALLBACK_USER_COMMAND           = ' '
*     I_CALLBACK_TOP_OF_PAGE            = ' '
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*     I_CALLBACK_HTML_END_OF_LIST       = ' '
*     I_STRUCTURE_NAME                  =
*     I_BACKGROUND_ID                   = ' '
*     I_GRID_TITLE                      =
*     I_GRID_SETTINGS                   =
     IS_LAYOUT                         = ls_layout
     IT_FIELDCAT                       = lt_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                          = gt_xs
   EXCEPTIONS
     PROGRAM_ERROR                     = 1
     OTHERS                            = 2
            .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!