可编辑保存ALV

*---------------------------------------------------------------------*
* PROGRAM ID          : ZMB2112                                       *
* AUTHOR              : loeley                                        *
* TRANSACTION         : N/A                                           *
* PROGRAM TYPE        : Reporting                                     *
* INPUT FILES         : N/A                                           *
* OUTPUT FILES        : N/A                                           *
* SAP RELEASE         : 6.0                                           *
* DESCRIPTION         : 设定库位最大库存                               *
* AMENDMENTS                                                          *
*=====================================================================*


REPORT  ZMB2112.


TYPE-POOLS:slis.

TABLES sscrfields.

**************ALV显示定义******************************************
*ALV定义
DATA: gv_title TYPE lvc_title.    "标题
DATA: gs_layout TYPE  slis_layout_alv,"布局
      gt_fields  TYPE  slis_t_fieldcat_alv,"列名表
      gs_fields  TYPE  LINE  OF  slis_t_fieldcat_alv."列名表表头

TABLES:ZMB21KUWEI,M_KOSTN,T157H,T001L.

*******************************************************************
*变量
*******************************************************************

DATA: gt_mm03   LIKE TABLE OF ZMB21KUWEI WITH HEADER LINE.
DATA: gt_sfold  LIKE TABLE OF ZMB21KUWEI WITH HEADER LINE.
DATA: gt_sf     LIKE TABLE OF ZMB21KUWEI WITH HEADER LINE.

*******************************************************************
* INITIALIZATION
************* 获得当前日期-7天字符串 ****************************************
INITIALIZATION.
************* 选择屏幕定义 ****************************************
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.  "选择屏幕块
SELECT-OPTIONS:sWERKS FOR  T001L-WERKS obligatory.
SELECT-OPTIONS:sLGORT for T001L-LGORT.
SELECTION-SCREEN END OF BLOCK block1 .

AT SELECTION-SCREEN .

START-OF-SELECTION.
PERFORM getdata.

END-OF-SELECTION.

PERFORM  alvdata.

*&---------------------------------------------------------------------*
*&      Form  getdata
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM getdata.
  CLEAR gt_mm03.
  REFRESH gt_mm03.

 SELECT
        T001L~WERKS
        T001L~LGORT as KUWEI
        T001L~LGOBE
        ZMB21KUWEI~MAXNUM
        ZMB21KUWEI~EDMAN
        ZMB21KUWEI~EDDAT
    INTO CORRESPONDING FIELDS OF TABLE gt_mm03
    FROM  T001L left join ZMB21KUWEI on ZMB21KUWEI~WERKS = T001L~WERKS and ZMB21KUWEI~KUWEI = T001L~LGORT
   WHERE T001L~WERKS in sWERKS AND LGORT in sLGORT .

 move  gt_mm03[] to gt_sfold[].
ENDFORM.                    "getdata

*&---------------------------------------------------------------------*
*&      Form  alvdata
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alvdata.
" gv_title  = '领料单'.
  gs_layout-colwidth_optimize  =  'X'.
  "gs_layout-box_fieldname  =  'CHE'.      "确定选择列
  gs_layout-zebra  =  'X'.                 "各行显示不同的颜色
  REFRESH  gt_fields.
  CLEAR    gs_fields.

  gs_fields-fieldname  =  'WERKS'.
  gs_fields-seltext_l  =  '工厂'.
  gs_fields-outputlen = 40.
  APPEND  gs_fields  TO  gt_fields.
  CLEAR  gs_fields.

  gs_fields-fieldname  =  'KUWEI'.
  gs_fields-seltext_l  =  '库位'.
  gs_fields-outputlen = 40.
  APPEND  gs_fields  TO  gt_fields.
  CLEAR  gs_fields.

  gs_fields-fieldname  =  'LGOBE'.
  gs_fields-seltext_l  =  '库位描述'.
  gs_fields-outputlen = 60.
  APPEND  gs_fields  TO  gt_fields.
  CLEAR  gs_fields.

  gs_fields-fieldname  =  'MAXNUM'.
  gs_fields-seltext_l  =  '最大库存'.
  gs_fields-edit = 'X'.
  gs_fields-outputlen = 20.
  "gs_fields-DECIMALS = 0.
  APPEND  gs_fields  TO  gt_fields.
  CLEAR  gs_fields.

  gs_fields-fieldname  =  'EDMAN'.
  gs_fields-seltext_l  =  '最后设定人'.
  gs_fields-outputlen = 20.
  "gs_fields-DECIMALS = 0.
  APPEND  gs_fields  TO  gt_fields.
  CLEAR  gs_fields.

  gs_fields-fieldname  =  'EDDAT'.
  gs_fields-seltext_l  =  '最后设定时间'.
  gs_fields-outputlen = 20.
  "gs_fields-DECIMALS = 0.
  APPEND  gs_fields  TO  gt_fields.
  CLEAR  gs_fields.


    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       i_callback_program       = sy-repid
       i_callback_pf_status_set = 'SET_PF'
       i_callback_user_command  = 'USER_COM'
  "     it_events                = i_events
       i_grid_title             = gv_title
       is_layout                = gs_layout
       it_fieldcat              = gt_fields
       i_save                   = 'X'
     TABLES
       t_outtab                 = gt_mm03[]
     EXCEPTIONS
       program_error            = 1
       OTHERS                   = 2.


ENDFORM.                    "alvdata

*----------------------------------------------------------------------*
FORM  set_pf  USING    extab  TYPE  slis_t_extab.
  SET  PF-STATUS  'ZALV2112'.
ENDFORM.

FORM  user_com  USING  r_ucomm  LIKE  sy-ucomm
      rs_selfield  TYPE  slis_selfield  .
*  修改Alv表的数据,并在内表中显示修改的内容
  DATA: lr_grid TYPE REF TO cl_gui_alv_grid,
        myindex TYPE sy-tabix.
*  刷新屏幕
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = lr_grid.
  CALL METHOD lr_grid->check_changed_data.
  rs_selfield-refresh = 'X'.

*  CLEAR:gw_sd01.
*
*  READ TABLE gt_sd01 INTO gw_sd01 INDEX rs_selfield-tabindex.

  CASE  r_ucomm.
    WHEN:  'BACK'  OR  'EXIT'  OR  'CANCEL'.
      LEAVE  TO  SCREEN  0.
    WHEN 'BAOCUN'.
    perform  savedata.

  ENDCASE.
  rs_selfield-refresh = 'X'.
  CLEAR r_ucomm.

ENDFORM.
                "savedata

FORM savedata.

  LOOP AT gt_mm03.
    loop at gt_sfold where WERKS = gt_mm03-WERKS and KUWEI = gt_mm03-KUWEI.
      if gt_sfold-MAXNUM <> gt_mm03-MAXNUM.
          gt_mm03-EDMAN = SY-UNAME.
          gt_mm03-EDDAT = SY-DATUM.
          modify gt_mm03.
      endif.
    endloop.
  ENDLOOP.

  MODIFY ZMB21KUWEI FROM TABLE gt_mm03.
  if sy-subrc = 0.
     message '保存成功' type 'S'.
  ELSE.
     message '保存失败' type 'E'.
  ENDIF.

ENDFORM.                    "savedata

你可能感兴趣的:(可编辑保存ALV)