Sunteți pe pagina 1din 19

Creation of Variants in Module Pool Program

By Deepan Ignaatious, Kaavian systems


Scenario: In this example, demonstrates on how to create selection screen variant for module
pool programs. Module programming can be used with Selection Screens and similar to the
report programming, variants can be saved and loaded.
Steps in short:
The steps to create Screen Variants are as follows.

Creation of Module Pool Program with Selection screen


Create a screen for saving the Variants
Load and Display the variant
Create and Execute the Transaction Code

Steps:
1.

Create a Z MODULE POOL program in SE38.

2. Right click the left hand side program name and create new screen 9000.

3.

The attribute screen of the screen 9000 is as shown below.

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.

15. Create a sub screen area named sub2.

16. Add OK_CODE in general attributes of the screen element list.

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.

Add the button OK in the application toolbar

19. Create a transaction and execute the program

20. Selection text used for the program

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'.

MESSAGE 'Variant operation terminated' TYPE 'S' DISPLAY LIKE 'E'.


ELSE.
MESSAGE 'Variant selected' TYPE 'S'.
ENDIF.
CALL SCREEN 9000.
WHEN OTHERS.
LEAVE TO SCREEN 9000.
ENDCASE.
ENDMODULE.
" USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
*&
Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE STATUS_9001 OUTPUT.
SET PF-STATUS 'ZGUI_9001'.
* SET TITLEBAR 'xxx'.
ENDMODULE.
" STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9001 INPUT.
IF NOT P_NAME IS INITIAL.
OK_CODE = 'OK'.
ELSE.
OK_CODE = 'CANCEL'.
ENDIF.
CASE OK_CODE.
WHEN 'OK'.
IF NOT P_NAME IS INITIAL.
PERFORM SAVE_VARIANT.
MESSAGE 'Variant has been saved' TYPE 'S'.
ENDIF.
WHEN 'CANCEL'.
MESSAGE '"Variant Not saved.' TYPE 'S' DISPLAY LIKE 'E'.
ENDCASE.
CALL SCREEN 9000.
ENDMODULE.
" USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
*& Form SAVE_VARIANT
*&---------------------------------------------------------------------*
* Routine to Save the variant
*----------------------------------------------------------------------*
form SAVE_VARIANT .
DATA: BEGIN OF rsparams_tab OCCURS 10.
INCLUDE STRUCTURE rsparams.
DATA: END OF rsparams_tab.
DATA: BEGIN OF varid_tab.
INCLUDE STRUCTURE varid.
DATA: END OF varid_tab.
DATA: BEGIN OF varit_tab OCCURS 2.
INCLUDE STRUCTURE varit.

DATA: END OF varit_tab.


DATA: rc TYPE syst-subrc.
* Tabellen initialisieren
CLEAR: varid_tab.
REFRESH varit_tab.
REFRESH rsparams_tab.
*fill VARID structure - variant description
varid_tab-report = 'ZD_VARIANT_MODULE'.
varid_tab-variant = p_name.
varid_tab-environmnt = 'A'.
varit_tab-mandt = sy-mandt.
varit_tab-langu = sy-langu.
varit_tab-report = varid_tab-report.
varit_tab-variant = varid_tab-variant.
varit_tab-vtext = p_mean.
APPEND varit_tab.
*fill RSPARAMS structure - Selektionswerte; variant contents
LOOP AT s_matnr.
rsparams_tab-selname = 'S_MATNR'.
rsparams_tab-kind = 'S'.
rsparams_tab-sign = s_matnr-sign.
rsparams_tab-option = s_matnr-option.
rsparams_tab-low = s_matnr-low.
rsparams_tab-high = s_matnr-high.
APPEND rsparams_tab.
ENDLOOP.
rsparams_tab-selname = 'P_REC'.
rsparams_tab-kind = 'P'.
rsparams_tab-sign = 'I'.
rsparams_tab-option = 'EQ'.
rsparams_tab-low = p_rec.
rsparams_tab-high = ' '.
APPEND rsparams_tab.
*Check variant
CALL FUNCTION 'RS_VARIANT_EXISTS'
EXPORTING
report = varid_tab-report
variant = varid_tab-variant
IMPORTING
r_c = rc
EXCEPTIONS
not_authorized = 01
no_report = 02
report_not_existent = 03
report_not_supplied = 04.
IF sy-subrc <> 0.
MESSAGE e001(VL) WITH text-e22 DISPLAY LIKE 'S'.
ENDIF.
IF rc = 0.
" Variante existiert
CALL FUNCTION 'RS_CHANGE_CREATED_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_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

S-ar putea să vă placă și