Modal Dialog BOX

In the following example we are creating a module pool program where a Modal dialog box will be implemented. There is a selection screen with select option for creation date of materials. There are radio buttons of Raw materials and finished good materials. We can enter date range here and select the material type radio button and click on the display button. Now it will open a pop up screen where a table control will display the required list of materials.

1)      At first we created the module pool program. Four includes will be there as follows.

   INCLUDE zsr_top                                 .  " global Data
INCLUDE zsr_o01                                 .  " PBO-Modules
INCLUDE zsr_i01                                 .  " PAI-Modules
INCLUDE zsr_f01                                 .  " FORM-Routines

2)      Create the top include where all data & table declarations are there.

   PROGRAM sapmzsr_test.

TABLES: mara.
DATA: ok_9000 TYPE sy-ucomm,
      ok_9001 TYPE sy-ucomm,
      roh     TYPE VALUE 'X',
      fert    TYPE c.

TYPES: BEGIN OF ty_mara,
         matnr TYPE mara-matnr,
         ersda TYPE mara-ersda,
         ernam TYPE mara-ernam,
         mtart TYPE mara-mtart,
         matkl TYPE mara-matkl,
         meins TYPE mara-meins,
       END OF ty_mara.
DATA: wa_mara TYPE ty_mara,
      it_mara TYPE TABLE OF ty_mara.

SELECT-OPTIONS s_date FOR mara-ersda.


3)      Now create the screens where the modal dialog box will be selected. Since we are implementing select option, a default 100 number of screen will be created. Hence there will be three screens: sub screen for select option, calling screen 9000 and modal dialog box 9001.

  MODULE status_9000.
  CALL SUBSCREEN sel INCLUDING sy-repid '100'.

  MODULE user_command_9000.

  MODULE status_9001.

  LOOP AT it_mara INTO wa_mara WITH CONTROL tabc.
    MODULE tabc_modal.

  LOOP AT it_mara.
    MODULE tabc_modify_modal.

  MODULE user_command_9001.

4)      Now create the GUI status of 9000 and then call the sub screen for select option @ PBO.

   MODULE status_9000 OUTPUT.
  SET PF-STATUS 'PF_9000'.
*  SET TITLEBAR 'T_9000'.

5)      Then create the PAI logic for 9000 screen. Write the logic of the Display button to display material list.

   MODULE user_command_9000 INPUT.

  CASE ok_9000.
    WHEN 'BACK'.
    WHEN 'DISP'.
      PERFORM display_materials.



   FORM display_materials .

  DATA: lv_mtart TYPE mara-mtart.

  IF roh = 'X'.
    lv_mtart = 'ROH'.
    lv_mtart = 'FERT'.

  SELECT matnr ersda ernam mtart matkl meins
    FROM mara INTO TABLE it_mara
    WHERE ersda IN s_date
      AND mtart = lv_mtart.

  IF sy-subrc = 0.
    SORT it_mara BY ersda.
    CALL SCREEN 9001
    ENDING AT   95 18.


6)      Here we shall mention the modal dialog screen starting and ending co-ordinate. This co-ordinate is mandatory to display the modal dialog box.

                CALL SCREEN 9001
    ENDING AT   95 18.

7)      Now write the PBO modules of modal dialog. There is no need to create GUI status (if you want then you can) separately. Since we are using table control here, loop with control for ITAB. The same pattern will be used as we use to create table control. Similarly to modify the table we create PAI module over there. In screen you can disable the input option in table control as usual.

   MODULE tabc_modal OUTPUT.

  DESCRIBE TABLE it_mara LINES sy-dbcnt.
  tabc-current_line  = sy-loopc.
  tabc-lines         = sy-dbcnt.

  mara-matnr = wa_mara-matnr.
  mara-ersda = wa_mara-ersda.
  mara-ernam = wa_mara-ernam.
  mara-mtart = wa_mara-mtart.
  mara-matkl = wa_mara-matkl.
  mara-meins = wa_mara-meins.
  CLEAR: wa_mara.


   MODULE tabc_modify_modal INPUT.

  READ TABLE it_mara INTO wa_mara INDEX tabc-current_line.
  IF sy-subrc = 0.
    MODIFY it_mara FROM wa_mara INDEX tabc-current_line.


8)      Now create the PAI user command code as follows.

   MODULE user_command_9001 INPUT.

  CASE ok_9001.
      CLEAR ok_9001.


9)      Finally create the transaction code to execute this program.

 Enter T-code.

Click on the Display button. Then the following pop up screen will open which contains the list of Raw materials.

Now click on the close button and it will be back to the previous screen. Select the finished good button and then Display.

The following pop up screen will come which contains the list of finished good materials.