module pool sap programming

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

description

module pool sap programming

Transcript of module pool sap programming

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

*&---------------------------------------------------------------------**&ModulePoolZD_VARIANT_MODULE*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*PROGRAMZD_VARIANT_MODULE.TABLES:MARA.DATA:OK_CODETYPESY-UCOMM,G_VARIANT1TYPERSVAR-VARIANT,G_USER_VARITYPERSVAR-VARIANT,G_VARI_REPORTTYPERSVAR-REPORT,G_SEL_VARTYPERSVAR-VARIANT,G_SEL_VARTXTTYPERSVAR-VTEXT,G_REPORTTYPERSVAR-REPORT,G_VAREXISTSTYPEC.SELECTION-SCREENBEGINOFSCREEN901ASSUBSCREEN.SELECTION-SCREENBEGINOFBLOCKB1WITHFRAMETITLETEXT-001."InputSELECT-OPTIONS:S_MATNRFORMARA-MATNR."MaterialNumberSELECTION-SCREENSKIP.PARAMETERS:P_RECTYPECHAR4DEFAULT'1000'."Max.No.ofRecordsSELECTION-SCREENENDOFBLOCKB1.SELECTION-SCREENENDOFSCREEN901.SELECTION-SCREENBEGINOFSCREEN902ASSUBSCREEN.SELECTION-SCREENBEGINOFBLOCKB2WITHFRAMETITLETEXT-001.PARAMETERS:P_NAMETYPERSVAR-VARIANT,P_MEANTYPERSVAR-VTEXT.SELECTION-SCREENENDOFBLOCKB2.SELECTION-SCREENENDOFSCREEN902.*&---------------------------------------------------------------------**&ModuleSTATUS_9000OUTPUT*&---------------------------------------------------------------------**text*----------------------------------------------------------------------*MODULESTATUS_9000OUTPUT.SETPF-STATUS'ZGUI_9000'.SETTITLEBAR'ZTITLE_900'.ENDMODULE."STATUS_9000OUTPUT*&---------------------------------------------------------------------**&ModuleUSER_COMMAND_9000INPUT*&---------------------------------------------------------------------**text*----------------------------------------------------------------------*MODULEUSER_COMMAND_9000INPUT.CLEAROK_CODE.OK_CODE=SY-UCOMM.CASEOK_CODE.WHEN'SAVE'.CLEAR:P_NAME,P_MEAN.CALLSCREEN9001STARTINGAT105.WHEN'VARIANT'.PERFORMLOAD_VARIANT.IFSY-UCOMMEQ'CANC'.MESSAGE'Variantoperationterminated'TYPE'S'DISPLAYLIKE'E'.ELSE.MESSAGE'Variantselected'TYPE'S'.ENDIF.CALLSCREEN9000.WHENOTHERS.LEAVETOSCREEN9000.ENDCASE.ENDMODULE."USER_COMMAND_9000INPUT*&---------------------------------------------------------------------**&ModuleSTATUS_9001OUTPUT*&---------------------------------------------------------------------**text*----------------------------------------------------------------------*MODULESTATUS_9001OUTPUT.SETPF-STATUS'ZGUI_9001'.*SETTITLEBAR'xxx'.ENDMODULE."STATUS_9001OUTPUT*&---------------------------------------------------------------------**&ModuleUSER_COMMAND_9001INPUT*&---------------------------------------------------------------------**text*----------------------------------------------------------------------*MODULEUSER_COMMAND_9001INPUT.IFNOTP_NAMEISINITIAL.OK_CODE='OK'.ELSE.OK_CODE='CANCEL'.ENDIF.CASEOK_CODE.WHEN'OK'.IFNOTP_NAMEISINITIAL.PERFORMSAVE_VARIANT.MESSAGE'Varianthasbeensaved'TYPE'S'.ENDIF.WHEN'CANCEL'.MESSAGE'"VariantNotsaved.'TYPE'S'DISPLAYLIKE'E'.ENDCASE.CALLSCREEN9000.ENDMODULE."USER_COMMAND_9001INPUT*&---------------------------------------------------------------------**&FormSAVE_VARIANT*&---------------------------------------------------------------------**RoutinetoSavethevariant*----------------------------------------------------------------------*formSAVE_VARIANT.DATA:BEGINOFrsparams_tabOCCURS10.INCLUDESTRUCTURErsparams.DATA:ENDOFrsparams_tab.DATA:BEGINOFvarid_tab.INCLUDESTRUCTUREvarid.DATA:ENDOFvarid_tab.DATA:BEGINOFvarit_tabOCCURS2.INCLUDESTRUCTUREvarit.DATA:ENDOFvarit_tab.DATA:rcTYPEsyst-subrc.*TabelleninitialisierenCLEAR:varid_tab.REFRESHvarit_tab.REFRESHrsparams_tab.*fillVARIDstructure-variantdescriptionvarid_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.APPENDvarit_tab.*fillRSPARAMSstructure-Selektionswerte;variantcontentsLOOPATs_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.APPENDrsparams_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=''.APPENDrsparams_tab.*CheckvariantCALLFUNCTION'RS_VARIANT_EXISTS'EXPORTINGreport=varid_tab-reportvariant=varid_tab-variantIMPORTINGr_c=rcEXCEPTIONSnot_authorized=01no_report=02report_not_existent=03report_not_supplied=04.IFsy-subrc0.MESSAGEe001(VL)WITHtext-e22DISPLAYLIKE'S'.ENDIF.IFrc=0."VarianteexistiertCALLFUNCTION'RS_CHANGE_CREATED_VARIANT'EXPORTINGcurr_report=varid_tab-reportcurr_variant=varid_tab-variantvari_desc=varid_tabTABLESvari_contents=rsparams_tabvari_text=varit_tabEXCEPTIONSillegal_report_or_variant=01illegal_variantname=02not_authorized=03not_executed=04report_not_existent=05report_not_supplied=06variant_doesnt_exist=07variant_locked=08selections_no_match=09.ELSE.CALLFUNCTION'RS_CREATE_VARIANT'EXPORTINGcurr_report=varid_tab-reportcurr_variant=varid_tab-variantvari_desc=varid_tabTABLESvari_contents=rsparams_tabvari_text=varit_tabEXCEPTIONSillegal_report_or_variant=01illegal_variantname=02not_authorized=03not_executed=04report_not_existent=05report_not_supplied=06variant_exists=07variant_locked=08.ENDIF.rc=sy-subrc.endform."SAVE_VARIANTformLOAD_VARIANT.PERFORMchoose_variantCHANGINGg_sel_var.IFg_sel_varNEspace.CALLFUNCTION'RS_SUPPORT_SELECTIONS'EXPORTINGreport=sy-repidvariant=g_sel_varEXCEPTIONSvariant_not_existent=1variant_obsolete=2OTHERS=3.ENDIF.endform."LOAD_VARIANTformCHOOSE_VARIANTchangingfp_sel_var.CALLFUNCTION'RS_VARIANT_CATALOG'EXPORTINGreport=sy-repidmasked='X'IMPORTINGsel_variant=fp_sel_varsel_variant_text=g_sel_vartxtEXCEPTIONSno_report=1report_not_existent=2report_not_supplied=3no_variants=4no_variant_selected=5variant_not_existent=6OTHERS=7.endform."CHOOSE_VARIANT