首页 > 其他分享 >ALV-带更新

ALV-带更新

时间:2022-12-09 20:12:03浏览次数:35  
标签:bkpf fieldcat 更新 lt ls ALV 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 = '会计年度'.
ls_fieldcat-do_sum = 'X'.
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 = '凭证抬头文本'.
ls_fieldcat-edit = 'X'.
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.


"排序设置
DATA it_sort TYPE slis_sortinfo_alv OCCURS 0.
DATA ls_sort TYPE slis_sortinfo_alv.
ls_sort-fieldname = 'belnr'.
ls_sort-down = 'X'.
APPEND ls_sort TO it_sort.

DATA ls_setting TYPE lvc_s_glay.
ls_setting-edt_cll_cb = 'X'.


"显示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    = ls_setting
    is_layout          = ls_layout
    it_fieldcat        = lt_fieldcat
*   IT_EXCLUDING       =
*   IT_SPECIAL_GROUPS  =
    it_sort            = 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 'ZSAVE'.
      data t_bkpf type TABLE OF bkpf.
      data e_bkpf type bkpf.


      SELECT * FROM bkpf  INTO TABLE t_bkpf
        FOR ALL ENTRIES IN lt_ty_alvshow
        where BELNR = lt_ty_alvshow-belnr.

      LOOP at t_bkpf INTO e_bkpf.
        READ TABLE lt_ty_alvshow INTO ls_ty_alvshow WITH KEY belnr = e_bkpf-belnr.

        IF sy-subrc = 0.
            data xid type char50.
            xid = ls_ty_alvshow-bktxt.

              e_bkpf-bktxt = ls_ty_alvshow-bktxt.
              MODIFY t_bkpf FROM e_bkpf.
            MESSAGE xid  type 'I'.
        ENDIF.
      ENDLOOP.

      UPDATE bkpf FROM TABLE t_bkpf.
      IF sy-subrc = 0.
          commit WORK.
          MESSAGE '更新成功'  type 'I'.
       ELSE.
          ROLLBACK work.
      ENDIF.



    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.

 

标签:bkpf,fieldcat,更新,lt,ls,ALV,TYPE,event
From: https://www.cnblogs.com/hua900822/p/16969890.html

相关文章