Crud Operation Using OALV Custom Container

Estimated read time 15 min read

 

In SAP ABAP, CRUD (Create, Read, Update, Delete) operations form the foundation of most applications. They are essential for managing data in business scenarios. Using OALV (Object-Oriented ALV) containers, we can create interactive, user-friendly screens that allow end users to perform CRUD operations with ease. In this blog, I’ll demonstrate how to implement these operations step-by-step using OALV containers.

Steps To acheive crud operation using OALV containers

Fetch the record and store in the internal table.Call the specified ScreenCreate the container object using cl_gui_custom_containerCreate the OALV grid inside the custom containerEnable the editable mode for CRUD operationPopulate the field catalog based on the structure of the internal table Used in alv grid. Display the initial data using the method set_table_for_first_display. Add the toolbar events of cl_gui_alv_grid to create the button like create And delete. Define and handle events for the crud operation.

Let me explain with a scenario An airline admin wants to manage flights in the system. The system provides functionality to retrieve, create, update, and delete flight records using a user-friendly interface. This includes details such as the flight number, destination, departure time, arrival time, and status. Here i have a flight database table named as zsan_dt_flight. Here I am retreiving available flights based on the country from and country to.

Here i created one report program and maintained all the data declarations.

 

 

REPORT ZSAN_RP_OALV_CRUD.
INITIALIZATION .
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001 .
PARAMETERS : P_cnfrom type ZSAN_DE_CNTRYFROM MATCHCODE OBJECT
ZSAN_ESH_CFROM ,
P_cnto type ZSAN_DE_CNTRYTO MATCHCODE OBJECT
ZSAN_ESH_CTO .
SELECTION-SCREEN end of BLOCK b1 .

DATA : gt_flight_det TYPE TABLE OF zsan_dt_flight,
gs_flight_det TYPE zsan_dt_flight,
gt_flight_old TYPE TABLE OF zsan_dt_flight ,
gs_flight_new TYPE zsan_dt_flight ,
gt_flight_new type table of zsan_dt_flight ,
lo_cust TYPE REF TO cl_gui_custom_container,
lo_grid TYPE REF TO cl_gui_alv_grid ,
ls_layo TYPE lvc_s_layo,
lt_fieldcat TYPE lvc_t_fcat ,
CHECK .
types : tt_flight_old type table of zsan_dt_flight ,
tt_flight_new type table of zsan_dt_flight .

FIELD-SYMBOLS : <ft_flight_new> type tt_flight_new ,
<fs_flight_new> type zsan_dt_flight ,
<ft_flight_old> type tt_flight_old ,
<fs_flight_old> type zsan_dt_flight .
ASSIGN gt_flight_old to <ft_flight_old> .
ASSIGN gt_flight_new to <ft_flight_new> .
assign gs_flight_new to <fs_flight_new> .

 

 

Need to fetch the data from the relevant tables and call the specified screen and build layout for enabling editable mode.

 

 

START-OF-SELECTION .
PERFORM fetch_data.
call SCREEN β€˜100’ .

INCLUDE zsan_rp_fetch_data.
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& Form fetch_data
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& –> p1 text
*& <– p2 text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
FORM fetch_data .
SELECT FROM zsan_dt_flight FIELDS * WHERE countryfr = @P_cnfrom AND countryto = @p_cnto
into table _flight_det .
perform build_layout.
ENDFORM.
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& Form build_layout
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& –> p1 text
*& <– p2 text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
FORM build_layout .
ls_layo = VALUE #( edit = β€˜X’ col_opt = β€˜X’ ) .
ENDFORM.

 

 

Create the container object using cl_gui_custom_container.

Create the OALV grid inside the custom container

 

 

*β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-*
***INCLUDE ZSAN_RP_OALV_CRUD_STATUS_01O01.
*β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-*

*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& Module STATUS_0100 OUTPUT
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*&
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
MODULE status_0100 OUTPUT.
* SET PF-STATUS β€˜xxxxxxxx’.
* SET TITLEBAR β€˜xxx’.
if lo_cust is not BOUND .
CREATE OBJECT lo_cust
EXPORTING
* parent = ” Parent container
container_name = β€˜CONTAINER’
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endif .
if lo_cust is BOUND .
create OBJECT lo_grid
EXPORTING
i_parent = lo_cust ” Parent Container .
endif .

