4 Replies Latest reply: Feb 18, 2008 2:37 PM by Jyothsna M RSS

how to write module pool program

surender kumar
Currently Being Moderated

hai,

 

what is the module -pool program ?

what are the procedures to write the module-pool program.

plz give the simple program for module-pool programs?

regards

surender

  • Re: how to write module pool program
    DEEPANKER MAHAJAN
    Currently Being Moderated

    Hi

     

    Hope it will help you.

     

    <REMOVED BY MODERATOR>

     

    REPORT ZBHMOD1 .
    DATA:OKCODE1 LIKE SY-UCOMM,
    OKCODE2 LIKE SY-UCOMM.
    DATA:N1(10) TYPE N,N2(10) TYPE N,RES(12) TYPE N.
    
    MODULE USER_COMMAND_1000 INPUT.
    
    CASE OKCODE1.
    WHEN 'NEXT'.
    RES = N1 + N2.
    SET SCREEN 1001.
    WHEN 'CLEA'.
    CLEAR:N1,N2.
    WHEN 'BACK'.
    SET SCREEN '0'.
    ENDCASE.
    
    ENDMODULE. " USER_COMMAND_1000 INPUT
    
    
    MODULE STATUS_1000 OUTPUT.
    * SET PF-STATUS 'xxxxxxxx'.
    SET TITLEBAR 'TIT1'.
    
    ENDMODULE. " STATUS_1000 OUTPUT
    
    
    MODULE USER_COMMAND_1001 INPUT.
    
    CASE OKCODE2.
    WHEN 'BACK'.
    SET SCREEN 1000.
    ENDCASE.
    
    ENDMODULE. " USER_COMMAND_1001 INPUT
    
    
    MODULE STATUS_1001 OUTPUT.
    * SET PF-STATUS 'xxxxxxxx'.
    SET TITLEBAR 'TIT2'.
    
    ENDMODULE. " STATUS_1001 OUTPUT

     

    FLOW LOGIC:

     

    PROCESS BEFORE OUTPUT.
    MODULE STATUS_1000.
    *
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_1000.
    
    
    
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_1001.
    *
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_1001.

     

    **************************************************************************

    ************************************************************************

    2)

     

    REPORT ZBHMOD2.
    
    DATA: OKCODE1 TYPE SY-UCOMM,
    OKCODE2 TYPE SY-UCOMM,
    ENAME(10) TYPE C,
    DNAME(10) TYPE C.
    
    MODULE STATUS_1000 OUTPUT.
    * SET PF-STATUS 'xxxxxxxx'.
    SET TITLEBAR 'TIT1'.
    
    ENDMODULE. " STATUS_1000 OUTPUT
    
    
    MODULE STATUS_1001 OUTPUT.
    * SET PF-STATUS 'xxxxxxxx'.
    SET TITLEBAR 'TIT2'.
    
    ENDMODULE. " STATUS_1001 OUTPUT
    
    
    MODULE USER_COMMAND_1000 INPUT.
    
    CASE OKCODE1.
    WHEN 'BACK'.
    SET SCREEN '0'.
    WHEN 'NEXT'.
    DNAME = ENAME.
    SET SCREEN '1001'.
    ENDCASE.
    
    ENDMODULE. " USER_COMMAND_1000 INPUT
    
    
    MODULE USER_COMMAND_1001 INPUT.
    
    CASE OKCODE2.
    WHEN 'BACK'.
    SET SCREEN '1000'.
    ENDCASE.
    
    ENDMODULE. " USER_COMMAND_1001 INPUT
    
    
    
    FORM ON_CTMENU_FORM USING ZDEMO1 TYPE REF TO CL_CTMENU.
    
    CALL METHOD ZDEMO1->LOAD_GUI_STATUS
    EXPORTING
    PROGRAM = 'ZDEMO1'
    STATUS = 'ZDEMO1'
    MENU = ZDEMO1.
    
    ENDFORM. " ON_CTMENU_FORM

     

    FLOW LOGIC:

     

    PROCESS BEFORE OUTPUT.
    MODULE STATUS_1000.
    *
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_1000.
    
    
    
    
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_1001.
    *
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_1001.

     

    *************************************************************

     

    Every Screen has a pbo and a pai.

    Screen elements are the textbox, buttons, radio buttons and check boxes .....

    If we want to pass data from a abap program to a screen element, we have to create a variable with the name we have given in the screen.So whatever the value is present in that variable is reflected on to the screen element.

    Here is an example :

    Using subscreens and some of the screen elements

     

    REPORT demo_dynpro_subscreens.
    
    DATA: ok_code TYPE sy-ucomm,
    save_ok TYPE sy-ucomm.
    
    DATA: number1(4) TYPE n VALUE '0110',
    number2(4) TYPE n VALUE '0130',
    field(10) TYPE c, field1(10) TYPE c, field2(10) TYPE c.
    
    CALL SCREEN 100.
    
    MODULE status_100 OUTPUT.
    SET PF-STATUS 'SCREEN_100'.
    ENDMODULE.
    
    MODULE fill_0110 OUTPUT.
    field = 'Eingabe 1'(001).
    ENDMODULE.
    
    MODULE fill_0120 OUTPUT.
    field = field1.
    ENDMODULE.
    
    MODULE fill_0130 OUTPUT.
    field = 'Eingabe 2'(002).
    ENDMODULE.
    
    MODULE fill_0140 OUTPUT.
    field = field2.
    ENDMODULE.
    
    MODULE cancel INPUT.
    LEAVE PROGRAM.
    ENDMODULE.
    
    MODULE save_ok INPUT.
    save_ok = ok_code.
    CLEAR ok_code.
    ENDMODULE.
    
    MODULE user_command_0110 INPUT.
    IF save_ok = 'OK1'.
    number1 = '0120'.
    field1 = field.
    CLEAR field.
    ENDIF.
    ENDMODULE.
    
    MODULE user_command_0130 INPUT.
    IF save_ok = 'OK2'.
    number2 = '0140'.
    field2 = field.
    CLEAR field.
    ENDIF.
    ENDMODULE.
    
    MODULE user_command_100 INPUT.
    CASE save_ok.
    WHEN 'SUB1'.
    number1 = '0110'.
    WHEN 'SUB2'.
    number1 = '0120'.
    CLEAR field1.
    WHEN 'SUB3'.
    number2 = '0130'.
    WHEN 'SUB4'.
    number2 = '0140'.
    CLEAR field2.
    ENDCASE.
    ENDMODULE.
    
    
    * flow logic for screen 100 
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_100.
    CALL SUBSCREEN: AREA1 INCLUDING SY-REPID NUMBER1,
    AREA2 INCLUDING SY-REPID NUMBER2.
    
    PROCESS AFTER INPUT.
    MODULE CANCEL AT EXIT-COMMAND.
    MODULE SAVE_OK.
    CALL SUBSCREEN: AREA1,
    AREA2.
    MODULE USER_COMMAND_100.
    
    * flow logic for screen 110 
    PROCESS BEFORE OUTPUT.
    MODULE FILL_0110.
    
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_0110.
    
    * flow logic for screen 120 
    PROCESS BEFORE OUTPUT.
    MODULE FILL_0120.
    
    PROCESS AFTER INPUT.
    
    * flow logic for screen 130 
    PROCESS BEFORE OUTPUT.
    MODULE FILL_0130.
    
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_0130. 
    
    * flow logic for screen 140 
    
    PROCESS BEFORE OUTPUT.
    MODULE FILL_0140.
    
    PROCESS AFTER INPUT.

     

    Edited by: Alvaro Tejada Galindo on Feb 18, 2008 12:44 PM

  • Re: how to write module pool program
    DEEPANKER MAHAJAN
    Currently Being Moderated
  • Re: how to write module pool program
    manjari kotta
    Currently Being Moderated

    Hi,

    goto se51 to create customized screen and then we need to write the code in the form of module which we place module names in the flow logic and the code in it we will write in the subsequent program.

    module pool program is nothing but the collection of modules in the program.

  • Re: how to write module pool program
    Jyothsna M
    Currently Being Moderated

    Hi

    This component though is not attached to the screen painter, plays important role in transaction. Normally, for reports, on line executable programs are written but for transaction, Module Pool Programs are written. The module pool program contains only modules to handle various events associated with screen and data declaration statements.

     

    System divides the module pool program into several include program. These are global field, PBO modules, and PAI modules. It is entirely user’s decision whether to use these modules or write directly into main program.

     

    Creation of Module Pool Program

     

    You can create module pool program either through

     

    Object browser

     

    System automatically creates the module pool program and for these program which are created through object browser, system creates the include modules.

    Or

    ABAP/4 editor

     

    It is similar to normal program creation. Type of program should be given ‘M’ and is not created by system.

     

    Communication between Dynpro and Module Program

     

    For each screen, the system executes the flow logic, which contains corresponding events. The control is passed to Module Pool Program. Module Pool Program handles the code for these events and again passes back control to the flow logic and finally to screen. Unlike on line program, in this case, the control remains with flow logic. The switching of control between flow logic and module pool program and back is common process when user executes transaction.

     

    Creation of a Complete Transaction

     

    Steps involved to create a complete transaction

     

    •     Create module pool program.

    •     From screen painter create screens.

    •     Write flow logic for each screen.

    •     Write code for all the events in module pool program.

    •     Check for any error in screen and flow logic.

    •     Generate each and every component of screen i.e. flow logic and screen.

    •     Single screen can be tested using Screen Painter.

    •     Create transaction code through object browser.

    •     Generate the transaction code.

    •     User can execute the transaction by entering the transaction code in the command field.

     

    Handling Function Code

     

    The function code or OKCODE is the last field of Field list. Function code can be handled as follows:

    During the Designing of the screen, a function code is assigned to pushbutton.

     

    •     In field list, developer needs to specify OKCODE as last field.

    •     In module program it is a global field and can be evaluated in the PAI event.

    •     A function code is treated in the same way, regardless it comes from pushbutton, menu item or any other GUI element.

    When the user clicks on the Display button, you want to display details of sflight, with corresponding carrid and connid (which is entered by the user).

     

    Module pool program to handle this particular screen is as follows:

     

    Program YVTEST7.

    TABLES: SFLIGHT.

    DATA: OKCODE (4).

     

    MODULE INPUT1 INPUT,

    CASE OKCODE.

       WHEN ‘DISP’.

         SELECT * FROM SFLIGHT

                WHERE CARRID =  SFLIGHT – CARRID AND

                               CONNID = SFLIGHT – CONNID.

         ENDSELECT.

         LEAVE TO SCREEN 200.

       WHEN ‘EXIT’.  LEAVE TO SCREEN 0.

      ENDCASE.

    ENDMODULE.               “INPUT1 INPUT

    MODULE USER_COMMAND_0200 INPUT.

    CASE OKCODE.

    WHEN ‘BACK’. LEAVE TO SCREEN 100.

    ENDCASE.

    ENDMODULE.                    “USER_COMMAND_0200 INPUT

     

    When the user clicks on display, control is transferred to screen no. 200 on which you display sflight details & on the same screen, when user clicks on BACK button, he comes back to main screen.

    Flow logic for screen 100 is as follows:

     

    PROCESS AFTER INPUT.

    MODULE INPUT.

    Flow logic for screen 200

     

    PROCESS AFTER INPUT.

    USER_COMMAND_0200.

     

    MODULES: Modules are handled in module pool program.

     

    You need to write flow logic for screen 200 and design screen 200.

    In case of transaction transfer of data from program to screen is automatic i.e. you need not transfer the data from program to screen explicitly. The fields, which you define in the screen receives the data from program and displays the same.

     

    The Field Checks

     

    As already mentioned Transaction is the only method, which SAP recommends to update the database tables. Data entered in the database table should be valid and correct. Data entered is validated at each and every point. ABAP/4 offers various methods to validate data and those are as follows:

     

    •     Automatic field checks

    •     Checks performed in the flow logic

    •     Checks performed in the ABAP/4 module pool program

     

     

    Automatic Field Checks

     

    These checks are based on the field information stored in the dictionary. These checks are performed by the system automatically when the user enters the data for the screen field. System performs these checks before PAI event is triggered. Types of field checks performed by system are as follows:

    •     Required input

    While designing the screen, for particular screen field if you click the Req. Entry checkbox, the field becomes mandatory. When the transaction is executed if user leaves this particular field blank, the system displays error message. User cannot proceed until the user enters some data.

    •     Proper Data Format

    Each field has its own data format whether it is table field or screen field. Whenever data is entered, system checks for the proper format of the data. For example date. Each user has its own format for date, which is defined in the user master record. If the date defined in the user master record is in the format DD/MM/YYYY, if the user enters the date, say, in YY/DD/MM, the user displays the error message. System also checks for the value of month or days. For example if month entered is greater than twelve then the error message is displayed.

    •     Valid Value for the Field

    In data dictionary two tables are related by Primary key-Foreign key relationship.  Whenever the user enters the data, the system checks for the check table values.   Also in Domain, if you have fixed values, then the system checks for these values.

     

    Automatic field checks are repeated each time the user enters the data.

     

    About at Exit – Command

     

    Automatic field checks can be avoided by AT EXIT-COMMAND, which works exactly the same way as Cancel works on application tools bar. In the R/3 screen, if you want to quit the processing of that particular screen without entering the mandatory fields, user can click the Cancel button. Same functionality can be incorporated in the user-defined transaction by using AT EXIT-COMMAND. This module can be called before the system executes the automatic field checks and it goes without saying that before PAI event. Code for AT EXIT-COMMAND in flow logic and in module pool program can be written as follows:

     

    In Flow Logic

    Process After Input.

    Module exit AT EXIT-COMMAND.

             In module pool program.

    Module exit.

    Case okcode.

    When ‘Exit’.

    Leave to screen 0.

     

    To achieve this kind of functionality a pushbutton or menu item should be assigned a function type ‘E’. It tells the system to process this particular module before carrying out any field checks.

     

    Flow Logic Validations

     

    Consider the case where you want user to enter only ‘LH’ and ‘SQ’ for sflight-carrid. In this case, you are restricting value of a screen field. This cannot be achieved by automatic field check. Hence there is a need of additional validation. It can be done in flow logic by using following statement:

     

    Field -


    Values

     

    Syntax

     

    PAI.

    Field sflight-carrid values (‘LH’).

     

    For multiple values

     

    PAI.

    Field sflight-carrid values (‘LH’ ‘SQ’).

    Field sflight-price values (between 1000 and 2000).

     

    In this case when the user enters the value, PAI is triggered  and field is checked for  that particular value. If the value entered happens to be wrong, that field is enabled for user to enter. If you have multiple Field statements in your flow logic, it is sequential execution.

     

    Consider the following case:

     

    PAI.

    Module  assign.

    Field sflight-carrid values (‘LH’ ‘SQ’).

     

    In ABAP/4

     

    Module  assign.

    Data: carrid1 like sflight-carrid.

    Carrid1 = sflight-carrid.

    Endmodule.

     

    In this case, Sflight-carrid is used in the flow logic before the field statement. The system will give invalid value or some previous value as the field sflight-carrid is used in module before it is checked i.e., field statement is after the module in which sflight-carrid is being used. The field is not available to the system unless it executes the field statement. Field statement transfers the values to the program and is done only once. If you don’t have Field statement in your flow logic, transfer of values takes place in PAI event.

     

    Consider one more case where you have multiple field statement

    PAI.

    Field Sflight-carrid values (‘LH’).

    Field Sflight-connid values (‘0400’ ‘0500’).

    In this case if the user enters only carrid wrong, then this particular field is enabled and rest of the fields are disabled for user to input. Many times if the user enters wrong value for one field, then you might want to give option to user to enter all the fields, which is not possible by using Field statement only. This functionality can be achieved by CHAIN – ENDCHAIN.

     

    Syntax

     

    Chain.

    Field sflight-carrid value (‘LH’).

         Field sflight-connid values (between ‘200’ and ‘500’).

    Endchain.

     

    Field sflight-price values (‘100’ ‘1000’).

     

    In this case, if the user enters wrong value only for carrid, both the fields i.e. carrid and connid are enabled as they are grouped together in the Chain statement. The field price will be disabled for input. Usually, logically related fields are grouped together with Chain-Endchain statement.

     

    Module Pool Program Validations

     

    Checking fields ABAP/4 program includes

     

    •     Field statement in flow logic.

    •     Module statement in ABAP/4 module pool Program.

     

    Syntax

     

    PAI.

    Field sflight-carrid module <name>.

    This module can be handled in the main program i.e. module pool program.

     

    In ABAP/4 program

     

    Module Check.

    Select single * from sflight where carrid = sflight-carrid.

    If sy-subrc ne 0.

         Message e001.

    Endif.

     

    In this case, field sflight-carrid is checked in the table for its existence.

    Dynamically Calling the Screens

     

    About Displaying Next Screen

     

    Transaction is a sequence of screens, which are displayed one after the other. The next screen displayed depends upon the attributes of first screen. In attributes you need to give Next Screen number i.e. if next screen displayed should be 200 screen, then this number should be given in next Screen attributes. These are static attributes of the screen. By default, if nothing is specified in the program, the system branches out to the screen number, which is specified in the attribute screen.

    In this case, if user selects MARA pushbutton, then fields from Mara table are displayed. When the user clicks on the MARD, then the fields from MARD table are displayed. Depending upon users selection, the screen is branched out and this has to be done during runtime. This functionality can be achieved by dynamically calling the screen in module pool program.

     

    The screen can branch out to new screen depending upon user selection. Following command in module pool program can do this:

    •     SET SCREEM

    •     CALL SCREEN

    •     LEAVE TO SCREEN <NUMBER>

     

    All these commands override the specifications given in the attributes. This overriding is temporary. The values stored in the attribute are not changed.

     

    Set Screen

     

    Syntax

     

    Set screen <number>.

     

    In module pool program

     

    Case okcode.

         When  ‘DISP’.

              Set screen 200.

         When ‘LIST’.

              Set screen 300.

    Endcase.

     

    In this case, the entire processing of current screen takes place and then the system branches out to next screen. If you want to branch out to the next screen without processing the current screen, LEAVE SCREEN should be used along with the SET SCREEN.

     

    For Example:

     

    Case okcode..

         When  ‘DISP’.

              Set screen 200.

              Leave Screen.

     

         When ‘LIST’.

              Set screen 300.

              Leave Screen.

    Endcase.

    When SET SCREEN is used, control cannot be transferred to the main screen or previous screen, unless you write code for the same.

     

    Call Screen

     

    Usually used for pop up screens. Many times, there is a need for user to enter additional information or secondary information on another screen or pop up screen. Once the user enters the data, he should be able to go back to main screen or to the screen where he started. This is not possible by using SET SCREEN. CALL SCREEN achieves this functionality.

     

    Syntax

    Call Screen 200.

     

    Will simply call a screen number 200 from a main screen. Once the screen is displayed the user can enter all the data and return to the main screen by clicking BACK button.

     

    To call screen as pop up screen the syntax is

     

    Call screen starting at <col.no.> <line no>

                         Ending at <col no> <line no>.

     

    In this case window will be popped as window and user can close it by using BACK button.

     

    Leave to screen

     

    To SET a new screen without processing current screen, you need to use the following two statements together:

     

    SET SCREEN 200.

    LEAVE SCREEN.

     

    Or a Single statement

     

    LEAVE TO SCREEN 200.

Actions