首页 > 其他分享 >ALV demo 07: CL_SALV_TABLE 设置可编辑

ALV demo 07: CL_SALV_TABLE 设置可编辑

时间:2022-10-16 17:01:29浏览次数:65  
标签:07 CL demo LO ------------------------------------------------------------------

以下是纯顾问群~

QQ群 :SAP干货铺,  群号:775662808
所有群管理严格,严格禁止一切外来链接、招聘、广告等垃圾信息!


效果:

点test 按钮切换到可编辑状态

ALV demo 07: CL_SALV_TABLE 设置可编辑_ide


建status

ALV demo 07: CL_SALV_TABLE 设置可编辑_更新数据_02

代码

REPORT ZLM_ALV006.
*----------------------------------------------------------------------*
* Define the Local class inheriting from the CL_SALV_MODEL_LIST
* to get an access of the model, controller and adapter which inturn
* provides the Grid Object
*----------------------------------------------------------------------*
CLASS LCL_SALV_MODEL DEFINITION INHERITING FROM CL_SALV_MODEL_LIST.

PUBLIC SECTION.
DATA: O_CONTROL TYPE REF TO CL_SALV_CONTROLLER_MODEL,
O_ADAPTER TYPE REF TO CL_SALV_ADAPTER.

METHODS:
GRABE_MODEL
IMPORTING
IO_MODEL TYPE REF TO CL_SALV_MODEL,

GRABE_CONTROLLER,

GRABE_ADAPTER.


PRIVATE SECTION.
DATA: LO_MODEL TYPE REF TO CL_SALV_MODEL.

ENDCLASS. "LCL_SALV_MODEL DEFINITION

*----------------------------------------------------------------------*
* Event handler for the added buttons
*----------------------------------------------------------------------*
CLASS LCL_EVENT_HANDLER DEFINITION.

PUBLIC SECTION.
DATA: GV_EDIT TYPE FLAG.
METHODS:
ON_USER_COMMAND FOR EVENT ADDED_FUNCTION OF CL_SALV_EVENTS
IMPORTING E_SALV_FUNCTION.

ENDCLASS. "lcl_event_handler DEFINITION

*----------------------------------------------------------------------*
* Local Report class - Definition
*----------------------------------------------------------------------*
CLASS LCL_REPORT DEFINITION.

PUBLIC SECTION.

TYPES: TY_T_SFLIGHTS TYPE STANDARD TABLE OF SFLIGHTS.

DATA: T_DATA TYPE TY_T_SFLIGHTS.

DATA: O_SALV TYPE REF TO CL_SALV_TABLE.
DATA: O_SALV_MODEL TYPE REF TO LCL_SALV_MODEL.
DATA: GV_EDIT TYPE FLAG.

METHODS:
GET_DATA,

GENERATE_OUTPUT.

ENDCLASS. "lcl_report DEFINITION

*----------------------------------------------------------------------*
* Global data
*----------------------------------------------------------------------*
DATA: LO_REPORT TYPE REF TO LCL_REPORT.

*----------------------------------------------------------------------*
* Start of selection
*----------------------------------------------------------------------*
START-OF-SELECTION.

CREATE OBJECT LO_REPORT.

LO_REPORT->GET_DATA( ).

LO_REPORT->GENERATE_OUTPUT( ).

*----------------------------------------------------------------------*
* Local Report class - Implementation
*----------------------------------------------------------------------*
CLASS LCL_REPORT IMPLEMENTATION.

METHOD GET_DATA.

SELECT * FROM SFLIGHTS
INTO TABLE ME->T_DATA
UP TO 30 ROWS.

ENDMETHOD. "get_data

METHOD GENERATE_OUTPUT.
TRY.
CL_SALV_TABLE=>FACTORY(
EXPORTING
LIST_DISPLAY = ABAP_FALSE
IMPORTING
R_SALV_TABLE = O_SALV
CHANGING
T_TABLE = T_DATA ).
CATCH CX_SALV_MSG. "#EC NO_HANDLER
ENDTRY.