CALL FUNCTION β€˜LVC_FIELDCATALOG_MERGE’
EXPORTING
* I_BUFFER_ACTIVE =
I_STRUCTURE_NAME = β€˜ZSAN_DT_FLIGHT’
* I_CLIENT_NEVER_DISPLAY = β€˜X’
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
set HANDLER handle_event=>handle_toolbar for lo_grid .
set HANDLER handle_event=>handle_user for lo_grid .
lo_grid->set_table_for_first_display(
EXPORTING
i_structure_name = β€˜ZSAN_DT_FLIGHT’ ” Internal Output Table Structure Name
is_layout = ls_layo ” Layout
CHANGING
it_outtab = gt_flight_det ” Output Table
it_fieldcatalog = lt_fieldcat ” Field Catalog
EXCEPTIONS
invalid_parameter_combination = 1 ” Wrong Parameter
program_error = 2 ” Program Errors
too_many_lines = 3 ” Too many Rows in Ready for Input Grid
others = 4
).
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMODULE.

 

 

In the Process after input write the logic to enable the pfstatus back cancel and leave button.

 

 

*β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-*
***INCLUDE ZSAN_RP_OALV_CRUD_USER_COMMI01.
*β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-*
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& Module USER_COMMAND_0100 INPUT
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
* text
*β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-*
MODULE user_command_0100 INPUT.
case SY-UCOMM .
WHEN β€˜BACK’ OR β€˜CANCEL’ OR β€˜EXIT’ .
LEAVE to SCREEN 0 .
ENDCASE .
ENDMODULE.

 

 

Add the toolbar events of cl_gui_alv_grid to create the button like create And delete.

 

 

CLASS handle_event DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
CLASS-METHODS:handle_user FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.

 

 

We can make use of standard table type ttb_button to add, modify, control toolbar buttons in alv.

FUNCTION ICON QUICKINFO BUTN_TYPE DISABLED TEXT CHECKED are the fields available in the predefined stucture STB_BUTTON.

 

 

CLASS handle_event IMPLEMENTATION .
METHOD handle_toolbar.
e_object->mt_toolbar = VALUE #( base e_object->mt_toolbar (
function = β€˜SAVE’
icon = ICON_SYSTEM_SAVE
butn_type = 0
text = β€˜SAVE’
quickinfo = β€˜SAVE’) (
function = β€˜DELETE’
icon = ICON_DELETE
quickinfo = β€˜delete record’
butn_type = 0
text = β€˜DELETE’
) ) .
ENDMETHOD.
METHOD handle_user.
CASE e_ucomm.
WHEN β€˜SAVE’.
PERFORM update_data_base.

when β€˜DELETE’ .
PERFORM DELETE_DATA_BASE .
ENDCASE.
ENDMETHOD.
ENDCLASS .

 

 

Define and handle events for the crud operation.

 

*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& Form update_data_base
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& –> p1 text
*& <– p2 text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
FORM update_data_base .

lo_grid->check_changed_data(
IMPORTING
e_valid = check ” Entries are Consistent
* CHANGING
* c_refresh = β€˜X’ ” Character Field of Length 1
).
IF gt_flight_det NE gt_flight_old .
LOOP AT gt_flight_det ASSIGNING FIELD-SYMBOL(<fs_flight_det>) .
MOVE-CORRESPONDING <fs_flight_det> TO <fs_flight_new> .
APPEND INITIAL LINE TO <ft_flight_new> ASSIGNING <fs_flight_new> .
ENDLOOP .
CALL FUNCTION β€˜ZUPD_FM_FLIGHT_UPDATE’ IN UPDATE TASK
EXPORTING
gt_upd_flight_det = <ft_flight_new> .
COMMIT WORK . β€œUpdate function module”
IF sy-subrc = 0 .
MESSAGE s055(zcl_san_msg) . β€œData Updated Successfully”
ELSE .
MESSAGE e080(zcl_san_msg) DISPLAY LIKE β€˜I’ .
β€œData is Not updated to the database”
ENDIF .
ENDIF .
ENDFORM.

 

 

 

 

