ABAP ALV可编辑更新

  • Post author:
  • Post category:其他




ALV 编辑更新

一:设置可编辑

LW_FIELDCAT-EDIT = 'X'. "EDIT


二:获取内表对象

  DATA: LR_GRID TYPE REF TO CL_GUI_ALV_GRID.  "DEFINE OBJECT
                                              "TYPE REF TO用来定义一个数据对象,这个数据对象是用来指向另外的数据的;
                                              "DATA: R1 TYPE REF TO C1.
                                              "属于ABAP面向对象编程,C1是一个类,R1定义了这个类的对象

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' "GET ALV GUI OBJECT
      IMPORTING
        E_GRID = LR_GRID.

  CALL METHOD LR_GRID->CHECK_CHANGED_DATA. "检查内表变化,然后把改之前的内表先复制一个,然后2个内表,改之前的,跟改之后的

  SELFIELD-REFRESH = 'X'. "自动刷新,需要写在最后面,不然不会更新到内表

三:更新

  MODIFY ZTBC_QUOTH_09 FROM TABLE GT_ITAB_UPDATE. "UPDATE DBTABLE DATA

实例:

在这里插入图片描述

在这里插入图片描述

*&---------------------------------------------------------------------*
*& REPORT Z_09_ALV02
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_09_ALV02.

****************数据库插入数据*********************
**定义工作区
*DATA LW_ITAB TYPE ZTBC_QUOTH_09.
*DATA LW_ITAB2 TYPE ZTBC_QUOTI_09.
*
**定义表
*DATA LT_ITAB LIKE TABLE OF LW_ITAB.
*DATA LT_ITAB2 LIKE TABLE OF LW_ITAB2.
*
**清空数据库表
*DELETE FROM ZTBC_QUOTH_09.
*DELETE FROM ZTBC_QUOTI_09.
*
**循环往内表添加数据
*DO 100 TIMES.
*  LW_ITAB-OBJECT_ID = SY-INDEX.
*  LW_ITAB-PROCESS_TYPE = '1234'.
*  LW_ITAB-CREATE_AT = '20210414'.
*  LW_ITAB-CREATE_BY = SY-UNAME.
*  LW_ITAB-DESCRIPTION = 'TEST' && SY-INDEX.
*
*  LW_ITAB2-ITEM_ID = SY-INDEX.
*  LW_ITAB2-OBJECT_ID = LW_ITAB-OBJECT_ID.
*  LW_ITAB2-PRODUCT_ID = SY-INDEX.
*  LW_ITAB2-QUANTITY = SY-INDEX.
*  LW_ITAB2-UNIT = 'KG'.
*
*  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' "去前导零
*  EXPORTING
*    input  = LW_ITAB-OBJECT_ID
*  IMPORTING
*    output = LW_ITAB-OBJECT_ID.
*
*  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' "去前导零
*  EXPORTING
*    input  = LW_ITAB2-OBJECT_ID
*  IMPORTING
*    output = LW_ITAB2-OBJECT_ID.
*
*  INSERT LW_ITAB INTO TABLE LT_ITAB.
*
*  INSERT LW_ITAB2 INTO TABLE LT_ITAB2.
*ENDDO.
*
*
**内表数据存入数据库
*INSERT ZTBC_QUOTH_09 FROM TABLE LT_ITAB.
*IF SY-SUBRC = 0.
*  WRITE: / 'YES1'.
*ENDIF.
**内表数据存入数据库
*INSERT ZTBC_QUOTI_09 FROM TABLE LT_ITAB2.
*IF SY-SUBRC = 0.
*  WRITE: / 'YES2'.
*ENDIF.

**************************************************ALV SHOW DATA*************************************************************

