Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Create multiple variants via RS_CREATE_VARIANT

szymon_glapiak
Explorer

Hi team.

I'm trying to create multiple variants in single session via FM 'RS_CREATE_VARIANT' . I noticed that the variants created in that way can inherited part of parameters from previously created item. Below some example.

      ls_variant_content-kind = 'P'.
      ls_variant_content-selname = 'PARAM1'.
      ls_variant_content-low = abap_true.
      APPEND ls_variant_content TO lt_content.
      ls_variant_content-selname = 'PARAM2'.
      ls_variant_content-low = abap_true.
      APPEND ls_variant_content TO lt_content.
       CALL FUNCTION 'RS_CREATE_VARIANT'
         EXPORTING
           curr_report               =    'ZTEST'              " Report Name
           curr_variant              =    'TEST'              " Variant name
           vari_desc                 =   ls_description               " Variant description (structure VARID)
         TABLES
           vari_contents             =    lt_content              " Contents (STRUCTURE RSPARAMS)
           vari_text                 =    lt_text              " Variant text (structure VARIT)
      COMMIT WORK.
............
      REFRESH lt_content.
      ls_variant_content-kind = 'P'.
      ls_variant_content-selname = 'PARAM1'.
      ls_variant_content-low = abap_true.
      APPEND ls_variant_content TO lt_content.
       CALL FUNCTION 'RS_CREATE_VARIANT'
         EXPORTING
           curr_report               =    'ZTEST'              " Report Name
           curr_variant              =    'TEST1'              " Variant name
           vari_desc                 =   ls_description               " Variant description (structure VARID)
         TABLES
           vari_contents             =    lt_content              " Contents (STRUCTURE RSPARAMS)
           vari_text                 =    lt_text              " Variant text (structure VARIT)
   COMMIT WORK.

For the example above variant TEST1 has Param1 = X what is ok and also PARAM2 = X which I don't send to function. Do You know why and how I can avoid it (without to send PARAM2 = space )

1 REPLY 1

Sandra_Rossi
Active Contributor
0 Kudos

That's an internal limit (internally, the program ZTEST is loaded into the memory of the internal session, its parameter and select-option values are modified by RS_CREATE_VARIANT, and if you don't explicitly pass a value to a parameter/select-options it will keep the last one).

You must pass the values of all parameters and select-options. Add this, and you'll see that PARAM2 takes the value abap_false:

      ls_variant_content-selname = 'PARAM2'.
      ls_variant_content-low = abap_false.
      APPEND ls_variant_content TO lt_content.
NB: minimal reproducible example (program creates variants on itself):
REPORT ztesttest.
PARAMETERS param1 AS CHECKBOX.
PARAMETERS param2 AS CHECKBOX.
DATA ls_variant_content type rsparams.
DATA lt_content type table of rsparams.
DATA ls_description type varid.
DATA lt_text type table of varit.
      ls_variant_content-kind = 'P'.
      ls_variant_content-selname = 'PARAM1'.
      ls_variant_content-low = abap_true.
      APPEND ls_variant_content TO lt_content.
      ls_variant_content-selname = 'PARAM2'.
      ls_variant_content-low = abap_true.
      APPEND ls_variant_content TO lt_content.
ls_description = VALUE #(
    report     = sy-repid
    variant    = 'TEST'
    transport  = 'F'
    ENVIRONMNT = 'A' ).
lt_text = VALUE #( ( VALUE #( BASE CORRESPONDING #( ls_description )
                     langu = sy-langu
                     vtext = 'test' ) ) ).
       CALL FUNCTION 'RS_CREATE_VARIANT'
         EXPORTING
           curr_report               =   ls_description-report
           curr_variant              =   ls_description-variant
           vari_desc                 =   ls_description 
         TABLES
           vari_contents             =    lt_content  
           vari_text                 =    lt_text.    
      COMMIT WORK.
............
      REFRESH lt_content.
      ls_variant_content-kind = 'P'.
      ls_variant_content-selname = 'PARAM1'.
      ls_variant_content-low = abap_true.
      APPEND ls_variant_content TO lt_content.
      ls_variant_content-selname = 'PARAM2'.
      ls_variant_content-low = abap_false.
      APPEND ls_variant_content TO lt_content.
ls_description-variant = 'TEST1'.
lt_text = VALUE #( ( VALUE #( BASE CORRESPONDING #( ls_description )
                     langu = sy-langu
                     vtext = 'test' ) ) ).
       CALL FUNCTION 'RS_CREATE_VARIANT'
         EXPORTING
           curr_report               =   ls_description-report
           curr_variant              =   ls_description-variant
           vari_desc                 =   ls_description
         TABLES
           vari_contents             =    lt_content  
           vari_text                 =    lt_text.    
   COMMIT WORK.