DATA: lt_selected_rows TYPE lvc_t_row,
lv_index TYPE lvc_index,
ls_row TYPE lvc_s_row.

CALL METHOD lo_grid->get_selected_rows
IMPORTING
et_index_rows = lt_selected_rows ” Indexes of Selected
Rows
* et_row_no = ” Numeric IDs of Selected Rows
.
IF lt_selected_rows IS INITIAL.
MESSAGE β€˜No rows selected for deletion’ TYPE β€˜I’.
RETURN.
ENDIF.

LOOP AT lt_selected_rows INTO ls_row.
lv_index = ls_row-index.
” Get the corresponding row from the internal table
READ TABLE gt_flight_det INTO gs_flight_det INDEX lv_index.

IF sy-subrc = 0.
” Delete the record from the database
DELETE FROM zsan_dt_flight WHERE airline_code
= gs_flight_det-airline_code AND
flight_conn_no = gs_flight_det-flight_conn_no
AND airport_to = gs_flight_det-airport_to .
IF sy-subrc = 0.
” If deletion was successful, remove from the internal table
DELETE gt_flight_det INDEX lv_index.

ELSE.
MESSAGE e081(zcl_san_msg) .
ENDIF.
ENDIF.
ENDLOOP.
CALL METHOD lo_grid->refresh_table_display.
MESSAGE s060(zcl_san_msg) .

ENDFORM.

 

 

Execute the report progaram.

Read 

To retreive the flight details from the selected country. 

Update 

Admin can update the flight details based on the requirements.

Here the data is updated successfully. 

Insert 

Admin can insert the new flights to the existing database table. Click on append row.  

Click on save  

click on save 

One entry is  created in the database table.  also multiple entries  can be created by clicking on append row multiple times.

Delete 

Select the flights (entry)  and click on the delete button.  

the selected flight entry is deleted from the database table.

 

 

 

 

 

 

 

 

 

 

 

 

 

​  In SAP ABAP, CRUD (Create, Read, Update, Delete) operations form the foundation of most applications. They are essential for managing data in business scenarios. Using OALV (Object-Oriented ALV) containers, we can create interactive, user-friendly screens that allow end users to perform CRUD operations with ease. In this blog, I’ll demonstrate how to implement these operations step-by-step using OALV containers.Steps To acheive crud operation using OALV containersFetch the record and store in the internal table.Call the specified ScreenCreate the container object using cl_gui_custom_containerCreate the OALV grid inside the custom containerEnable the editable mode for CRUD operationPopulate the field catalog based on the structure of the internal table Used in alv grid. Display the initial data using the method set_table_for_first_display. Add the toolbar events of cl_gui_alv_grid to create the button like create And delete. Define and handle events for the crud operation.Let me explain with a scenario An airline admin wants to manage flights in the system. The system provides functionality to retrieve, create, update, and delete flight records using a user-friendly interface. This includes details such as the flight number, destination, departure time, arrival time, and status. Here i have a flight database table named as zsan_dt_flight. Here I am retreiving available flights based on the country from and country to.Here i created one report program and maintained all the data declarations.  REPORT ZSAN_RP_OALV_CRUD.
INITIALIZATION .
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001 .
PARAMETERS : P_cnfrom type ZSAN_DE_CNTRYFROM MATCHCODE OBJECT
ZSAN_ESH_CFROM ,
P_cnto type ZSAN_DE_CNTRYTO MATCHCODE OBJECT
ZSAN_ESH_CTO .
SELECTION-SCREEN end of BLOCK b1 .

