* _______ _______ _______ _______ _______ _______ ______ _______ _______ ______ _______ * | _ | _ | _ | | | _ | || _ | _ | _ | | _ | * | |_| | |_| | |_| | _ | | |_| | _ | |_| | |_| | | || | |_| | * | | | | |_| | | | | | | | | |_||_| | * | | _ || | ___| _| | |_| | | _ || __ | | * | _ | |_| | _ | | | |_| _ | | _ | |_| | | | | _ | * |__| |__|_______|__| |__|___| |_______|__| |__|______||__| |__|_______|___| |_|__| |__| * www.abapcadabra.com * *------------------------------------------------------------------------------------------- * program : ZABAPCADABRA_PERSONAL_F4_LISTS * title : Copy the F4 personal values list on a search help to other users * functional area : Cross modules * environment : 4.7 * program Function : Search helps can work with a personal values list which limits the * number of entries that are shown in the search help results of the * end used. With this report, the settings of a given user (example * user) can be copied into the settings of a list of (up to 20) users. * This can be very usefull if e.g. old values should be suppressed or * if the values-list of a department should be aligned. Can also * be scheduled. * Documentation : Search for "Personal value list" on AbapcadabrA.com * Previous version : This is the initial version * Developer name : Wim Maasdam * Development date : 29/06/2015 * Version : 0.1 *--------------------------------------------------------------------- * Change list: * Date Description * 29/06/2015 Initial release *--------------------------------------------------------------------- REPORT ZABAPCADABRA_PERSONAL_F4_LISTS. tables: sscrfields, syst. *--------------------------------------------------------------------- * C L A S S D E F I N I T I O N *--------------------------------------------------------------------- CLASS lcl_personal_pref DEFINITION. PUBLIC SECTION. types: begin of ty_target, username type DDSHPVAL50-username, end of ty_target. class-data: gv_source type sy-uname, gv_SHLPNAME type DD30T-SHLPNAME, gr_targets type range of sy-uname, gt_targets type STANDARD TABLE OF ty_target. class-methods: f4_search_help importing uname type sy-uname, select_targets, clear_settings importing direct_call type boolean default abap_true, copy_settings. ENDCLASS. CLASS lcl_personal_pref IMPLEMENTATION. method f4_search_help. data: lt_DDSHPVAL50 type standard table of DDSHPVAL50, lw_DDSHPVAL50 type DDSHPVAL50, lw_DD30T type DD30T, lt_DD30T type STANDARD TABLE OF DD30T. clear: lt_DDSHPVAL50[]. * Compose a list of search helps objects, for which the user * has personal preference settings available select * from DDSHPVAL50 into table lt_DDSHPVAL50 where username = uname. if lt_DDSHPVAL50[] is initial. message 'No personal preference settings found - create first' type 'S'. exit. endif. sort lt_DDSHPVAL50. DELETE ADJACENT DUPLICATES FROM lt_DDSHPVAL50 COMPARING pvalkey. clear: lt_DD30T[]. loop at lt_DDSHPVAL50 into lw_DDSHPVAL50. select * from DD30T into lw_DD30T up to 1 rows where SHLPNAME = lw_DDSHPVAL50-pvalkey and DDLANGUAGE = sy-langu. endselect. if sy-subrc = 0. append lw_DD30T to lt_DD30T. endif. endloop. CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING ddic_structure = 'DD30T' retfield = 'SHLPNAME' dynpprog = SY-REPID dynpnr = '1000' dynprofield = 'X' value_org = 'S' TABLES value_tab = lt_DD30T. endmethod. method select_targets. data: lv_linecount type sy-tabix. clear gt_targets[]. * Compose a list of actual users, from the gr_targets range. select bname from usr01 into table gt_targets where bname in gr_targets. * A maximum number of target users is set to 20, just to ensure * no system-wide updates can de done describe table gt_targets lines lv_linecount. if lv_linecount > 20. message 'Only 20 individual targets supported' type 'E'. endif. * Check whether source is also in targets read table gt_targets with key username = gv_source TRANSPORTING NO FIELDS. if sy-subrc = 0. message 'Source is also a target (not allowed)' type 'E'. endif. endmethod. method clear_settings. data: lt_DDSHPVAL50 type standard table of DDSHPVAL50, lw_DDSHPVAL50 type DDSHPVAL50, lv_answer type c length 1. lv_answer = '1'. if sy-batch is initial and direct_call = abap_true. * Don't bother with the confirmation when scheduled in background CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING TITLEBAR = 'Please confirm' TEXT_QUESTION = 'Do you want to remove the preference settings for all target users ?' DISPLAY_CANCEL_BUTTON = space IMPORTING ANSWER = lv_answer. endif. if lv_answer = '1'. *--------------------------------------------------- delete from DDSHPVAL50 where username in gr_targets and PVALKEY = gv_SHLPNAME. *--------------------------------------------------- if sy-subrc = 0. message 'Personal preference settings removed for target users' type 'S'. else. message 'No personal preference settings available for target users' type 'S'. endif. else. message 'Action cancelled' type 'S'. endif. endmethod. method copy_settings. data: lt_DDSHPVAL50 type standard table of DDSHPVAL50, lw_DDSHPVAL50 type DDSHPVAL50, lt_DDSHPVAL50_new type standard table of DDSHPVAL50, lv_answer type c length 1, lv_target type ty_target. * First select the source settings for the user and search help: select * from DDSHPVAL50 into table lt_DDSHPVAL50 where username = gv_source and PVALKEY = gv_SHLPNAME. if lt_DDSHPVAL50[] is initial. message 'Personal preference settings not found (for this user)' type 'S'. exit. endif. * Now we're in serious business - confirm update step: lv_answer = '1'. if sy-batch is initial. * Don't bother with the confirmation when scheduled in background CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING TITLEBAR = 'Please confirm' TEXT_QUESTION = 'Do you want to replace the preference settings for all target users ?' DISPLAY_CANCEL_BUTTON = space IMPORTING ANSWER = lv_answer. endif. if lv_answer = '1'. * The personal settings for the user are available, now remove existing settings * for the target group clear_settings( exporting direct_call = abap_false ). * Copy new settings for each individual person: clear: lt_DDSHPVAL50_new[]. loop at gt_targets into lv_target. loop at lt_DDSHPVAL50 into lw_DDSHPVAL50. lw_DDSHPVAL50-username = lv_target-username. append lw_DDSHPVAL50 to lt_DDSHPVAL50_new. endloop. endloop. * Insert composed information into the database: *--------------------------------------------------- insert DDSHPVAL50 from table lt_DDSHPVAL50_new. *--------------------------------------------------- if sy-subrc = 0. message 'Personal preference settings were copied' type 'S'. else. message 'Insert error - Personal preference settings were NOT copied' type 'S'. endif. endif. endmethod. ENDCLASS. *--------------------------------------------------------------------- * S E L E C T I O N - S C R E E N *--------------------------------------------------------------------- selection-SCREEN BEGIN OF LINE. selection-SCREEN COMMENT 1(28) lbl_01 FOR FIELD pa_uname. PARAMETERS: pa_uname TYPE XUBNAME MATCHCODE OBJECT SX_USER OBLIGATORY DEFAULT sy-uname. selection-SCREEN END OF LINE. selection-SCREEN BEGIN OF LINE. selection-SCREEN COMMENT 1(28) lbl_02 FOR FIELD pa_shlpn. PARAMETERS: pa_shlpn TYPE DD30T-SHLPNAME OBLIGATORY. selection-SCREEN END OF LINE. selection-SCREEN BEGIN OF LINE. PARAMETERS: pa_clear TYPE c AS CHECKBOX DEFAULT space. selection-SCREEN COMMENT 4(40) lbl_03 FOR FIELD pa_clear. selection-SCREEN END OF LINE. selection-SCREEN SKIP. selection-SCREEN BEGIN OF LINE. selection-SCREEN COMMENT 1(25) lbl_04 FOR FIELD so_uname. SELECT-OPTIONS so_uname FOR syst-uname MATCHCODE OBJECT SX_USER NO INTERVALS. selection-SCREEN END OF LINE. selection-SCREEN SKIP. selection-SCREEN BEGIN OF LINE. SELECTION-SCREEN PUSHBUTTON (70) lbl_abca USER-COMMAND ABAPCADABRA VISIBLE LENGTH 5. selection-SCREEN END OF LINE. AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_shlpn. * Pick the dynpro value directly from the screen data: lt_DYNPREAD type standard table of DYNPREAD, lw_DYNPREAD type DYNPREAD. lw_DYNPREAD-FIELDNAME = 'PA_UNAME'. clear lt_DYNPREAD[]. append lw_DYNPREAD to lt_DYNPREAD. CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING DYNAME = sy-repid DYNUMB = '1000' TRANSLATE_TO_UPPER = 'X' TABLES DYNPFIELDS = lt_DYNPREAD EXCEPTIONS OTHERS = 0. read table lt_DYNPREAD into lw_DYNPREAD index 1. pa_uname = lw_DYNPREAD-FIELDVALUE. lcl_personal_pref=>f4_search_help( EXPORTING uname = pa_uname ). AT SELECTION-SCREEN ON so_uname. if so_uname[] is initial. message 'No target user ID''s specified' type 'E'. endif. AT SELECTION-SCREEN. CASE sscrfields-ucomm. WHEN 'ABAPCADABRA'. CALL FUNCTION 'CALL_BROWSER' EXPORTING URL = 'http://abapcadabra.com/index.php/reporting/the-selection-screen/545-personal-value-list-tool' EXCEPTIONS OTHERS = 0. ENDCASE. *--------------------------------------------------------------------- * I N I T I T A L I Z A T I O N *--------------------------------------------------------------------- INITIALIZATION. * All texts for this report have been set up as hard-coded texts (no use * of the report text-pool). Reason: easy copying of report source code. lbl_abca = '@N5\QMore on AbapcadabrA.com@'. lbl_01 = 'Settings from user'. lbl_02 = 'Search object (for user)'. lbl_03 = 'Clear settings (for target users)'. lbl_04 = 'Target user list'. *--------------------------------------------------------------------- * S T A R T - O F - S E L E C T I O N *--------------------------------------------------------------------- START-OF-SELECTION. lcl_personal_pref=>gv_source = pa_uname. lcl_personal_pref=>gv_shlpname = pa_shlpn. lcl_personal_pref=>gr_targets[] = so_uname[]. lcl_personal_pref=>select_targets( ). if lcl_personal_pref=>gt_targets[] is initial. message 'No target users selected' type 'S'. else. if not pa_clear is initial. lcl_personal_pref=>clear_settings( ). else. lcl_personal_pref=>copy_settings( ). endif. endif.