Introduction In the below example I am going to explain CRUD Operations using module pool programming. Here, I have done CRUD operations by taking separate screens i.e., GET, CREATE, UPDATE and DELETE operations. Step 1: Go to SE38 transaction code. Provide the program name as “ZR_CRUD_OPERATIONS_MP” and click on the create button, a pop up will be displayed Step 2: Provide the title as “Create Report for CRUD Operations Using Module pool”, type as “executable program” and click on the save button, there need to save our own package Step 3: Initial Screen Double click on screen “100”, the below screen will be displayed there we need to click on yes button REPORT zr_crud_operations_mp NO STANDARD PAGE HEADING. *** --- Data Declarations DATA:it TYPE TABLE OF zmara_table1, wa TYPE zmara_table1. *** --- Start Of Selection START-OF-SELECTION. CALL SCREEN '100'. Enter the short description and click on “Layout” button Design the screen like as below. Save, check and activate In the flow logic, Uncomment both modules and double click on PBO module, the below screen will be displayed where we need to click on yes button Process Before Output (PBO) Provide the PF-STATUS as “Function keys”, double click on Function keys *&---------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'FUNCTION KEYS'. SET TITLEBAR 'TITLE1'. ENDMODULE. Expand the Function keys and provide the “save, back and cancel” save, check and activate Double click on “TITLE1”, a pop up will be displayed Provide the title as “SCREEN 1” and click on ok button Process After Input (PAI) Double click on PAI module, the below screen will be displayed where we need to click on yes button Provide the below code and double click on-screen ‘101‘ to navigate to another screen to see the GET operation data. *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0100 INPUT. CASE sy-ucomm . WHEN 'SAVE' OR 'BACK'. LEAVE PROGRAM. ENDCASE. CASE sy-ucomm. WHEN 'GET'. CALL SCREEN '101'. ENDCASE. ENDMODULE. A pop up will be displayed, we need to click on yes button Step 4: GET Operation – Screen Provide the short description and click on “Flow Logic” button Uncomment both modules and provide the below code PROCESS BEFORE OUTPUT. MODULE STATUS_0101. PROCESS AFTER INPUT. MODULE USER_COMMAND_0101. CHAIN. FIELD:WA-MATNR. MODULE INPUT_VALIDATION. ENDCHAIN. MODULE user_command_0101. Click on “Layout” button. Design the screen like as below Select the “push-button” , adjust the buttons as needed. Provide the Name, text and Fctcode Click on “custom container” button, adjust the container and Provide the name Save, check and activate Process Before Output (PBO): Double click on “STATUS_0101“, a pop up will be displayed need to click on yes button Where we need to provide the below code MODULE status_0101 OUTPUT. SET PF-STATUS 'FUNCTION KEYS'. SET TITLEBAR 'TITLE2'. DATA(cust_container) = NEW cl_gui_custom_container( container_name = 'CC_ALV1' ). DATA(lv_grid) = NEW cl_gui_alv_grid( i_parent = cust_container ). SELECT * FROM zmara_table1 INTO TABLE it. CALL METHOD lv_grid->set_table_for_first_display EXPORTING i_structure_name = 'ZMARA_TABLE1' " Internal Output Table Structure Name CHANGING it_outtab = it " Output Table EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ENDMODULE. Process After Input (PAI) Double click on “USER_COMMAND_0101“, a pop up will be displayed need to click on yes button Provide the code like as below MODULE user_command_0101 INPUT. CASE sy-ucomm. WHEN 'GET'. SELECT SINGLE * FROM zmara_table1 INTO wa WHERE matnr = wa-matnr . WHEN 'BACK'. LEAVE TO SCREEN 100. ENDCASE. ENDMODULE. Step 5: CREATE Operation – Screen Click on-screen “102”, a pop up will be displayed Where we need to click on yes button MODULE user_command_0100 INPUT. CASE sy-ucomm . WHEN 'SAVE' OR 'BACK'. LEAVE PROGRAM. ENDCASE. CASE sy-ucomm. WHEN 'GET'. CALL SCREEN '101'. WHEN 'CREATE'. CALL SCREEN '102'. ENDCASE. ENDMODULE. Provide the short description and click on “Layout” button Design the screen like as below Save, check and activate Click on “Flow logic” button, uncomment both modules and create objects for both PBO and PAI Process Before Output (PBO): Provide the below code for “STATUS_0102” MODULE status_0102 OUTPUT. SET PF-STATUS 'FUNCTION KEYS'. SET TITLEBAR 'TITLE3'. ENDMODULE. Process After Input (PAI) Provide the below code for “USER_COMMAND_0102” MODULE user_command_0102 INPUT. CASE sy-ucomm. WHEN 'BACK'. LEAVE TO SCREEN 100. CLEAR it. WHEN 'SAVE'. MODIFY zmara_table1 FROM wa. IF sy-subrc EQ 0. COMMIT WORK. MESSAGE TEXT-001 TYPE 'S'. ENDIF. DATA(cust_container1) = NEW cl_gui_custom_container( container_name = 'CC_ALV1' ). DATA(lv_grid1) = NEW cl_gui_alv_grid( i_parent = cust_container1 ). SELECT * FROM zmara_table1 INTO TABLE it. CALL METHOD lv_grid1->set_table_for_first_display EXPORTING i_structure_name = 'ZMARA_TABLE1' " Internal Output Table Structure Name CHANGING it_outtab = it " Output Table EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ENDCASE. ENDMODULE. Step 6: UPDATE Operation – Screen Click on screen “103”, a pop up will be displayed Where we need to click on yes button MODULE user_command_0100 INPUT. CASE sy-ucomm . WHEN 'SAVE' OR 'BACK'. LEAVE PROGRAM. ENDCASE. CASE sy-ucomm. WHEN 'GET'. CALL SCREEN '101'. WHEN 'CREATE'. CALL SCREEN '102'. WHEN 'UPDATE'. CALL SCREEN '103'. ENDCASE. ENDMODULE. Provide the short description and click on “Layout” button Design the screen like as below Save, check and activate Click on “Flow logic”, uncomment both modules and create objects for both PBO and PAI Process Before Output (PBO): Provide the below code for “STATUS_0103” MODULE status_0103 OUTPUT. SET PF-STATUS 'FUNCTION KEYS'. SET TITLEBAR 'TITLE4'. ENDMODULE. Process After Input (PAI) Provide the below code for “USER_COMMAND_0103” MODULE user_command_0103 INPUT. CASE sy-ucomm. WHEN 'BACK'. LEAVE TO SCREEN 100. WHEN 'GET'. SELECT SINGLE * FROM zmara_table1 INTO wa WHERE matnr = wa-matnr. WHEN 'UPDATE'. UPDATE zmara_table1 FROM wa. IF sy-subrc EQ 0. MESSAGE TEXT-002 TYPE 'S'. ENDIF. DATA(custom_contaner2) = NEW cl_gui_custom_container( container_name = 'CC_ALV1' ). DATA(lv_grid2) = NEW cl_gui_alv_grid( i_parent = custom_contaner2 ). SELECT * FROM zmara_table1 INTO TABLE it. CALL METHOD lv_grid2->set_table_for_first_display EXPORTING i_structure_name = 'ZMARA_TABLE1' " Internal Output Table Structure Name CHANGING it_outtab = it " Output Table EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ENDCASE. ENDMODULE. Step 7: DELETE Operation – Screen Click on-screen “104”, a pop up will be displayed Where we need to click on yes button MODULE user_command_0100 INPUT. CASE sy-ucomm . WHEN 'SAVE' OR 'BACK'. LEAVE PROGRAM. ENDCASE. CASE sy-ucomm. WHEN 'GET'. CALL SCREEN '101'. WHEN 'CREATE'. CALL SCREEN '102'. WHEN 'UPDATE'. CALL SCREEN '103'. WHEN 'DELETE'. CALL SCREEN '104'. ENDCASE. ENDMODULE. Provide the short description and click on “Layout” button Design the screen like as below Save, check and activate Click on “Flow logic”, uncomment both modules and create objects for both PBO and PAI Process Before Output (PBO): Provide the below code for “STATUS_0104” MODULE status_0104 OUTPUT. SET PF-STATUS 'FUNCTION KEYS'. SET TITLEBAR 'TITLE5'. ENDMODULE. Process After Input (PAI) Provide the below code for “USER_COMMAND_0104” MODULE user_command_0104 INPUT. CASE sy-ucomm. WHEN 'GET'. SELECT SINGLE * FROM zmara_table1 INTO wa WHERE matnr = wa-matnr. WHEN 'DELETE'. DELETE zmara_table1 FROM wa. IF sy-subrc EQ 0. MESSAGE TEXT-003 TYPE 'S'. ENDIF. DATA(cust_container3) = NEW cl_gui_custom_container( container_name = 'CC_ALV1' ). DATA(lv_grid3) = NEW cl_gui_alv_grid( i_parent = cust_container3 ). SELECT * FROM zmara_table1 INTO TABLE it. CALL METHOD lv_grid3->set_table_for_first_display EXPORTING i_structure_name = 'ZMARA_TABLE1' " Internal Output Table Structure Name CHANGING it_outtab = it " Output Table EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. WHEN 'BACK'. LEAVE TO SCREEN 100. ENDCASE. ENDMODULE. Source code( CRUD operation): REPORT zr_crud_operations_mp NO STANDARD PAGE HEADING. *** --- Data Declarations DATA:it TYPE TABLE OF zmara_table1, wa TYPE zmara_table1. *** --- Start Of Selection START-OF-SELECTION. CALL SCREEN '100'. *&---------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'FUNCTION KEYS'. SET TITLEBAR 'TITLE1'. ENDMODULE. *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0100 INPUT. CASE sy-ucomm . WHEN 'SAVE' OR 'BACK'. LEAVE PROGRAM. ENDCASE. CASE sy-ucomm. WHEN 'GET'. CALL SCREEN '101'. WHEN 'CREATE'. CALL SCREEN '102'. WHEN 'UPDATE'. CALL SCREEN '103'. WHEN 'DELETE'. CALL SCREEN '104'. ENDCASE. ENDMODULE. *&---------------------------------------------------------------------* *& Module STATUS_0101 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_0101 OUTPUT. SET PF-STATUS 'FUNCTION KEYS'. SET TITLEBAR 'TITLE2'. DATA(cust_container) = NEW cl_gui_custom_container( container_name = 'CC_ALV1' ). DATA(lv_grid) = NEW cl_gui_alv_grid( i_parent = cust_container ). SELECT * FROM zmara_table1 INTO TABLE it. CALL METHOD lv_grid->set_table_for_first_display EXPORTING i_structure_name = 'ZMARA_TABLE1' " Internal Output Table Structure Name CHANGING it_outtab = it " Output Table EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ENDMODULE. *&---------------------------------------------------------------------* *& Module USER_COMMAND_0101 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0101 INPUT. CASE sy-ucomm. WHEN 'GET'. SELECT SINGLE * FROM zmara_table1 INTO wa WHERE matnr = wa-matnr . WHEN 'BACK'. LEAVE TO SCREEN 100. ENDCASE. ENDMODULE. *&---------------------------------------------------------------------* *& Module STATUS_0102 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_0102 OUTPUT. SET PF-STATUS 'FUNCTION KEYS'. SET TITLEBAR 'TITLE3'. ENDMODULE. *&---------------------------------------------------------------------* *& Module USER_COMMAND_0102 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0102 INPUT. CASE sy-ucomm. WHEN 'BACK'. LEAVE TO SCREEN 100. CLEAR it. WHEN 'SAVE'. MODIFY zmara_table1 FROM wa. IF sy-subrc EQ 0. COMMIT WORK. MESSAGE TEXT-001 TYPE 'S'. ENDIF. DATA(cust_container1) = NEW cl_gui_custom_container( container_name = 'CC_ALV1' ). DATA(lv_grid1) = NEW cl_gui_alv_grid( i_parent = cust_container1 ). SELECT * FROM zmara_table1 INTO TABLE it. CALL METHOD lv_grid1->set_table_for_first_display EXPORTING i_structure_name = 'ZMARA_TABLE1' " Internal Output Table Structure Name CHANGING it_outtab = it " Output Table EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ENDCASE. ENDMODULE. *&---------------------------------------------------------------------* *& Module STATUS_0103 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_0103 OUTPUT. SET PF-STATUS 'FUNCTION KEYS'. SET TITLEBAR 'TITLE4'. ENDMODULE. *&---------------------------------------------------------------------* *& Module USER_COMMAND_0103 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0103 INPUT. CASE sy-ucomm. WHEN 'BACK'. LEAVE TO SCREEN 100. WHEN 'GET'. SELECT SINGLE * FROM zmara_table1 INTO wa WHERE matnr = wa-matnr. WHEN 'UPDATE'. UPDATE zmara_table1 FROM wa. IF sy-subrc EQ 0. MESSAGE TEXT-002 TYPE 'S'. ENDIF. DATA(custom_contaner2) = NEW cl_gui_custom_container( container_name = 'CC_ALV1' ). DATA(lv_grid2) = NEW cl_gui_alv_grid( i_parent = custom_contaner2 ). SELECT * FROM zmara_table1 INTO TABLE it. CALL METHOD lv_grid2->set_table_for_first_display EXPORTING i_structure_name = 'ZMARA_TABLE1' " Internal Output Table Structure Name CHANGING it_outtab = it " Output Table EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ENDCASE. ENDMODULE. *&---------------------------------------------------------------------* *& Module STATUS_0104 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_0104 OUTPUT. SET PF-STATUS 'FUNCTION KEYS'. SET TITLEBAR 'TITLE5'. ENDMODULE. *&---------------------------------------------------------------------* *& Module USER_COMMAND_0104 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0104 INPUT. CASE sy-ucomm. WHEN 'GET'. SELECT SINGLE * FROM zmara_table1 INTO wa WHERE matnr = wa-matnr. WHEN 'DELETE'. DELETE zmara_table1 FROM wa. IF sy-subrc EQ 0. MESSAGE TEXT-003 TYPE 'S'. ENDIF. DATA(cust_container3) = NEW cl_gui_custom_container( container_name = 'CC_ALV1' ). DATA(lv_grid3) = NEW cl_gui_alv_grid( i_parent = cust_container3 ). SELECT * FROM zmara_table1 INTO TABLE it. CALL METHOD lv_grid3->set_table_for_first_display EXPORTING i_structure_name = 'ZMARA_TABLE1' " Internal Output Table Structure Name CHANGING it_outtab = it " Output Table EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. WHEN 'BACK'. LEAVE TO SCREEN 100. ENDCASE. ENDMODULE. Save, check and activate Click on the execute (F8) button. Selection Screen GET Operation Double click on “get” button The below screen will be displayed, Provide the material number and click on the “get” button Get the details for the material number “1” at the right side Click on the “back” button, it will go to screen 1 CREATE Operation Double click on “create” button The below screen will be displayed, Provide the details and click on “save” button Will get the message as “The record will be created successfully” and it will be visible in the database table Click on “back” button, it will go to screen 1 UPDATE Operation Double click on “update” button The below screen will be displayed, Provide the material number and click on “get” button The details will be displayed and “Update” the table and click on the “update” button Will get the message as “The record will be updated successfully” and it will be visible in the database table Click on the “back” button, it will go to screen 1 DELETE Operation Double click on “delete” button The below screen will be displayed, Provide the material number and click on “get” button The details will be displayed and click on the “delete” button Will get the message as “The record will be deleted successfully” and the record will not be there in the database table