* _______ _______ _______ _______ _______ _______ ______ _______ _______ ______ _______ * | _ | _ | _ | | | _ | || _ | _ | _ | | _ | * | |_| | |_| | |_| | _ | | |_| | _ | |_| | |_| | | || | |_| | * | | | | |_| | | | | | | | | |_||_| | * | | _ || | ___| _| | |_| | | _ || __ | | * | _ | |_| | _ | | | |_| _ | | _ | |_| | | | | _ | * |__| |__|_______|__| |__|___| |_______|__| |__|______||__| |__|_______|___| |_|__| |__| * www.abapcadabra.com * *------------------------------------------------------------------------------------------- * program : ZABAPCADABRA_VARIANT_DATASTORE * title : Example source: update variant with settings on last run * functional area : Cross modules * environment : 4.7 * program Function : This report demonstrates the use of a local class * lcl_variant_utility which can be used to read and * write parameter fields on the variant. * Documentation : Search for "variants - advanced" on AbapcadabrA.com * Previous version : This is the initial version * Developer name : Wim Maasdam * Development date : 15/01/2015 * Version : 0.1 *--------------------------------------------------------------------- * Change list: * Date Description * 15/01/2015 Initial release REPORT ZABAPCADABRA_VARIANT_DATASTORE. parameters pa_par type c length 4. *----------------------------------------------------------------------* * CLASS lcl_variant_utility DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_variant_utility DEFINITION. PUBLIC SECTION. DATA: gv_report type RSVAR-REPORT, gv_variant TYPE RSVAR-VARIANT, gw_varid type varid, gt_contents TYPE TABLE OF rsparams. METHODS: constructor IMPORTING variant_name TYPE any, get_parameter_value IMPORTING parameter TYPE any RETURNING VALUE(value) type rsparams-low, set_parameter_value IMPORTING parameter TYPE any value type any, save. ENDCLASS. "lcl_variant_utility DEFINITION *----------------------------------------------------------------------* * CLASS lcl_variant_utility IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_variant_utility IMPLEMENTATION. METHOD constructor. gv_report = sy-repid. gv_variant = variant_name. CLEAR: gt_contents[]. SELECT * FROM varid INTO gw_varid UP TO 1 ROWS WHERE REPORT = gv_report AND variant = gv_variant. ENDSELECT. IF sy-subrc = 0. * Read current variant settings: CALL FUNCTION 'RS_VARIANT_CONTENTS' EXPORTING REPORT = gv_report variant = gv_variant move_or_write = 'M' TABLES valutab = gt_contents EXCEPTIONS OTHERS = 0. ELSE. clear: gv_report, gv_variant. ENDIF. ENDMETHOD. "constructor * Fetch the value of a parameter (P) field METHOD get_parameter_value. DATA: lw_contents TYPE rsparams. check not gv_variant is initial. CLEAR VALUE. READ TABLE gt_contents INTO lw_contents WITH KEY SELNAME = PARAMETER KIND = 'P'. IF sy-subrc = 0. VALUE = lw_contents-low. ENDIF. ENDMETHOD. * Set/modify the value of a parameter (P) field METHOD set_parameter_value. FIELD-SYMBOLS: TYPE rsparams. check not gv_variant is initial. READ TABLE gt_contents ASSIGNING WITH KEY SELNAME = PARAMETER KIND = 'P'. IF sy-subrc = 0. -low = VALUE. ENDIF. ENDMETHOD. * Save the variant settings, with altered parameter values METHOD save. check not gv_variant is initial. * Save the variant CALL FUNCTION 'RS_CHANGE_CREATED_VARIANT' EXPORTING curr_report = gv_report curr_variant = gv_variant vari_desc = gw_varid only_contents = 'X' TABLES vari_contents = gt_contents EXCEPTIONS OTHERS = 4. ENDMETHOD. ENDCLASS. "lcl_variant_utility IMPLEMENTATION start-of-selection. data: go_var type ref to lcl_variant_utility, gv_counter type n length 4. create object go_var exporting variant_name = 'RUNCONTROL'. if go_var->gv_variant is initial. message 'Variant RUNCONTROL not available' type 'S'. else. gv_counter = go_var->get_parameter_value( 'PA_PAR' ). add 1 to gv_counter. go_var->set_parameter_value( parameter = 'PA_PAR' value = gv_counter ). go_var->save( ). if sy-subrc = 0. message 'Variant RUNCONTROL updated' type 'S'. else. message 'Variant RUNCONTROL could not be updated' type 'S'. endif. endif.