Application Development and Automation 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: 
Read only

Changing Variant Parameters Programmatically

Former Member
0 Likes
4,022

Hi Guys/Dolls

I've developed a program that has a user selection date range on it and I have saved this program as a variant. I submit this program has a batch job on a monthly basis but need to change the dates on the variant each month to be the start and end date of the previous month.

I believe I need to use the following Function Modules; please correct me if I am barking up the wrong tree. Unfortunately I have absolutely no idea how to use them within ABAP. Do I need anything else to change my variant parameters?

  • RS_VARIANT_CONTENTS

  • RS_CHANGE_CREATED_VARIANT

Does anybody have a very small snippet of code that will allow me to change the date of the variant.

Many thanks in advance.

Raj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,938

u can use the option of 'Dynamic Date Calculation' of the Variant.

5 REPLIES 5
Read only

Former Member
0 Likes
1,939

u can use the option of 'Dynamic Date Calculation' of the Variant.

Read only

Former Member
1,938

follow these steps

1.click on the 'Save' button of the seleciton screen

2. Find <b>Objects for selection screen</b>

select ur variable in the selection screen

3.scroll to the column 'Selection Variables'

select F4 help, choose the value 'D'

4.now scroll to the column 'Name of the variable'

click on F4 and select the value according to ur requirement.

Read only

Former Member
0 Likes
1,938

Ok Guys/Dolls

I've managed to hack a solution and have posted this for reference.

The code is as follows:-



FORM change_variant .

  DATA: h_rc LIKE sy-subrc.
  DATA: ival TYPE STANDARD TABLE OF rsparams WITH HEADER LINE.
  DATA: ls_variantdesc LIKE varid.

*1st check to see that the variant exists.
  CALL FUNCTION 'RS_VARIANT_EXISTS'
    EXPORTING
      report              = sy-repid
      variant             = variant_name
    IMPORTING
      r_c                 = h_rc
    EXCEPTIONS
      not_authorized      = 01
      no_report           = 02
      report_not_existent = 03
      report_not_supplied = 04.

* If variant exists then obtain the contents of the variants.
  IF h_rc = 0.

    CALL FUNCTION 'RS_VARIANT_CONTENTS'
      EXPORTING
        report                      = sy-repid
        variant                     = variant_name
        move_or_write               = 'W'
*   NO_IMPORT                   = ' '
*   EXECUTE_DIRECT              = ' '
* IMPORTING
*   SP                          =
      TABLES
*   L_PARAMS                    =
*   L_PARAMS_NONV               =
*   L_SELOP                     =
*   L_SELOP_NONV                =
        valutab                     = ival
*   OBJECTS                     =
*   FREE_SELECTIONS_DESC        =
*   FREE_SELECTIONS_VALUE       =
* EXCEPTIONS
*   VARIANT_NON_EXISTENT        = 1
*   VARIANT_OBSOLETE            = 2
*   REPORT_NOT_EXISTENT         = 3
*   OTHERS                      = 4
              .
    IF sy-subrc = 0.

*     Change value of the variants to what you want it to be.
      LOOP AT ival WHERE selname EQ 'PNPBEGDA' OR
                         selname EQ 'PNPBEGPS' OR
                         selname EQ 'PNPENDDA' OR
                         selname EQ 'PNPENDPS'.
        ival-low = ''.
        MODIFY ival.
      ENDLOOP.

      LOOP AT ival WHERE selname EQ 'P_CNGDAT'.
        ival-low  = '20000201'.
        ival-high = '20001231'.
        MODIFY ival.
      ENDLOOP.

*   Now re-save the variant with the appropriate changes.

*     Clear and re-populate the variant description.
      CLEAR ls_variantdesc.
      ls_variantdesc-aename   = sy-mandt.
      ls_variantdesc-aename   = sy-uname.
      ls_variantdesc-aedat    = sy-datum.
      ls_variantdesc-aetime   = sy-uzeit.


      CALL FUNCTION 'RS_CHANGE_CREATED_VARIANT'
        EXPORTING
          curr_report                     = sy-repid
          curr_variant                    = variant_name
          vari_desc                       = ls_variantdesc
*   ONLY_CONTENTS                   =
        TABLES
          vari_contents                   = ival
*   VARI_TEXT                       =
*   VARI_SEL_DESC                   =
*   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.
        PERFORM set_pnp_default.
      ENDIF.

    ENDIF.

  ENDIF.

ENDFORM.                    " change_variant


FORM set_pnp_default.

* The following 2 statement will set Today as the default on the PNP
* selection and also move the cursor to that field.
* IMPORTANT NOTE - you must have 'PNPTIMR1' in capitals otherwise it
* doesn't work.
  pnptimed = 'D'.
  SET CURSOR FIELD 'PNPTIMR1'.

ENDFORM.                    " set_pnp_default


Read only

Former Member
0 Likes
1,938

Hi!

When you save a variant, in SE38, on the selection, by pressing CTRL+S.

Here you have to tick the checkbox, which is called "Save field without values". In this case the variant will not overwrite this field, and the field will contain the values, you entered from the program's INITIALIZATION event.

Regards

Tamá

Read only

Former Member
0 Likes
1,938

See solution posted by myself on 11.05.07