**REFERENCE TYPE POOL
*TYPE-POOLS:SLIS.
*
**DEFINE THE ITERNAL TABLE REQUIRED BY ALV
*DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, "THE WHOLE OF THE TABLE FIELD..FIELDCAT'S INTERNAL TABLE
*      GW_FIELDCAT TYPE SLIS_FIELDCAT_ALV, "THE CONTENT OF A FIELD..FIELDCAT'S WORK AREA
*      GS_LAYOUT   TYPE SLIS_LAYOUT_ALV, "ALV LAYOUT
*      GT_EVENT    TYPE SLIS_T_EVENT, "EVENT INTERNAL TABLE
*      GW_EVENT    TYPE SLIS_ALV_EVENT. "EVENT WORK AREA
*
**DEFINE INTERNAL TABLE
*TYPES: BEGIN OF TY_ITAB, "DEFINE STRUCTURE TYPE
*         OBJECT_ID    LIKE ZTBC_QUOTH_09-OBJECT_ID,
*         PROCESS_TYPE LIKE ZTBC_QUOTH_09-PROCESS_TYPE,
*         CREATE_AT    LIKE ZTBC_QUOTH_09-CREATE_AT,
*         CREATE_BY    LIKE ZTBC_QUOTH_09-CREATE_BY,
*         DESCRIPTION  LIKE ZTBC_QUOTH_09-DESCRIPTION,
*         ITEM_ID      LIKE ZTBC_QUOTI_09-ITEM_ID,
*         PRODUCT_ID   LIKE ZTBC_QUOTI_09-PRODUCT_ID,
*         QUANTITY     LIKE ZTBC_QUOTI_09-QUANTITY,
*         UNIT         LIKE ZTBC_QUOTI_09-UNIT,
*       END OF TY_ITAB.
*DATA GW_ITAB TYPE TY_ITAB. "WORK AREA
*DATA GT_ITAB LIKE TABLE OF GW_ITAB. "INTERNAL TABLE
*
*
**SELECT DATA
*SELECT
*  A~OBJECT_ID
*  A~PROCESS_TYPE
*  A~CREATE_AT
*  A~CREATE_BY
*  A~DESCRIPTION
*  B~ITEM_ID
*  B~PRODUCT_ID
*  B~QUANTITY
*  B~UNIT
*  FROM ZTBC_QUOTH_09 AS A
*  CROSS JOIN ZTBC_QUOTI_09 AS B
*  INTO CORRESPONDING FIELDS OF TABLE GT_ITAB.
*
*
**ALV FORMAT CONTROL
*GS_LAYOUT-ZEBRA = 'X'. "ZEBRA STRIPE
*GS_LAYOUT-DETAIL_POPUP = 'X'. "WHTAT IS IT ?
*GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "AUTOMATICALLY OPTIMIZE COLUMN WIDTH
*
*GW_FIELDCAT-FIELDNAME = 'OBJECT_ID'. "THE FIELD NAME OF THE INNER TABLE TO OUTPUT
*GW_FIELDCAT-COL_POS  = '1'. "SPECIFY THE NUMBER OF COLUMNS
**GW_FIELDCAT-KEY = 'X'. "WHAT IS IT ?
*GW_FIELDCAT-DATATYPE = 'CHAR'. "
*GW_FIELDCAT-OUTPUTLEN = '10'. "OUTPUT LENGTH
*GW_FIELDCAT-SELTEXT_M = 'OBJECT_ID'. "FIELD DESCRIPTION
*APPEND GW_FIELDCAT TO GT_FIELDCAT.
*
*GW_FIELDCAT-FIELDNAME = 'PROCESS_TYPE'.
*GW_FIELDCAT-COL_POS  = '2'.
*GW_FIELDCAT-DATATYPE = 'CHAR'.
*GW_FIELDCAT-OUTPUTLEN = '4'.
*GW_FIELDCAT-SELTEXT_M = 'PROCESS_TYPE'.
*APPEND GW_FIELDCAT TO GT_FIELDCAT.
*
*GW_FIELDCAT-FIELDNAME = 'CREATE_AT'.
*GW_FIELDCAT-COL_POS  = '3'.
*GW_FIELDCAT-DATATYPE = 'DATS'.
*GW_FIELDCAT-OUTPUTLEN = '8'.
*GW_FIELDCAT-SELTEXT_M = 'CREATE_AT'.
*APPEND GW_FIELDCAT TO GT_FIELDCAT.
*
*GW_FIELDCAT-FIELDNAME = 'CEATE_BY'.
*GW_FIELDCAT-COL_POS  = '4'.
*GW_FIELDCAT-DATATYPE = 'CHAR'.
*GW_FIELDCAT-OUTPUTLEN = '10'.
*GW_FIELDCAT-SELTEXT_M = 'CREATE_BY'.
*APPEND GW_FIELDCAT TO GT_FIELDCAT.
*
*GW_FIELDCAT-FIELDNAME = 'DESCRIPTION'.
*GW_FIELDCAT-COL_POS  = '5'.
*GW_FIELDCAT-DATATYPE = 'CHAR'.
*GW_FIELDCAT-OUTPUTLEN = '40'.
*GW_FIELDCAT-SELTEXT_M = '描述'.
*APPEND GW_FIELDCAT TO GT_FIELDCAT.
*
*GW_FIELDCAT-FIELDNAME = 'ITEM_ID'.
*GW_FIELDCAT-COL_POS  = '6'.
*GW_FIELDCAT-DATATYPE = 'CHAR'.
*GW_FIELDCAT-OUTPUTLEN = '10'.
*GW_FIELDCAT-SELTEXT_M = 'ITEM_ID'.
*APPEND GW_FIELDCAT TO GT_FIELDCAT.
*
*GW_FIELDCAT-FIELDNAME = 'PRODUCT_ID'.
*GW_FIELDCAT-COL_POS  = '7'.
*GW_FIELDCAT-DATATYPE = 'CHAR'.
*GW_FIELDCAT-OUTPUTLEN = '4'.
*GW_FIELDCAT-SELTEXT_M = 'PRODUCT_ID'.
*APPEND GW_FIELDCAT TO GT_FIELDCAT.
*
*GW_FIELDCAT-FIELDNAME = 'QUANTITY'.
*GW_FIELDCAT-COL_POS  = '8'.
*GW_FIELDCAT-DATATYPE = 'QUAN'.
*GW_FIELDCAT-OUTPUTLEN = '10'.
*GW_FIELDCAT-SELTEXT_M = 'QUANTITY'.
*APPEND GW_FIELDCAT TO GT_FIELDCAT.
*
*GW_FIELDCAT-FIELDNAME = 'UNIT'.
*GW_FIELDCAT-COL_POS  = '9'.
*GW_FIELDCAT-DATATYPE = 'CHAR'.
*GW_FIELDCAT-OUTPUTLEN = '10'.
*GW_FIELDCAT-SELTEXT_M = 'UNIT'.
*APPEND GW_FIELDCAT TO GT_FIELDCAT.
*
**DEFINE EVENT
*GW_EVENT-NAME = 'TOP_OF_PAGE'."SHOW TITLE
*GW_EVENT-FORM = 'FORM_TOP_OF_PAGE'."DEFINE FORM..THIS GW_EVENT-FORM SHOULD HAVE THE SAVE NAME AS FORM
*APPEND GW_EVENT TO GT_EVENT.
*CLEAR :GW_EVENT.
*
**SHOW ALV
*CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
*  EXPORTING
*    I_CALLBACK_PROGRAM = SY-CPROG "CURRENT PROGRAM
*    IS_LAYOUT          = GS_LAYOUT
*    IT_FIELDCAT        = GT_FIELDCAT
*    IT_EVENTS          = GT_EVENT
*  TABLES
*    T_OUTTAB           = GT_ITAB
*  EXCEPTIONS
*    PROGRAM_ERROR      = 1
*    OTHERS             = 2.
*IF SY-SUBRC <> 0.
** IMPLEMENT SUITABLE ERROR HANDLING HERE
*ENDIF.
*
*
**FORM----TOP_OF_PAGE
*FORM FORM_TOP_OF_PAGE.
*  DATA:LT_COMMENTARY TYPE SLIS_T_LISTHEADER,
*       LW_COMMENTARY TYPE  SLIS_LISTHEADER.
*
*  LW_COMMENTARY-TYP = 'H'.
*  LW_COMMENTARY-INFO = 'TABLE'.
*  APPEND LW_COMMENTARY TO LT_COMMENTARY.
*  LW_COMMENTARY-TYP = 'S'.
*  LW_COMMENTARY-INFO = 'TABLE'.
*  APPEND LW_COMMENTARY TO LT_COMMENTARY.
*  LW_COMMENTARY-TYP = 'A'.
*  LW_COMMENTARY-INFO = 'TABLE'.
*  APPEND LW_COMMENTARY TO LT_COMMENTARY.
*  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
*    EXPORTING
*      IT_LIST_COMMENTARY = LT_COMMENTARY
*      I_LOGO             = 'ENJOYSAP_LOGO'.           "图片TCODEOAER
*ENDFORM.