DATA : gt_flight_det TYPE TABLE OF zsan_dt_flight,
gs_flight_det TYPE zsan_dt_flight,
gt_flight_old TYPE TABLE OF zsan_dt_flight ,
gs_flight_new TYPE zsan_dt_flight ,
gt_flight_new type table of zsan_dt_flight ,
lo_cust TYPE REF TO cl_gui_custom_container,
lo_grid TYPE REF TO cl_gui_alv_grid ,
ls_layo TYPE lvc_s_layo,
lt_fieldcat TYPE lvc_t_fcat ,
CHECK .
types : tt_flight_old type table of zsan_dt_flight ,
tt_flight_new type table of zsan_dt_flight .

FIELD-SYMBOLS : <ft_flight_new> type tt_flight_new ,
<fs_flight_new> type zsan_dt_flight ,
<ft_flight_old> type tt_flight_old ,
<fs_flight_old> type zsan_dt_flight .
ASSIGN gt_flight_old to <ft_flight_old> .
ASSIGN gt_flight_new to <ft_flight_new> .
assign gs_flight_new to <fs_flight_new> .  Need to fetch the data from the relevant tables and call the specified screen and build layout for enabling editable mode.  START-OF-SELECTION .
PERFORM fetch_data.
call SCREEN β€˜100’ .

INCLUDE zsan_rp_fetch_data.
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& Form fetch_data
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& –> p1 text
*& <– p2 text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
FORM fetch_data .
SELECT FROM zsan_dt_flight FIELDS * WHERE countryfr = @P_cnfrom AND countryto = @p_cnto
into table _flight_det .
perform build_layout.
ENDFORM.
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& Form build_layout
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& –> p1 text
*& <– p2 text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
FORM build_layout .
ls_layo = VALUE #( edit = β€˜X’ col_opt = β€˜X’ ) .
ENDFORM.  Create the container object using cl_gui_custom_container.Create the OALV grid inside the custom container  *β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-*
***INCLUDE ZSAN_RP_OALV_CRUD_STATUS_01O01.
*β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-*

*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& Module STATUS_0100 OUTPUT
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*&
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
MODULE status_0100 OUTPUT.
* SET PF-STATUS β€˜xxxxxxxx’.
* SET TITLEBAR β€˜xxx’.
if lo_cust is not BOUND .
CREATE OBJECT lo_cust
EXPORTING
* parent = ” Parent container
container_name = β€˜CONTAINER’
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endif .
if lo_cust is BOUND .
create OBJECT lo_grid
EXPORTING
i_parent = lo_cust ” Parent Container .
endif .

CALL FUNCTION β€˜LVC_FIELDCATALOG_MERGE’
EXPORTING
* I_BUFFER_ACTIVE =
I_STRUCTURE_NAME = β€˜ZSAN_DT_FLIGHT’
* I_CLIENT_NEVER_DISPLAY = β€˜X’
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
set HANDLER handle_event=>handle_toolbar for lo_grid .
set HANDLER handle_event=>handle_user for lo_grid .
lo_grid->set_table_for_first_display(
EXPORTING
i_structure_name = β€˜ZSAN_DT_FLIGHT’ ” Internal Output Table Structure Name
is_layout = ls_layo ” Layout
CHANGING
it_outtab = gt_flight_det ” Output Table
it_fieldcatalog = lt_fieldcat ” Field Catalog
EXCEPTIONS
invalid_parameter_combination = 1 ” Wrong Parameter
program_error = 2 ” Program Errors
too_many_lines = 3 ” Too many Rows in Ready for Input Grid
others = 4
).
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMODULE.  In the Process after input write the logic to enable the pfstatus back cancel and leave button.  *β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-*
***INCLUDE ZSAN_RP_OALV_CRUD_USER_COMMI01.
*β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-*
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& Module USER_COMMAND_0100 INPUT
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
* text
*β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-*
MODULE user_command_0100 INPUT.
case SY-UCOMM .
WHEN β€˜BACK’ OR β€˜CANCEL’ OR β€˜EXIT’ .
LEAVE to SCREEN 0 .
ENDCASE .
ENDMODULE.  Add the toolbar events of cl_gui_alv_grid to create the button like create And delete.  CLASS handle_event DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
CLASS-METHODS:handle_user FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.  We can make use of standard table type ttb_button to add, modify, control toolbar buttons in alv.FUNCTION ICON QUICKINFO BUTN_TYPE DISABLED TEXT CHECKED are the fields available in the predefined stucture STB_BUTTON.  CLASS handle_event IMPLEMENTATION .
METHOD handle_toolbar.
e_object->mt_toolbar = VALUE #( base e_object->mt_toolbar (
function = β€˜SAVE’
icon = ICON_SYSTEM_SAVE
butn_type = 0
text = β€˜SAVE’
quickinfo = β€˜SAVE’) (
function = β€˜DELETE’
icon = ICON_DELETE
quickinfo = β€˜delete record’
butn_type = 0
text = β€˜DELETE’
) ) .
ENDMETHOD.
METHOD handle_user.
CASE e_ucomm.
WHEN β€˜SAVE’.
PERFORM update_data_base.

