I_DYNNR TYPE SY-DYNNR - Current Screen Number
I_VARNAME TYPE RSVAR-VARIANT - Variant Name
I_VARTEXT TYPE VARIT-VTEXT - Program variant short text
method create_variant_for_ss.
data: ft_params type table of rsparams.
data: ft_sscr type table of rsscr.
data: fs_sscr type rsscr.
data: fr_selopt type range of rsscr-name.
data: fs_selopt like line of fr_selopt.
data: f_vari_desc type varid.
data: ft_vari_text type table of varit.
data: fs_vari_text type varit.
data: ft_vscreens type table of rsdynnr.
data: fs_vscreens type rsdynnr.
data: f_retcode type c.
*get all selection screen parameters and values
call function 'RS_REFRESH_FROM_SELECTOPTIONS'
exporting
curr_report = sy-repid
* IMPORTING
* SP = SP
tables
selection_table = ft_params
exceptions
not_found = 1
no_report = 2
others = 3
.
if sy-subrc eq 0.
endif.
*get fields of our subscreen
call function 'RS_ISOLATE_1_SELSCREEN'
exporting
program = sy-repid
dynnr = i_dynnr
* TABIX = 0
* IMPORTING
* LAST_TABIX = LAST_TABIX
tables
screen_sscr = ft_sscr
* GLOBAL_SSCR = GLOBAL_SSCR
exceptions
no_objects = 1
others = 2
.
if sy-subrc eq 0.
loop at ft_sscr into fs_sscr.
fs_selopt-sign = 'I'.
fs_selopt-option = 'EQ'.
fs_selopt-low = fs_sscr-name.
append fs_selopt to fr_selopt.
endloop.
*delete parameters and values not used on our subscreen
delete ft_params where selname not in fr_selopt.
endif.
*set variant global data
move sy-mandt to f_vari_desc-mandt.
move sy-repid to f_vari_desc-report.
move i_varname to f_vari_desc-variant.
move sy-uname to f_vari_desc-ename.
move sy-datum to f_vari_desc-edat .
move sy-uzeit to f_vari_desc-etime.
move 'X' to f_vari_desc-environmnt.
*set description of variant
move sy-mandt to fs_vari_text-mandt.
move sy-langu to fs_vari_text-langu.
move sy-repid to fs_vari_text-report .
move i_varname to fs_vari_text-variant.
move i_vartext to fs_vari_text-vtext.
append fs_vari_text to ft_vari_text.
*set subscreen number
fs_vscreens-dynnr = i_dynnr.
fs_vscreens-kind = ''.
append fs_vscreens to ft_vscreens.
*create variant
call function 'RS_CREATE_VARIANT'
exporting
curr_report = sy-repid
curr_variant = i_varname
vari_desc = f_vari_desc
tables
vari_contents = ft_params
vari_text = ft_vari_text
vscreens = ft_vscreens
exceptions
illegal_report_or_variant = 1
illegal_variantname = 2
not_authorized = 3
not_executed = 4
report_not_existent = 5
report_not_supplied = 6
variant_exists = 7
variant_locked = 8
others = 9.
if sy-subrc eq 7.
*variant already exists so ask if user wants to overwrite it
call function 'POPUP_TO_CONFIRM_WITH_MESSAGE'
exporting
diagnosetext1 = 'Variant exists, do you want to overwrite it?'(001)
textline1 = ' '(002)
titel = 'Variant exists, do you want to overwrite it?'(001)
cancel_display = space
importing
answer = f_retcode
exceptions
others = 1.
if sy-subrc <> 0.
exit.
endif.
if f_retcode eq 'J'.
*user agreed so change existing variant
call function 'RS_CHANGE_CREATED_VARIANT'
exporting
curr_report = sy-repid
curr_variant = i_varname
vari_desc = f_vari_desc
* ONLY_CONTENTS = ONLY_CONTENTS
tables
vari_contents = ft_params
vari_text = ft_vari_text
* VARI_SEL_DESC = VARI_SEL_DESC
* OBJECTS = OBJECTS
exceptions
illegal_report_or_variant = 1
illegal_variantname = 2
not_authorized = 3
not_executed = 4
report_not_existent = 5
report_not_supplied = 6
variant_doesnt_exist = 7
variant_locked = 8
selections_no_match = 9
others = 10
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endif.
endif.
endmethod.