*********************************************ENCAPSULATION FORM***********************************

*REFERENCE TYPE POOL
TYPE-POOLS:SLIS.

*DEFINE THE ITERNAL TABLE REQUIRED BY ALV
DATA: GT_FIELDCAT   TYPE SLIS_T_FIELDCAT_ALV, "THE WHOLE OF THE TABLE FIELD..FIELDCAT'S INTERNAL TABLE
      GW_FIELDCAT   TYPE SLIS_FIELDCAT_ALV, "THE CONTENT OF A FIELD..FIELDCAT'S WORK AREA
      GS_LAYOUT     TYPE SLIS_LAYOUT_ALV, "ALV LAYOUT
      GT_EVENT      TYPE SLIS_T_EVENT, "EVENT INTERNAL TABLE
      GW_EVENT      TYPE SLIS_ALV_EVENT, "EVENT WORK AREA
      GT_LISTHEADER TYPE SLIS_T_LISTHEADER "
      .

CONSTANTS: GC_CALLBACK_STATUS       TYPE SLIS_FORMNAME VALUE 'FORM_SET_STATUS',
           GC_CALLBACK_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'FORM_USER_COMMAND'.

*DEFINE INTERNAL TABLE
TYPES: BEGIN OF TY_ITAB, "DEFINE STRUCTURE TYPE
         OBJECT_ID    LIKE ZTBC_QUOTH_09-OBJECT_ID,
         PROCESS_TYPE LIKE ZTBC_QUOTH_09-PROCESS_TYPE,
         CREATE_AT    LIKE ZTBC_QUOTH_09-CREATE_AT,
         CREATE_BY    LIKE ZTBC_QUOTH_09-CREATE_BY,
         DESCRIPTION  LIKE ZTBC_QUOTH_09-DESCRIPTION,
         ITEM_ID      LIKE ZTBC_QUOTI_09-ITEM_ID,
         PRODUCT_ID   LIKE ZTBC_QUOTI_09-PRODUCT_ID,
         QUANTITY     LIKE ZTBC_QUOTI_09-QUANTITY,
         UNIT         LIKE ZTBC_QUOTI_09-UNIT,
         GV_SELECT TYPE C,
       END OF TY_ITAB.