when β€˜DELETE’ .
PERFORM DELETE_DATA_BASE .
ENDCASE.
ENDMETHOD.
ENDCLASS .  Define and handle events for the crud operation. *&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& Form update_data_base
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
*& –> p1 text
*& <– p2 text
*&β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”*
FORM update_data_base .

lo_grid->check_changed_data(
IMPORTING
e_valid = check ” Entries are Consistent
* CHANGING
* c_refresh = β€˜X’ ” Character Field of Length 1
).
IF gt_flight_det NE gt_flight_old .
LOOP AT gt_flight_det ASSIGNING FIELD-SYMBOL(<fs_flight_det>) .
MOVE-CORRESPONDING <fs_flight_det> TO <fs_flight_new> .
APPEND INITIAL LINE TO <ft_flight_new> ASSIGNING <fs_flight_new> .
ENDLOOP .
CALL FUNCTION β€˜ZUPD_FM_FLIGHT_UPDATE’ IN UPDATE TASK
EXPORTING
gt_upd_flight_det = <ft_flight_new> .
COMMIT WORK . β€œUpdate function module”
IF sy-subrc = 0 .
MESSAGE s055(zcl_san_msg) . β€œData Updated Successfully”
ELSE .
MESSAGE e080(zcl_san_msg) DISPLAY LIKE β€˜I’ .
β€œData is Not updated to the database”
ENDIF .
ENDIF .
ENDFORM.    DATA: lt_selected_rows TYPE lvc_t_row,
lv_index TYPE lvc_index,
ls_row TYPE lvc_s_row.

CALL METHOD lo_grid->get_selected_rows
IMPORTING
et_index_rows = lt_selected_rows ” Indexes of Selected
Rows
* et_row_no = ” Numeric IDs of Selected Rows
.
IF lt_selected_rows IS INITIAL.
MESSAGE β€˜No rows selected for deletion’ TYPE β€˜I’.
RETURN.
ENDIF.

LOOP AT lt_selected_rows INTO ls_row.
lv_index = ls_row-index.
” Get the corresponding row from the internal table
READ TABLE gt_flight_det INTO gs_flight_det INDEX lv_index.

IF sy-subrc = 0.
” Delete the record from the database
DELETE FROM zsan_dt_flight WHERE airline_code
= gs_flight_det-airline_code AND
flight_conn_no = gs_flight_det-flight_conn_no
AND airport_to = gs_flight_det-airport_to .
IF sy-subrc = 0.
” If deletion was successful, remove from the internal table
DELETE gt_flight_det INDEX lv_index.

ELSE.
MESSAGE e081(zcl_san_msg) .
ENDIF.
ENDIF.
ENDLOOP.
CALL METHOD lo_grid->refresh_table_display.
MESSAGE s060(zcl_san_msg) .

ENDFORM.  Execute the report progaram.Read To retreive the flight details from the selected country. Update Admin can update the flight details based on the requirements.Here the data is updated successfully. Insert Admin can insert the new flights to the existing database table. Click on append row.  Click on save  click on save One entry is  created in the database table.  also multiple entries  can be created by clicking on append row multiple times.Delete Select the flights (entry)  and click on the delete button.  the selected flight entry is deleted from the database table.               Read More Application Development Blog Posts articles 

#SAP

You May Also Like

More From Author