0% found this document useful (0 votes)
142 views

Module Pool Programming From Scratch - SAP Blogs

Uploaded by

Subhrajeet Das
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views

Module Pool Programming From Scratch - SAP Blogs

Uploaded by

Subhrajeet Das
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

Community

Ask a Question Write a Blog Post Login

Technical Articles

Sinela Anwar
June 17, 2022 | 3 minute read

Module Pool Programming from


scratch
 5  10  11,233
Follow

This is my first blog in this series.


 Like
In this blog post you will learn how to make a basic Module Pool program using
screen elements.
 RSS Feed
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.

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 1/11
12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

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”

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 2/11
12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

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.

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 3/11
12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

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

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 4/11
12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

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-M
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

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 5/11
12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

*--------------------------------------------------------------------
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
*&-------------------------------------------------------------------
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-MAT

ENDFORM.

Output

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 6/11
12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

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  Sinela Anwar 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

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 7/11
12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

Alert Moderator

Assigned Tags

ABAP Development

Similar Blog Posts 


Module Pool Programming from Scratch using Radio Button and Check Box (Part-2)
By Sinela Anwar Jun 22, 2022

Stop Module Pool Screen from Scrolling or Jumping to Initial Position


By Former Member Feb 25, 2014

Getting started with ABAP Programming from Scratch


By Anuja Kawadiwale Jun 08, 2022

Related Questions 
module pool
By Former Member Jul 19, 2007

Where to set up a TYPE-POOL Declaration in a Function Group ?


By Martin Sautter Aug 08, 2011

copy module pool


By Former Member Apr 03, 2008

5 Comments

You must be Logged on to comment or reply to a post.

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 8/11
12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

Lars Hvam
June 17, 2022 at 8:26 pm

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

Like 4 | Share

Juan Suros
June 17, 2022 at 9:34 pm

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.

Like 2 | Share

Sandra Rossi
June 18, 2022 at 7:13 am

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.

Like 5 | Share

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 9/11
12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

Paul Hardy
June 21, 2022 at 8:33 am

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.

Like 0 | Share

Paul Hardy
June 21, 2022 at 8:41 am

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.

Like 2 | Share

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 10/11
12/20/22, 1:40 PM Module Pool Programming from scratch | SAP Blogs

Find us on

Privacy Terms of Use

Legal Disclosure Copyright

Trademark Cookie Preferences

Newsletter Support

https://blogs.sap.com/2022/06/17/module-pool-programming-from-scratch/ 11/11

You might also like