DATA GW_ITAB TYPE TY_ITAB. "WORK AREA
DATA GT_ITAB LIKE TABLE OF GW_ITAB. "INTERNAL TABLE

DATA GW_ITAB_UPDATE TYPE ZTBC_QUOTH_09.
DATA GT_ITAB_UPDATE LIKE TABLE OF GW_ITAB_UPDATE. "UPDATE INTERNAL TABLE

*INITIALIZATION ALV FORMAT
INITIALIZATION.
  PERFORM LAYOUT_INIT USING GS_LAYOUT.
  PERFORM SET_ALV_HEADER USING GT_LISTHEADER[]. "SETTING ALV HEADER
  PERFORM EVENT_BUILD USING GT_EVENT[].

*GET DATA AND HANDLE DATA
START-OF-SELECTION.
  PERFORM GET_DATA TABLES GT_ITAB.
  PERFORM DISPLAY_ALV.

*SHOW DATA
END-OF-SELECTION.


*******************************FORM**************************************
*&---------------------------------------------------------------------*
*& FORM LAYOUT_INIT
*&---------------------------------------------------------------------*
*& ALV FORMAT CONTROL
*&---------------------------------------------------------------------*
*&      --> GS_LAYOUT
*&---------------------------------------------------------------------*
FORM LAYOUT_INIT  USING    P_GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
  P_GS_LAYOUT-ZEBRA = 'X'. "ZEBRA STRIPE
  P_GS_LAYOUT-DETAIL_POPUP = 'X'. "WHTAT IS IT ?
  P_GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "AUTOMATICALLY OPTIMIZE COLUMN WIDTH
  P_GS_LAYOUT-BOX_FIELDNAME = 'GV_SELECT'. "
ENDFORM.

*&---------------------------------------------------------------------*
*& FORM SET_ALV_HEADER
*&---------------------------------------------------------------------*
*& SET_ALVA_HEADER
*&---------------------------------------------------------------------*
*&      --> GT_LISTHEADER[]
*&---------------------------------------------------------------------*
FORM SET_ALV_HEADER  USING    P_GT_LISTHEADER TYPE SLIS_T_LISTHEADER.
  DATA:LW_LISTHEADER TYPE SLIS_LISTHEADER.

  LW_LISTHEADER-TYP = 'H'.
  LW_LISTHEADER-INFO = 'TABLE'.
  APPEND LW_LISTHEADER TO P_GT_LISTHEADER.
  LW_LISTHEADER-TYP = 'S'.
  LW_LISTHEADER-INFO = 'TABLE'.
  APPEND LW_LISTHEADER TO P_GT_LISTHEADER.
  LW_LISTHEADER-TYP = 'A'.
  LW_LISTHEADER-INFO = 'TABLE'.
  APPEND LW_LISTHEADER TO P_GT_LISTHEADER.
ENDFORM.