O_SALV->SET_SCREEN_STATUS(
PFSTATUS = 'STATUS'
REPORT = SY-REPID
SET_FUNCTIONS = O_SALV->C_FUNCTIONS_ALL ).

*...Event handler for the button.....................................
DATA: LO_EVENTS TYPE REF TO CL_SALV_EVENTS_TABLE,
LO_EVENT_H TYPE REF TO LCL_EVENT_HANDLER.

* event object
LO_EVENTS = O_SALV->GET_EVENT( ).

* event handler
CREATE OBJECT LO_EVENT_H.

* setting up the event handler
SET HANDLER LO_EVENT_H->ON_USER_COMMAND FOR LO_EVENTS.

*...Get Model Object ...............................................
DATA: LO_ALV_MOD TYPE REF TO CL_SALV_MODEL.

* Narrow casting
LO_ALV_MOD ?= O_SALV.

* object for the local inherited class from the CL_SALV_MODEL_LIST
CREATE OBJECT O_SALV_MODEL.

* grabe model to use it later
CALL METHOD O_SALV_MODEL->GRABE_MODEL
EXPORTING
IO_MODEL = LO_ALV_MOD.

*...Generate ALV output ...............................................
O_SALV->DISPLAY( ).

ENDMETHOD. "generate_output

ENDCLASS. "lcl_report IMPLEMENTATION

*----------------------------------------------------------------------*
* LCL_SALV_MODEL implementation
*----------------------------------------------------------------------*
CLASS LCL_SALV_MODEL IMPLEMENTATION.

METHOD GRABE_MODEL.

* save the model
LO_MODEL = IO_MODEL.

ENDMETHOD. "grabe_model

METHOD GRABE_CONTROLLER.

* save the controller
O_CONTROL = LO_MODEL->R_CONTROLLER.

ENDMETHOD. "grabe_controller

METHOD GRABE_ADAPTER.

* save the adapter from controller
O_ADAPTER ?= LO_MODEL->R_CONTROLLER->R_ADAPTER.

ENDMETHOD. "grabe_adapter

ENDCLASS. "LCL_SALV_MODEL IMPLEMENTATION

*----------------------------------------------------------------------*
* Event Handler for the SALV
*----------------------------------------------------------------------*
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.

METHOD ON_USER_COMMAND.

DATA: LO_GRID TYPE REF TO CL_GUI_ALV_GRID,
LO_FULL_ADAP TYPE REF TO CL_SALV_FULLSCREEN_ADAPTER.


DATA: LS_LAYOUT TYPE LVC_S_LAYO.


* Contorller
CALL METHOD LO_REPORT->O_SALV_MODEL->GRABE_CONTROLLER.

* Adapter
CALL METHOD LO_REPORT->O_SALV_MODEL->GRABE_ADAPTER.

* Fullscreen Adapter (Down Casting)
LO_FULL_ADAP ?= LO_REPORT->O_SALV_MODEL->O_ADAPTER.

* Get the Grid
LO_GRID = LO_FULL_ADAP->GET_GRID( ).


CASE E_SALV_FUNCTION.


* Make ALV as Editable ALV
WHEN 'TEST'.


* Editable ALV
IF GV_EDIT IS INITIAL.
GV_EDIT = 'X'.
LS_LAYOUT-EDIT = 'X'.
ELSE.
CLEAR GV_EDIT.
CLEAR LS_LAYOUT-EDIT.
ENDIF.

* Set the front layout of ALV
CALL METHOD LO_GRID->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = LS_LAYOUT.

* refresh the table
CALL METHOD LO_GRID->REFRESH_TABLE_DISPLAY.

* ENDIF.

WHEN 'SAVE'.

* 根据 LO_REPORT->T_DATA 更新数据

ENDCASE.

ENDMETHOD. "on_user_command

ENDCLASS. "lcl_event_handler IMPLEMENTATION

标签:07,CL,demo,LO,------------------------------------------------------------------
From: https://blog.51cto.com/u_15680210/5760448

相关文章