Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
91,896
This is my first blog in this series.

In this blog post you will learn how to make a basic Module Pool program using screen elements.

Module pool programming is a special type of programming which is used to create custom SAP screens.

Transaction code for creating module pool program is SE80.

There are four events in Module pool programming.

Here we will be using two events.

Process Before Output: 

It is triggered before MPP screen is displayed.

Process After Input:

It is triggered after MPP screen is displayed whenever user raises an action.

First create a new report in SE80 with top include and give the type Module pool as given below.


Create Transaction

Right click on report then create transaction then enter program name and screen name and then assign to package.

Create Screen

Step 1: Create by writing Call screen command in report as given below
CALL SCREEN 100.

Step 2: Now double click on screen and then click on layout.

Now Screen Painter will open. Here you can design your screen.

Click on “Dictionary/Program Fields Window”



Step 3: Enter the name of table in and click on “Get from Dictionary” and select the fields you want to display.


Step 4: Now drag and drop it on screen painter.


Step 5: Now create a button by clicking on the “Push Button” on the left toolbox and placing it on the screen wherever you want. Now double click on the button, a pop-up will come out, enter the name of the button there and mention the function code “Fct Code” this code will be used in user command. Now save and activate the screen.



Similarly create a push button for EXIT.

Step 6: Now go to the “Flow Logic” tab and uncomment the PBO and PAI modules respectively.

Then double click on both the Modules and create them in the Main Program.

Step 7: Now write code in user command for both the push buttons using function code as given below
CASE SY-UCOMM.
WHEN 'FC_1'.
SELECT
SINGLE
MATNR
ERSDA
CREATED_AT_TIME
ERNAM
MTART
MATKL
FROM MARA INTO CORRESPONDING FIELDS OF MARA WHERE MATNR = MARA-MAT
WHEN 'FC2'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.

Refer to the code below for the whole program.
*&---------------------------------------------------------------------*
*& Module Pool Z1015035_MPP_MARA_
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*

INCLUDE ZMARATOP . " Global Data
START-OF-SELECTION.
CALL SCREEN 100.

* INCLUDE ZMARAO01 . " PBO-Modules
* INCLUDE ZMARAI01 . " PAI-Modules
* INCLUDE ZMARAF01 . " FORM-Routines
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'FC_1'.
PERFORM GET_DATA.
WHEN 'FC2'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.

ENDMODULE.


---INCLUDE----

*&---------------------------------------------------------------------*
*& Include ZMARATOP - Module Pool Z1015035_MPP_MARA_
*&---------------------------------------------------------------------*
PROGRAM Z1015035_MPP_MARA_.
TABLES: MARA.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM GET_DATA .
SELECT
SINGLE
MATNR
ERSDA
CREATED_AT_TIME
ERNAM
MTART
MATKL
FROM MARA INTO CORRESPONDING FIELDS OF MARA WHERE MATNR = MARA-MATNR.

ENDFORM.


Output



By following the steps you will be able to create basic Module Pool Program. I hope this blog post helped you as beginner.

As we continue to learn more in this series about MPP, I will use this blog post to link all the parts of this series.

Follow my account  sinelanwar22 to be notified of the next blog post. Please feel free to ask any questions you have in the comments section below.

Join the conversation about the ABAP programming by following the tag  ABAP Development

Post questions and answer related to tag by following the tag Questions & Answers

Read other blog post on topic ABAP Development
6 Comments
larshp
Active Contributor

Thanks for sharing, even though dynpros are old technology, it is is still relevant for many customers

juan_suros
Contributor
Thank you for a new visit to the basic technologies.

I hope SAP remembers that they did not grow to their current size by offering cloud and phone apps, before they become the General Motors of the ERP world.
Sandra_Rossi
Active Contributor

Dynpros can be used not only with Module Pools, but also with Executable programs ("reports") and Function Pools/Groups, so "Module Pool Programming" is a too restrictive term. A module pool is to be used when you want to dedicate a program to only handle screens (and I would use ABAP Classes for the model and controller parts).

Although it's still used a lot, I agree that it's deprecated technology (replaced by Fiori App) and that you should inform at the beginning of the blog post.

I never use LEAVE PROGRAM, it's too excessive and to be reserved to special cases (like LEAVE TRANSACTION and LEAVE TO TRANSACTION), instead I'd use SET SCREEN 0 to leave the screen and return after the CALL SCREEN. It will help people when they use several screens. NB: it will not change anything in your example.

You should not define subroutines in the TOP include, better create a dedicated include for forms.

Note that subroutines are officially obsolete since 7.02, it was 13 years ago. Use methods instead. I would also mention that in the blog post.

hardyp180
SAP Mentor
SAP Mentor
0 Kudos
Now I would have to agree that there are so many existing ABAP programs using DYNPRO screens and the good old PBO/PAI modules to do all the business logic. Moreover I have no doubt dozens of new ones are being created every single day all throughout the world in SAP systems.

Nonetheless that does not change the fact that putting business logic in PBO/PAI modules became obsolete in the year 2000.with the advent of SAP 4.6 when ABAP OBJECTS was introduced.

Unlike Java there is no equivalent of SWING in the SAP GUI. The workaround - in 2000 and to this day - is to have as little business logic as possible (preferably none at all) in the PBO/PAI modules.

Methods cannot call screens and so you need a function module to actually bring the screen up and that function module has the screen definition within it. But really that function module should have no "smarts" at all - the controller class gets the current data from the model and calls the view class which calls the function module.

The function module then does nothing except return what command the user chose or what data the user changed on the screen.

That might sound horrificly complicated compared to what you can do with PBO/PAI but that is the way to apply the "separation of concerns" or the MVC pattern. Many people (including me circa 2012) thought all this OO stuff was nonsense and people were only being pushed to do this because it was "cool" and that is what other languages did.

As it turns out there are valid reasons why the traditional module pool approach of having business logic all mixed up with the UI was declared obsolete 22 years ago. One reason I can think of straight off is I could web enable my programs because none of the business logic was in the GUI.
hardyp180
SAP Mentor
SAP Mentor
And yes - the extended program check would warn you against putting routines in the TOP INCLUDE. That is not what the TOP INCLUDE is for. So do not do that ever and never tell beginners to do it.

And as I said on another blog I really am unhappy with telling beginners to use FORM routines. Once they start they will never stop.
Baibhab_Dey
Associate
Associate
0 Kudos

Thanks for sharing

Labels in this area