*&---------------------------------------------------------------------*
*& FORM EVENT_BUILD
*&---------------------------------------------------------------------*
*& *DEFINE EVENT
*&---------------------------------------------------------------------*
*&      --> GT_EVENT[]
*&---------------------------------------------------------------------*
FORM EVENT_BUILD  USING    P_GT_EVENT TYPE SLIS_T_EVENT.
  GW_EVENT-NAME = 'TOP_OF_PAGE'."SHOW TITLE
  GW_EVENT-FORM = 'FORM_TOP_OF_PAGE'."DEFINE FORM..THIS GW_EVENT-FORM SHOULD HAVE THE SAVE NAME AS FORM
  APPEND GW_EVENT TO P_GT_EVENT.
  CLEAR :GW_EVENT.
ENDFORM.

*AUTO EXCUTE. GENERATE ALV HEADER
FORM FORM_TOP_OF_PAGE.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      IT_LIST_COMMENTARY = GT_LISTHEADER
      I_LOGO             = 'ENJOYSAP_LOGO'.           "图片TCODEOAER
ENDFORM.

*&---------------------------------------------------------------------*
*& FORM GET_DATA
*&---------------------------------------------------------------------*
*& SELECT DATA
*&---------------------------------------------------------------------*
*&      --> GT_ITAB
*&---------------------------------------------------------------------*
FORM GET_DATA  TABLES   P_GT_ITAB.
  SELECT
  A~OBJECT_ID
  A~PROCESS_TYPE
  A~CREATE_AT
  A~CREATE_BY
  A~DESCRIPTION
  B~ITEM_ID
  B~PRODUCT_ID
  B~QUANTITY
  B~UNIT
  FROM ZTBC_QUOTH_09 AS A
  INNER JOIN ZTBC_QUOTI_09 AS B
  ON A~OBJECT_ID = B~OBJECT_ID
  INTO CORRESPONDING FIELDS OF TABLE P_GT_ITAB
  .
ENDFORM.

*&---------------------------------------------------------------------*
*& FORM DISPLAY_ALV
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM DISPLAY_ALV .
*SET FIELDCAT
  PERFORM SET_FIELDCAT USING 'OBJECT_ID'    '1'  'OBJECT_ID'    ''.
  PERFORM SET_FIELDCAT USING 'PROCESS_TYPE' '2'  'PROCESS_TYPE' ''.
  PERFORM SET_FIELDCAT USING 'CRATE_AT'     '3'  'CREATE_AT'    ''.
  PERFORM SET_FIELDCAT USING 'CREATE_BY'    '4'  'CREATE_BY'    'X'.
  PERFORM SET_FIELDCAT USING 'DESCRIPTION'  '5'  'DESCRIPTION'  ''.
  PERFORM SET_FIELDCAT USING 'ITEM_ID'      '6'  'ITEM_ID'      ''.
  PERFORM SET_FIELDCAT USING 'PRODUCT_ID'   '7'  'PRODUCT_ID'   ''.
  PERFORM SET_FIELDCAT USING 'QUANTITY'     '8'  'QUANTITY'     ''.
  PERFORM SET_FIELDCAT USING 'UNIT'         '9'  'UNIT'         ''.

*SHOW ALV
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-CPROG "CURRENT PROGRAM
      IS_LAYOUT                = GS_LAYOUT
      IT_FIELDCAT              = GT_FIELDCAT
      IT_EVENTS                = GT_EVENT
      I_CALLBACK_PF_STATUS_SET = GC_CALLBACK_STATUS "GUI STATUS
      I_CALLBACK_USER_COMMAND  = GC_CALLBACK_USER_COMMAND "USER COMMAND
    TABLES
      T_OUTTAB                 = GT_ITAB
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
  IF SY-SUBRC <> 0.
*IMPLEMENT SUITABLE ERROR HANDLING HERE
  ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*& FORM SET_FIELDCAT
*&---------------------------------------------------------------------*
*& SET_FIELDCAT
*&---------------------------------------------------------------------*
*&      --> P_
*&---------------------------------------------------------------------*
FORM SET_FIELDCAT  USING    FIELDNAME TYPE SLIS_FIELDCAT_ALV-FIELDNAME
                        COL_POS TYPE SLIS_FIELDCAT_ALV-COL_POS
                        SELTEXT_M TYPE SLIS_FIELDCAT_ALV-SELTEXT_M
                        EDIT TYPE SLIS_FIELDCAT_ALV-EDIT
                        .
  DATA LW_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
  CLEAR LW_FIELDCAT.

  LW_FIELDCAT-FIELDNAME = FIELDNAME. "THE FIELD NAME OF THE INNER TABLE TO OUTPUT
  LW_FIELDCAT-COL_POS  = COL_POS. "SPECIFY THE NUMBER OF COLUMNS
  LW_FIELDCAT-SELTEXT_M = SELTEXT_M. "FIELD DESCRIPTION
  LW_FIELDCAT-EDIT = EDIT. "EDIT
  APPEND LW_FIELDCAT TO GT_FIELDCAT.
