ABSTRACT
This article propose alternative solution for default values to transaction variant SHD0 or parameter id.
The idea is to provide to the business consultant which are not familiar with GuiXT the option the enjoy its functionality and save time for their customers.
for that ABAP Z function module was developed which activates the GuiXT and also creates in the background the GuiXT Scripts and automatically and store it in the %temp%\GuiXT folder, the function can be triggeredfrom any BAdi /user exit/enhancement in code area which is triggered before the requires default values screen is displayed.
GuiXT activation :
GuiXT is activation is handled automatically by the function module at first time the user enter the customized screen, it writes directly to windows registry the required entries , this is checked every time the FM is called - if GuiXT is not activated then pop message will be displayed asking to logoff and log on again ,the FM creates Reg file in the%temp%which contain the GuiXT required registry settings and bat file which to run the reg file , The Class CL_GUI_FRONTEND_SERVICES execute the bat file .
Script generation in ABAP at user exits/enhancement:
GuiXT scripts are generated automatically by this function module which uses methods from class CL_GUI_FRONTEND_SERVICES to create the GuiXT scripts and store it at the%temp%\GuiXTfolder.
When the FM is called ?
The FM can be called from several code areas before the GuiXT customized screens will be displayed, it can be done by any User Exits/ BAdi's /Enhancement implicit which preferbly contain the required buffer data in order define different default values per type . for Exemple : for notification type M1 we can use different values from notification type M2 .
Scripts deployments:
All GuiXT code is part of the ABAP code which write the GuiXT syntax ,GuiXT scripts are generated automatically and stored in %temp%/GuiXTlocal folder
New script are re-downloaded only if the FM is called with new version parameter or new object type will be created
Pre condition
SAP GUI for window , SAP GUIsecurity pop ups are disabled (handled also by the FM).
For transaction with multi tabs or screen - the default values are populated only when the relevant tab / screen is accessed
For which transaction this solution can be used?
Any transaction with initial screen before the customized screen.
Implementation Steps
Step 1 : Define the Function Module Z_GUIXT_DEFAULT _VALUES (attached)
Step 2 : Find appropriate User exit / BADi , enhancement which is triggered before the required screen is displayed at enter in the required screen.
Step 3 : Call Function Z_GUIXT_DEFAULT _VALUES with the default files ,make sure the change the version number after every change.
Step 4: In the first time the user enters the required customized screen pop up message instruct to logoff and logon again so that this solution will be activated .
Exemples : from previoues threads in the EAM forum which can use the proposed solution
Exemple 1 :IW21 - How to populate Functional Location/Equipment by default for specific Notification type ?)
We use here user exit QQMA025
*&---------------------------------------------------------------------* *& Include ZXWOCU21 *&---------------------------------------------------------------------* DATA: lt_data TYPE STANDARD TABLE OF string , ls_data LIKE LINE OF lt_data , ls_includename type string , lv_change_flg type xfeld. CONCATENATE 'include ' ' NOTIF_TYPE_' '&F[VIQMEL-QMART]' '.txt' into ls_includename. append ls_includename to lt_data . CALL FUNCTION 'Z_GUIXT_SCRIPT_GENERATE' EXPORTING activate = 'X' version = '004' program = 'sapliqs0' screen = '7200' IMPORTING change_flg = lv_change_flg TABLES script_tab = lt_data . check lv_change_flg = 'X' . ""if not change no neeed to generate again the other includes clear :ls_data , lt_data ,ls_includename . ls_data = 'default F[RIWO1-TPLNR] K1-B1-2'. append ls_data to lt_data . ls_includename = 'NOTIF_TYPE_M1'. CALL FUNCTION 'Z_GUIXT_SCRIPT_GENERATE' EXPORTING include = ls_includename TABLES script_tab = lt_data . clear :ls_data , lt_data ,ls_includename . ls_data = 'default F[RIWO1-TPLNR] K1-B'. append ls_data to lt_data . ls_includename = 'NOTIF_TYPE_M2'. CALL FUNCTION 'Z_GUIXT_SCRIPT_GENERATE' EXPORTING include = ls_includename TABLES script_tab = lt_data . clear :ls_data , lt_data ,ls_includename . ls_data = 'default F[RIWO1-TPLNR] K1'. append ls_data to lt_data . ls_includename = 'NOTIF_TYPE_M3'. CALL FUNCTION 'Z_GUIXT_SCRIPT_GENERATE' EXPORTING include = ls_includename TABLES script_tab = lt_data .
Exemple 2 : default values for task list : Using Enhencmenet implicit to Call the FM
Fill fields in the task list by default
FORM plan_records_valid_det. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Form PLAN_RECORDS_VALID_DET, Start A *$*$-Start: (1)---------------------------------------------------------------------------------$*$* ENHANCEMENT 1 Z_GUIXT_DEFAULT. "active version DATA: lt_data TYPE STANDARD TABLE OF string. DATA: ls_data LIKE LINE OF lt_data . if sy-UNAME = 'EHP7USER373'. ls_data = 'default F[PLKOD-WERKS] 2000'. append ls_data to lt_data . ls_data = 'default F[PLKOD-VERWE] 4'. append ls_data to lt_data . ls_data = 'default F[PLKOD-STATU] 4'. append ls_data to lt_data . CALL FUNCTION 'Z_GUIXT_SCRIPT_GENERATE' EXPORTING activate = 'X' version = '001' program = 'saplcpda' screen = '3010' TABLES script_tab = lt_data .Exemple 3 : default values for PM order
Exit: Default values when adding a Work order
*&---------------------------------------------------------------------* *& Include ZXWOCU04 *&---------------------------------------------------------------------* DATA: lt_data TYPE STANDARD TABLE OF string , ls_data LIKE LINE OF lt_data , ls_includename type string , lv_change_flg type xfeld. CONCATENATE 'include ' ' ORDER_TYPE_' '&F[CAUFVD-AUART]' '.txt' into ls_includename. append ls_includename to lt_data . CALL FUNCTION 'Z_GUIXT_SCRIPT_GENERATE' EXPORTING activate = 'X' version = '001' program = 'SAPLCOIH' screen = '3000' IMPORTING change_flg = lv_change_flg TABLES script_tab = lt_data . check lv_change_flg = 'X' . ""if not change no neeed to generate again the other includes clear :ls_data , lt_data ,ls_includename . ls_data = 'default F[CAUFVD-VAPLZ] 1330'. append ls_data to lt_data . ls_includename = 'ORDER_TYPE_PM01'. CALL FUNCTION 'Z_GUIXT_SCRIPT_GENERATE' EXPORTING include = ls_includename TABLES script_tab = lt_data . clear :ls_data , lt_data ,ls_includename . ls_data = 'default F[CAUFVD-VAPLZ] 1000'. append ls_data to lt_data . ls_includename = 'ORDER_TYPE_PM02'. CALL FUNCTION 'Z_GUIXT_SCRIPT_GENERATE' EXPORTING include = ls_includename TABLES script_tab = lt_data .
FUNCTION Z_GUIXT_SCRIPT_GENERATE. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" REFERENCE(ACTIVATE) TYPE XFELD OPTIONAL *" REFERENCE(TCODE) TYPE TCODE OPTIONAL *" REFERENCE(VERSION) TYPE CHAR4 OPTIONAL *" REFERENCE(PROGRAM) TYPE BDC_PROG OPTIONAL *" REFERENCE(SCREEN) TYPE BDC_DYNR OPTIONAL *" REFERENCE(INITIAL_PROGRAM) TYPE BDC_PROG OPTIONAL *" REFERENCE(INITIAL_SCREEN) TYPE BDC_DYNR OPTIONAL *" REFERENCE(INCLUDE) OPTIONAL *" EXPORTING *" REFERENCE(CHANGE_FLG) TYPE XFELD *" TABLES *" DATA_TAB STRUCTURE BDCDATA OPTIONAL *" SCRIPT_TAB OPTIONAL *"---------------------------------------------------------------------- Include OLE2INCL. Constants :lc_reg_key TYPE string VALUE 'Software\SAP\SAPGUI Front\SAP Frontend server\Customize' , lc_value_name TYPE string VALUE 'GuiXT.Directory1' , lc_value TYPE string VALUE 'C:\temp' , lc_reg type string VALUE '.Reg', lc_guixt TYPE string VALUE 'GuiXT' , lc_filename TYPE string VALUE '\Security.Reg' , lc_txt TYPE string VALUE 'txt' , lc_value_active TYPE string VALUE '1' , lc_active TYPE string VALUE '1' , lc_batfile type string VALUE 'REGEDIT.EXE /S "', lc_root TYPE i VALUE '1' , lv_dot TYPE string VALUE '.' , lv_slh TYPE string VALUE '\' . data : lc_reg_curr_value TYPE string , lv_answer TYPE ehsbe_logpopupanswer, lo_reg type ole2_object , lv_rc type i , lv_active_val TYPE string, lv_bat type string, lv_filename type string , lv_regfilename type string, lt_data TYPE STANDARD TABLE OF string, lt_lines TYPE STANDARD TABLE OF string, ls_data LIKE LINE OF lt_data , lv_guixt_path type string , lv_guixt_script_name type string, lv_guixt_script_name_path type string, lv_initial_screen type string, lv_initial_program type string, lv_win type string, lv_hkey type string, lv_defult type string, lv_security type string , lv_clear_flag type xfeld, lv_current_version type string , lv_tmp TYPE string , lv_last_file_first_line like line of lt_data, lv_first_line like line of lt_data, lv_file_exists type ABAP_BOOL, rc type i. call method CL_GUI_FRONTEND_SERVICES=>ENVIRONMENT_GET_VARIABLE exporting VARIABLE = 'TEMP' changing VALUE = lv_tmp exceptions CNTL_ERROR = 1 others = 2. call method CL_GUI_CFW=>FLUSH exceptions CNTL_SYSTEM_ERROR = 1 CNTL_ERROR = 2. lv_win = 'Windows Registry Editor Version 5.00'. lv_hkey = '[HKEY_CURRENT_USER\Software\SAP\SAPGUI Front\SAP Frontend Server\Security]'. lv_security = '"SecurityLevel"=dword:00000000'. ls_data = lv_win. append ls_data to lt_data . ls_data = lv_hkey. append ls_data to lt_data . ls_data = lv_security. append ls_data to lt_data . ls_data = '"DefaultAction"=dword:00000000'. append ls_data to lt_data . ls_data = '[HKEY_CURRENT_USER\Software\SAP\SAPGUI Front\SAP Frontend Server\Customize] '. append ls_data to lt_data . ls_data = '"GuiXT.ComponentGuiXT"=dword:00000001 '. append ls_data to lt_data . ls_data = '"GuiXT"=dword:00000001'. append ls_data to lt_data . ls_data = '"GuiXT.ComponentInputAssistant"=dword:00000000'. append ls_data to lt_data . ls_data = '"GuiXT.ComponentViewer"=dword:00000000'. append ls_data to lt_data . ls_data = '"GuiXT.ComponentControls"=dword:00000000'. append ls_data to lt_data . ls_data = '"GuiXT.ComponentDesigner"=dword:00000000'. append ls_data to lt_data . ls_data = '"GuiXT.StartHidden"=dword:00000001'. append ls_data to lt_data . ls_data = '"GuiXT.NoLanguageKey"=dword:00000001'. append ls_data to lt_data . CONCATENATE lv_tmp lv_slh lc_guixt into lv_guixt_path. " t1. REPLACE ALL OCCURRENCES OF '\' IN lv_guixt_path WITH '\\'. CONCATENATE '"GuiXT.Directory1"="' lv_guixt_path '"' into lv_guixt_path. append lv_guixt_path to lt_data . CONCATENATE lv_tmp lc_filename INTO lv_regfilename. *check if the bat file exist call METHOD cl_gui_frontend_services=>file_exist EXPORTING file = lv_regfilename RECEIVING result = lv_file_exists EXCEPTIONS cntl_error = 1 error_no_gui = 2 wrong_parameter = 3 not_supported_by_gui = 4 OTHERS = 5. call method CL_GUI_CFW=>FLUSH exceptions CNTL_SYSTEM_ERROR = 1. if activate = 'X' . if lv_file_exists NE 'X'. Call Function 'POPUP_TO_INFORM' Exporting TITEL = 'User interface extensions activated' TXT1 = 'Please approve accsees popups logoff and logon again' TXT2 = '-- Thank you ---'. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING filename = lv_regfilename * filetype = 'ASC' CHANGING data_tab = lt_data[] EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 not_supported_by_gui = 22 error_no_gui = 23 OTHERS = 24. call method CL_GUI_CFW=>FLUSH exceptions CNTL_SYSTEM_ERROR = 1. CONCATENATE lc_batfile lv_regfilename '"' into lv_bat. CLEAR lt_data . append lv_bat to lt_data . CONCATENATE lv_tmp '\reg.bat' INTO lv_bat. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING filename = lv_bat * filetype = 'ASC' CHANGING data_tab = lt_data[] EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 not_supported_by_gui = 22 error_no_gui = 23 OTHERS = 24. call method CL_GUI_CFW=>FLUSH exceptions CNTL_SYSTEM_ERROR = 1. * Run the Bat File CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE EXPORTING DOCUMENT = lv_bat. exit. endif. endif. "activate if version is not initial . CONCATENATE '//' version into lv_current_version. endif. clear : ls_data , lt_data ,change_flg. if script_tab[] is not initial . concatenate '//' version INTO ls_data. append ls_data to lt_data . append lines of script_tab[] TO lt_data[]. endif. if program is not initial and screen is not initial. concatenate program lv_dot screen lv_dot lc_txt into lv_guixt_script_name. " concatenate lv_tmp lv_slh lc_guixt lv_slh lv_guixt_script_name into lv_guixt_script_name_path. " endif. if include is not initial . concatenate include lv_dot lc_txt into lv_guixt_script_name. " concatenate lv_tmp lv_slh lc_guixt lv_slh lv_guixt_script_name into lv_guixt_script_name_path. " endif. *check the value in : Directory 1 CALL METHOD CL_GUI_FRONTEND_SERVICES=>registry_get_value EXPORTING root = lc_root key = lc_reg_key value = lc_value_name IMPORTING reg_value = lc_reg_curr_value . * Connect to desktop object Create Object lo_reg 'SAPINFO'. * Read registry - Guixt Is activated ? Call Method OF lo_reg 'GetRegDWValueEx' = lv_active_val Exporting #1 = lc_root #2 = 'SOFTWARE\SAP\SAPGUI FRONT\SAP FRONTEND SERVER\CUSTOMIZE' #3 = 'GuiXT'. clear lv_guixt_path. CONCATENATE lv_tmp lv_slh lc_guixt into lv_guixt_path. if include is initial . if lc_reg_curr_value <> lv_guixt_path or lv_active_val <> lc_active. Call Function 'POPUP_TO_INFORM' Exporting TITEL = 'User interface extensions activated' TXT1 = 'Please logoff and logon again' TXT2 = '-- Thank you ---'. ** set registry : GuiXT Active Call Method OF lo_reg 'SetRegDWValueEx' Exporting #1 = lc_root #2 = 'SOFTWARE\SAP\SAPGUI FRONT\SAP FRONTEND SERVER\CUSTOMIZE' #3 = 'GuiXT' #4 = 1. ** set directory 1 value CALL METHOD CL_GUI_FRONTEND_SERVICES=>registry_set_value EXPORTING root = lc_root key = lc_reg_key value_name = lc_value_name value = lv_guixt_path IMPORTING rc = lv_rc . call method CL_GUI_CFW=>FLUSH exceptions CNTL_SYSTEM_ERROR = 1 CNTL_ERROR = 2. exit. endif. **"---------------------------------------------------------------------- * read version - check if change call method cl_gui_frontend_services=>gui_upload exporting filename = lv_guixt_script_name_path read_by_line = 'X' changing data_tab = lt_lines exceptions file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 not_supported_by_gui = 17 error_no_gui = 18 others = 19. call method CL_GUI_CFW=>FLUSH exceptions CNTL_SYSTEM_ERROR = 1 CNTL_ERROR = 2. * *"---------------------------------------------------------------------- read table lt_lines[] into lv_last_file_first_line index 1. "version check is relevenat only the first screen if lv_last_file_first_line is not initial. check lv_last_file_first_line ne lv_current_version . endif. endif. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING filename = lv_guixt_script_name_path * filetype = 'ASC' CHANGING data_tab = lt_data[] EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 not_supported_by_gui = 22 error_no_gui = 23 OTHERS = 24. call method CL_GUI_CFW=>FLUSH exceptions CNTL_SYSTEM_ERROR = 1. change_flg = 'X'. ENDFUNCTION.
Regards,
Ziv