Module Pool Sap Programming
Module Pool Sap Programming
Steps:
1.
2. Right click the left hand side program name and create new screen 9000.
3.
4. Click on Layout button and create a subscreen area element and name it sub1 as shown
below.
5.
Go back to element list and add 'OK_CODE' in the last empty field.
6. Now go to the flow logic tab and uncomment those lines and the extra line as shown below to
add the sub screen.
7. Now double click the module status and module user command to add in the program
8. Now the program looks like this. Now add the code lines for 901 sub screen as shown below.
9. Double click the zgui_900 to create a GUI status for the 9000 screen
10. Create Execute and variant button in the GUI status as shown below with function code
execute and variant.
11. Create 4 Function keys in GUI as shown below with function code save, back, exit,
cancel.
12. Add the code for the USER_COMMAND of the 9000 screen.
13. Create a new screen 9001 which is to be designed for the variant popup screen.
14. Fill in the screen attributes and select the screen type as modal dialog box.
17. Uncomment the lines in the flow logic of the screen and add the lines as shown below.
18. Double click and add these modules in the main program and then set a pf status ZGUI_9001
for the screen.
21. Below have mentioned the coding to be used for the scenario.
*&---------------------------------------------------------------------*
*& Module Pool
ZD_VARIANT_MODULE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
PROGRAM ZD_VARIANT_MODULE.
TABLES: MARA.
DATA: OK_CODE TYPE SY-UCOMM,
G_VARIANT1 TYPE RSVAR-VARIANT,
G_USER_VARI TYPE RSVAR-VARIANT,
G_VARI_REPORT TYPE RSVAR-REPORT,
G_SEL_VAR TYPE RSVAR-VARIANT,
G_SEL_VARTXT TYPE RSVAR-VTEXT,
G_REPORT TYPE RSVAR-REPORT,
G_VAREXISTS TYPE C.
SELECTION-SCREEN BEGIN OF SCREEN 901 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. "Input
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR. "Material Number
SELECTION-SCREEN SKIP.
PARAMETERS: P_REC TYPE CHAR4 DEFAULT '1000'. "Max. No. of Records
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN END OF SCREEN 901.
SELECTION-SCREEN BEGIN OF SCREEN 902 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_NAME TYPE RSVAR-VARIANT, P_MEAN TYPE RSVAR-VTEXT.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN END OF SCREEN 902.
*&---------------------------------------------------------------------*
*&
Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.
SET PF-STATUS 'ZGUI_9000'.
SET TITLEBAR 'ZTITLE_900'.
ENDMODULE.
" STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.
CLEAR OK_CODE.
OK_CODE = SY-UCOMM.
CASE OK_CODE.
WHEN 'SAVE'.
CLEAR: P_NAME, P_MEAN.
CALL SCREEN 9001 STARTING AT 10 5.
WHEN 'VARIANT'.
PERFORM LOAD_VARIANT.
IF SY-UCOMM EQ 'CANC'.
vari_desc
= varid_tab
TABLES
vari_contents = rsparams_tab
vari_text
= varit_tab
EXCEPTIONS
illegal_report_or_variant = 01
illegal_variantname
= 02
not_authorized
= 03
not_executed
= 04
report_not_existent
= 05
report_not_supplied
= 06
variant_doesnt_exist
= 07
variant_locked
= 08
selections_no_match
= 09.
ELSE.
CALL FUNCTION 'RS_CREATE_VARIANT'
EXPORTING
curr_report = varid_tab-report
curr_variant = varid_tab-variant
vari_desc = varid_tab
TABLES
vari_contents = rsparams_tab
vari_text
= varit_tab
EXCEPTIONS
illegal_report_or_variant = 01
illegal_variantname = 02
not_authorized
= 03
not_executed
= 04
report_not_existent = 05
report_not_supplied = 06
variant_exists
= 07
variant_locked
= 08.
ENDIF.
rc = sy-subrc.
endform.
" SAVE_VARIANT
form LOAD_VARIANT .
PERFORM choose_variant CHANGING g_sel_var.
IF g_sel_var NE space.
CALL FUNCTION 'RS_SUPPORT_SELECTIONS'
EXPORTING
report
=
sy-repid
variant =
g_sel_var
EXCEPTIONS
variant_not_existent = 1
variant_obsolete = 2
OTHERS
= 3.
ENDIF.
endform.
" LOAD_VARIANT
form CHOOSE_VARIANT changing fp_sel_var.
CALL FUNCTION 'RS_VARIANT_CATALOG'
EXPORTING
report
= sy-repid
masked
= 'X'
IMPORTING
sel_variant
= fp_sel_var
sel_variant_text = g_sel_vartxt
EXCEPTIONS
no_report
=1
report_not_existent = 2
report_not_supplied = 3
no_variants
=4
no_variant_selected = 5
variant_not_existent = 6
OTHERS
= 7.
endform.
" CHOOSE_VARIANT