5 1 1 1 1 1 Rating 100% (1 Vote)
In article Save variant for single selection screen subscreen I've shown you how to save a variant for single selection-screen subscreen with a little help of FM RS_ISOLATE_1_SELSCREENRS_CREATE_VARIANT. If you use method shown there it may happen that when you're loading a variant to a screen it overrides also values from other fields. To avoid that I've prepared a method to fill only fields from one subscreen. I will use here FM RS_VARIANT_CATALOG to allow user to select variant for subscreen, FM RS_VARIANT_CONTENTS to read it's content, FM RS_ISOLATE_1_SELSCREEN to get the fields of subscreen and field-symbols to put them on place. So let's start.
 
As input parameter I will use only subscreen number:

i_dynnr type sy-dynnr  -> subscreen number

Implementation of method:

method get_variant_for_ss.
  dataft_params type table of rsparams.
  dataf_variant type rsvar-variant.
  dataf_text type rsvar-vtext.
  datafs_params type rsparams.
  datafs_paramsscr type rsparams.
  data  f_fieldname type fieldname.
  dataft_sscr type table of rsscr.
  field-symbols <any_selopt_itab> type standard table.
  field-symbols <any_selopt> type any.
  field-symbols <any_field> type any.

  "now I will display pop-up with variants for one subscreen
  call function 'RS_VARIANT_CATALOG'
  exporting
    report                    sy-repid
*     NEW_TITLE                 = ' '
    dynnr                      i_dynnr
*     INTERNAL_CALL              = ' '
*     MASKED                     = 'X'
*     VARIANT                    = ' '
    pop_up                     'X'
  importing
    sel_variant                f_variant
    sel_variant_text           
f_text
*   TABLES
*     BELONGING_DYNNR            = BELONGING_DYNNR
  exceptions
    no_report                  1
    report_not_existent        2
    report_not_supplied        3
    no_variants                4
    no_variant_selected        5
    variant_not_existent       6
    others                     7
    .
  if sy-subrc eq .
    "if variant was supplied then I read its content
    call function 'RS_VARIANT_CONTENTS'
    exporting
      report                      sy-repid
      variant                     f_variant
      move_or_write               = 'M'
*     NO_IMPORT                   = ' '
*     EXECUTE_DIRECT              = ' '
*   IMPORTING
*     SP                          = SP
    tables
*     L_PARAMS                    = L_PARAMS
*     L_PARAMS_NONV               = L_PARAMS_NONV
*     L_SELOP                     = L_SELOP
*     L_SELOP_NONV                = L_SELOP_NONV
      valutab                     ft_params
*     OBJECTS                     = OBJECTS
*     FREE_SELECTIONS_DESC        = FREE_SELECTIONS_DESC
*     FREE_SELECTIONS_VALUE       = FREE_SELECTIONS_VALUE
    exceptions
      variant_non_existent        1
      variant_obsolete            2
      others                      3
      .
    if sy-subrc eq 0.
      "let's see what fields are on this 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.
        sort ft_sscr by name ascending.

        " clear current content of selection fields
        loop at ft_params into fs_params.
          read table ft_sscr with key name fs_params-selname binary search transporting no fields.
          if sy-subrc ne 0.
            continue.
          endif.
          concatenate '(' sy-repid ')' fs_params-selname into f_fieldname.
          case fs_params-kind.
            when 'S'.
              concatenate f_fieldname '[]' into f_fieldname.
              assign (f_fieldnameto <any_selopt_itab>.
              if sy-subrc eq 0.
                refresh <any_selopt_itab>.
              endif.
            when 'P'.
              assign (f_fieldnameto <any_field>.
              if sy-subrc eq 0.
                clear <any_field>.
              endif.
            when others.
          endcase.
        endloop.

        "add values from saved variant to selection fields
        loop at ft_params into fs_params.
          read table ft_sscr with key name fs_params-selname binary search transporting no fields.
          if sy-subrc ne 0.
            continue.
          endif.
          concatenate '(' sy-repid ')' fs_params-selname into f_fieldname.
          case fs_params-kind.
            when 'S'"select-options
              concatenate f_fieldname '[]' into f_fieldname.
              assign (f_fieldnameto <any_selopt_itab>.
              if sy-subrc eq 0.
                "firstly append initial line to be able to assign components
                append initial line to <any_selopt_itab> assigning <any_selopt>.
                "now fill each component separately
                assign component 'SIGN' of structure  <any_selopt> to <any_field>.
                if sy-subrc eq 0.
                  <any_field> fs_params-sign.
                endif.

                assign component 'OPTION' of structure  <any_selopt> to <any_field>.
                if sy-subrc eq 0.
                  <any_field> fs_params-option.
                endif.

                assign component 'LOW' of structure <any_selopt> to <any_field>.
                if sy-subrc eq 0.
                  <any_field> fs_params-low.
                endif.

                assign component 'HIGH' of structure <any_selopt> to <any_field>.
                if sy-subrc eq 0.
                  <any_field> fs_params-high.
                endif.

                "just to be sure that select options are filled
                assign component 'SIGN' of structure  <any_selopt> to <any_field>.
                if sy-subrc ne 0.
                  delete table <any_selopt_itab> from <any_selopt>.
                elseif <any_field> is initial.
                  delete table <any_selopt_itab> from <any_selopt>.
                endif.

              endif.
            when 'P'"parameters
              assign (f_fieldnameto <any_field>.
              if sy-subrc eq 0.
                clear <any_field>.
                <any_field> fs_params-low.
              endif.
            when others.
          endcase.

        endloop.
      endif.
    endif.
  endif.
endmethod.

Now you're able to save and load a variant for one selection screen subscreen! 
Enjoy!