Skip to Content
Technical Articles
Author's profile photo chavva paddu

CRUD Operations in Module Pool

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 “Module Pool” 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

Transaction Creation

Step 8

Go to SE93 transaction code.

Provide Transaction code and click on create button

The below screen will be displayed, Provide the required fields

Click on save 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

Conclusion:

By following the above steps we have successfully used CRUD Operations in module pool programming.

Hope this will help.

Thanks for reading.

 

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sandra Rossi
      Sandra Rossi

      Longest blog post I've ever seen. You said you would "explain" CRUD in module pool programming, but unfortunately I only see "do that and that", so I think your post is only good for people who want to train at creating a module pool (which will implement CRUD operations). Missing prerequisite: create transparent table ZMARA_TABLE1 (and maybe other ones?)

      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      +1. Also it says "module pool" but there is no actual module pool created, it's an ABAP report with some screens. Sure, there are modules but it doesn't mean we can use the term loosely. Module pools are special programs that are accessed using a transaction code.

      "Do this and that" without any explanation of why is very ineffective. If this was meant to educate the ABAP beginners in the dynpro screen programming I'm afraid it missed the mark.

      Author's profile photo Tomas Buryanek
      Tomas Buryanek

      Few tips:

      • It is not good idea to define variables inside MODULEs. Your variables are named with l* prefix, but they are actually global (one of the reasons why not to program directly inside modules, but rather inside methods).
      • It is good to use meaningful names of variables (I am pointing at "wa" & "it" for example).
      Author's profile photo Matthew Billingham
      Matthew Billingham

      As pointed out already - this is not module pool programming. You can tell this because you've not created a module pool.

      A few more tips:

      Check out MVC pattern. In my screen based programs, I handle all the screen operation in a controlling class, and all the interaction with the business logic in a model class.

      You must add locking.

      There's really no need for separate screens - you can do it all with just one.