首页 > 其他分享 >ALV2

ALV2

时间:2022-12-08 23:01:59浏览次数:40  
标签:ALV2 fieldcat lt ls commentary TYPE event

*&---------------------------------------------------------------------*
*& Report  Z14
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT z14.

TYPE-POOLS:slis.

"1.声明变量
DATA:lt_fieldcat TYPE   slis_t_fieldcat_alv,
     ls_fieldcat TYPE   slis_fieldcat_alv,
     ls_layout   TYPE   slis_layout_alv.

DATA    lt_event    TYPE slis_t_event. "定义事件内表
DATA     ls_event    TYPE slis_alv_event. "定义事件工作区
"2.定义内表
TYPES:BEGIN OF ty_alvshow,

    bukrs TYPE bkpf-bukrs,"公司代码
    belnr TYPE bkpf-belnr,"会计凭证编号
    gjahr TYPE bkpf-gjahr,"会计年度
    blart TYPE bkpf-blart,"凭证类型
    bktxt TYPE bkpf-bktxt,"凭证抬头文本
  END OF ty_alvshow.

DATA: lt_ty_alvshow TYPE TABLE OF ty_alvshow,
      ls_ty_alvshow TYPE ty_alvshow.

"3-读取数据
SELECT
    a~bukrs
    a~belnr
    a~gjahr
    a~blart
    a~bktxt
FROM bkpf AS a INTO TABLE lt_ty_alvshow .


ls_layout-zebra = 'X'.
ls_layout-detail_popup = 'X'.
ls_layout-f2code = '&ETA'.
ls_layout-colwidth_optimize = 'X'.
ls_layout-detail_titlebar = '详细信息'.

DATA index TYPE int2.
index = 1.
ls_fieldcat-col_pos = index.
ls_fieldcat-fieldname = 'bukrs'.
ls_fieldcat-key = 'X'.
ls_fieldcat-datatype = 'char'.
ls_fieldcat-outputlen = '4'.
ls_fieldcat-seltext_m = '公司代码'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.

index = index + 1.
ls_fieldcat-col_pos = index.
ls_fieldcat-fieldname = 'belnr'.
ls_fieldcat-key = 'X'.
ls_fieldcat-datatype = 'char'.
ls_fieldcat-outputlen = '10'.
ls_fieldcat-seltext_m = '会计凭证编号'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.

index = index + 1.
ls_fieldcat-col_pos = index.
ls_fieldcat-fieldname = 'gjahr'.
ls_fieldcat-datatype = 'NUMC'.
ls_fieldcat-outputlen = '4'.
ls_fieldcat-seltext_m = '会计年度'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.

index = index + 1.
ls_fieldcat-col_pos = index.
ls_fieldcat-fieldname = 'blart'.
ls_fieldcat-datatype = 'CHAR'.
ls_fieldcat-outputlen = '2'.
ls_fieldcat-seltext_m = '凭证类型'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.

index = index + 1.
ls_fieldcat-col_pos = index.
ls_fieldcat-fieldname = 'bktxt'.
ls_fieldcat-datatype = 'CHAR'.
ls_fieldcat-outputlen = '25'.
ls_fieldcat-seltext_m = '凭证抬头文本'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.


"定义事件


************定义事件 REUSE_ALV_EVENTS_GET
ls_event-name = 'USER_COMMAND'."用户响应事件
ls_event-form = 'FORM_USER_COMMAND'."定义子例程最好和name值一样前面加FORM
APPEND ls_event TO lt_event.
CLEAR :ls_event.
ls_event-name = 'TOP_OF_PAGE'."显示标题
ls_event-form = 'FORM_TOP_OF_PAGE'.
APPEND ls_event TO lt_event.
CLEAR :ls_event.
ls_event-name = 'PF_STATUS_SET'."设置GUI状态栏
ls_event-form = 'FORM_PF_STATUS_SET'.
APPEND ls_event TO lt_event.
CLEAR :ls_event.


"显示ALV
DATA:pgm TYPE sy-repid.
pgm = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
  I_CALLBACK_PROGRAM                = pgm
*   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   = lt_event
*   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    = lt_ty_alvshow
 EXCEPTIONS
   PROGRAM_ERROR                     = 1
   OTHERS      = 2
  .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


*----------------------------------------------子例程程序-------------------------
**************form子例程定义****************
FORM form_user_command  USING r_ucomm     LIKE sy-ucomm
                                     rs_selfield TYPE slis_selfield.

  CASE r_ucomm  .
    WHEN  'ZADD'.
      MESSAGE '你点击了添加按钮' TYPE 'I'.
    WHEN 'DEL'.
      MESSAGE '你点击了删除按钮' TYPE 'I'.
  ENDCASE.
ENDFORM.

FORM form_top_of_page.
  DATA:lt_commentary TYPE slis_t_listheader,
       wt_commentary TYPE  slis_listheader.

  wt_commentary-typ = 'H'.
  wt_commentary-info = '销售凭证清单'.
  APPEND wt_commentary TO lt_commentary.
  wt_commentary-typ = 'S'.
  wt_commentary-info = '销售凭证清单'.
  APPEND wt_commentary TO lt_commentary.
  wt_commentary-typ = 'A'.
  wt_commentary-info = '销售凭证清单'.
  APPEND wt_commentary TO lt_commentary.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = lt_commentary
*     i_logo             = 'ZXY'           "图片tcodeOAER
*     I_END_OF_LIST_GRID =
*     I_ALV_FORM         =
    .


ENDFORM.

FORM form_pf_status_set USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'Z142'.
ENDFORM.

 

标签:ALV2,fieldcat,lt,ls,commentary,TYPE,event
From: https://www.cnblogs.com/hua900822/p/16967669.html

相关文章