文件名称:ABAP中的ALV操作
文件大小:410KB
文件格式:DOC
更新时间:2013-11-15 05:00:41
ALV
*&---------------------------------------------------------------------* *& Report YTEST31 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT YTEST31. DATA: OK_CODE TYPE SY-UCOMM, SAVE_OK TYPE SY-UCOMM. TABLES SPFLI. DATA LS_SPFLI TYPE SPFLI. DATA WA_SPFLI TYPE TABLE OF SPFLI. DATA WADEL_SPFLI TYPE TABLE OF SPFLI. SELECT * INTO TABLE WA_SPFLI FROM SPFLI. DATA: WA_CONTAINER TYPE SCRFNAME VALUE 'ALVDATA', ALV_GRID TYPE REF TO CL_GUI_ALV_GRID, WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. DATA WA_LAYOUT TYPE LVC_S_LAYO. WA_LAYOUT-EDIT = 'X'. CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED. DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER. ************************************************************************ * CLASS LCL_EVENT_RECEIVER DEFINITION * * * ************************************************************************ CLASS LCL_EVENT_RECEIVER DEFINITION. PUBLIC SECTION. TYPES: DEL_ROWS TYPE STANDARD TABLE OF SPFLI. DATA: DDEL_ROWS TYPE STANDARD TABLE OF SPFLI. METHODS: HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID IMPORTING ER_DATA_CHANGED. METHODS: UPDATE_DELTA_TABLES IMPORTING PR_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL. METHODS: GET_DELETED_ROWS EXPORTING DELETED_ROWS TYPE DEL_ROWS. ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION *&-------------------------------------------------------------------------- *& CLASS LCL_EVENT_RECEIVER IMPLENTMENTATION *& *&-------------------------------------------------------------------------- CLASS LCL_EVENT_RECEIVER IMPLEMENTATION. METHOD HANDLE_DATA_CHANGED. CALL METHOD UPDATE_DELTA_TABLES( ER_DATA_CHANGED ). ENDMETHOD. "HANDLE_DATA_CHANGED METHOD UPDATE_DELTA_TABLES. "HANDLE_DATA_CHANGED DATA: L_DEL_ROW TYPE LVC_S_MOCE. LOOP AT PR_DATA_CHANGED->MT_DELETED_ROWS INTO L_DEL_ROW. READ TABLE WA_SPFLI INTO LS_SPFLI INDEX L_DEL_ROW-ROW_ID. IF SY-SUBRC NE 0. MESSAGE E208(00) WITH '?理??'. ELSE. APPEND LS_SPFLI TO DDEL_ROWS. ENDIF. ENDLOOP. ENDMETHOD. "UPDATE_DELTA_TABLES METHOD GET_DELETED_ROWS. "update_delta_tables DELETED_ROWS = ME->DDEL_ROWS. ENDMETHOD. "GET_DELETED_ROWS ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION START-OF-SELECTION. CALL SCREEN 100. WRITE / '?除的内表??'. "get_deleted_rows WRITE / '______________'. "LCL_EVENT_RECEIVER DEFINITION CALL METHOD EVENT_RECEIVER->GET_DELETED_ROWS IMPORTING DELETED_ROWS = WADEL_SPFLI. LOOP AT WADEL_SPFLI INTO SPFLI. WRITE: / SPFLI-CARRID,SPFLI-CONNID,SPFLI-CITYFROM. ENDLOOP. WRITE: / '更新后的内表??:'. WRITE: / '__________________'. LOOP AT WA_SPFLI INTO SPFLI. WRITE : / SPFLI-CARRID,SPFLI-CONNID,SPFLI-CITYFROM. ENDLOOP. *此?是更新到数据?的操作 *WHEN 'SAVE'. * MODIFY SPFLI FORM TABLE WA_SPFLI. * IF SY-SUBRC NE 0. *MESSAGE I005(YMESS) WITH '更新数据??!'. EXIT. * ELSE. * MESSAGE I005(YMESS) WITH '更新数据OK!'. * ENDIF. * DELETE SPFLI FROM TABLE DELA_SPFLI. * IF SY-SUBRC NE 0. * MESSAGE I005(YMESS) WITH '更新数据??!'. * ELSE. * MESSAGE I005(YMESS) WITH '更新数据OK!'. * ENDIF. END-OF-SELECTION. INCLUDE YTEST31_STATUS_100. INCLUDE YTEST31_USER_COMMAND_100.