Select Option in Module Pool Program

In report programming system automatically build screen controls based on selection screen definition. In theory, all elements of selection screen can be built in module pool screen but it would require astronomical level of effort specially to mimic select options. Incidentally, there is an easy way to achieve this.

Idea is based on the fact that you can define selection screen as subscreen and this can be loaded on subscreen area defined in module pool program.

Step 1. Create a report ZPWSELSCREEN. You can also create module pool program but I am working with report and I will call a screen in report. Copy following code in report.

REPORT  zpwselscreen.

DATA : workarea TYPE mara ,
       itab     TYPE TABLE OF mara .

SELECTION-SCREEN BEGIN OF SCREEN 9000 AS SUBSCREEN .
SELECT-OPTIONS : s_matnr FOR workarea-matnr ,
                 s_matkl FOR workarea-matkl .
SELECTION-SCREEN END OF SCREEN 9000.

CALL SCREEN 100 .

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'PF01'.
  SET TITLEBAR 'TIT01'.
ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK' OR 'CANC' OR 'EXIT' .
      LEAVE TO SCREEN 0 .
    WHEN 'OK'.                   "OK

    WHEN OTHERS.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

Step 2. Create screen 100 and place a subscreen area SUBSCR on it.

module pool sap select option selection screen

Step 3. In flow logic copy following code. Apart from normal PBO and PAI module we are loading subscreen 9000 defined in report to subscreen area SUBSCR in PBO and then copy values back from screen controls to report variables with CALL SUBSCREEN subscr.


*--------------------------------------------------------------------*
* Process Before Output
*--------------------------------------------------------------------*
PROCESS BEFORE OUTPUT.

  CALL SUBSCREEN subscr INCLUDING sy-repid '9000'.

  MODULE status_0100.

*--------------------------------------------------------------------*
* Process After Input
*--------------------------------------------------------------------*
PROCESS AFTER INPUT.
  CALL SUBSCREEN subscr.
  MODULE user_command_0100.

Step 4. Define normal PF Status PF01 as shown in screen shot below with codes OK, BACK, EXIT and CANC.

module pool sap select option selection screen

Step 5. Define title bar TIT01

module pool sap select option selection screen

Activate all objects and execute report. You should have selection screen with select option on module pool screen 100.

module pool sap select option selection screen

6 Replies to “Select Option in Module Pool Program

  1. Hello Guy,

    I have an issue with this implémentation, i can not use serach help on the screen ( exemple on material number )
    Can you help me ?

    With regards,

    Jack

    1. Hi,

      Search help assigned to field should appear on screen where user press F4 button. Any values entered through search should be accessible in field S_MATNR.

      Can you give specifics of problem you are facing?

  2. My Question is how reduce the gap between label and input field of select option, can you provide an example?

  3. Thank you! I didn’t understand two moments.
    1. Did you create subscreen 9000 using se51 with painter? Or was it created dynamically after declaration in report?
    2. Trying to run this, I got an error “Window expected after AS. Why isn’t subscreen expected?

Leave a Reply