ENDFORM.

*&---------------------------------------------------------------------*
*& FORM FORM_SET_STATUS
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*&      --> GS_EXTAB
*&      --> TYPE
*&      --> SLIS_T_EXTAB
*&---------------------------------------------------------------------*
FORM FORM_SET_STATUS USING I_IT_EXTAB TYPE SLIS_T_EXTAB. "FIXED PARAMETERS
  SET PF-STATUS 'ZDCH_09_ALV02_GUI'. "THIS VALUE SHOULD CORRESPONDING GUI STATUS BY MY SETTING
ENDFORM.

*COMMAND
*把修改后的数据传到ALV内表,然后修改数据库
FORM FORM_USER_COMMAND  USING UCOMM     LIKE SY-UCOMM
                                     SELFIELD TYPE SLIS_SELFIELD.   "FIXED PARAMETER

  DATA: LR_GRID TYPE REF TO CL_GUI_ALV_GRID.  "DEFINE OBJECT
                                              "TYPE REF TO用来定义一个数据对象,这个数据对象是用来指向另外的数据的;
                                              "DATA: R1 TYPE REF TO C1.
                                              "属于ABAP面向对象编程,C1是一个类,R1定义了这个类的对象

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' "GET ALV GUI OBJECT
      IMPORTING
        E_GRID = LR_GRID.

  CALL METHOD LR_GRID->CHECK_CHANGED_DATA. "检查内表变化,然后把改之前的内表先复制一个,然后2个内表,改之前的,跟改之后的

  SELFIELD-REFRESH = 'X'. "自动刷新,需要写在最后面,不然不会更新到内表

  "处理命令行
  CASE UCOMM.
    WHEN 'UPDATE_OO'.
      FREE GT_ITAB_UPDATE. "CLEAR TABLE

*      FIELD-SYMBOLS: <WA> LIKE GT_ITAB.
*      LOOP AT GT_ITAB ASSIGNING <WA>.
*         GT_ITAB_UPDATE-OBJECT_ID = <WA>-OBJECT_ID.
*         GT_ITAB_UPDATE-PROCESS_TYPE = <WA>-PROCESS_TYPE.
*         GT_ITAB_UPDATE-CREATE_BY = <WA>-CREATE_BY.
*         GT_ITAB_UPDATE-CREATE_AT = <WA>-CREATE_AT.
*         GT_ITAB_UPDATE-DESCRIPTION = <WA>-DESCRIPTION.
*      ENDLOOP.

      LOOP AT GT_ITAB INTO GW_ITAB WHERE GV_SELECT = 'X'. "GET SELECTED ROW. UPDATE INNER TABLE DATA
         GW_ITAB_UPDATE-OBJECT_ID = GW_ITAB-OBJECT_ID.
         GW_ITAB_UPDATE-PROCESS_TYPE = GW_ITAB-PROCESS_TYPE.
         GW_ITAB_UPDATE-CREATE_BY = GW_ITAB-CREATE_BY.
         GW_ITAB_UPDATE-CREATE_AT = GW_ITAB-CREATE_AT.
         GW_ITAB_UPDATE-DESCRIPTION = GW_ITAB-DESCRIPTION.

         APPEND GW_ITAB_UPDATE TO GT_ITAB_UPDATE.
      ENDLOOP.

      "UPDATE ZTBC_QUOTH_09 SET: CREATE_BY = GW_ITAB_UPDATE-CREATE_BY WHERE OBJECT_ID = GW_ITAB_UPDATE-OBJECT_ID.
      MODIFY ZTBC_QUOTH_09 FROM TABLE GT_ITAB_UPDATE. "UPDATE DBTABLE DATA

      IF SY-SUBRC = 0.
         "SELFIELD-REFRESH = 'X'.
         MESSAGE '更新了' TYPE 'I'. "MESSAGE
      ENDIF.
    WHEN 'DELETE'.
      MESSAGE '你点击了删除按钮' TYPE 'I'.
  ENDCASE.
ENDFORM.



版权声明:本文为qq_34060435原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。