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: 

Creating Variants programatically

Kartik2
Contributor
0 Kudos

Dear Developers,

I am new to sap and need some help, so I am writing in this forum to seek help with regard to creating variants programatically.

I am creating variants programatically by using the function module 'RS_CREATE_VARIANT'. The variants are getting created and it is fine. But some of the variants require dynamic date calculations, how do i go about doing it.

for the present the low and high periods of date parameter are hard coded values but i want the date to dynamically change and the range to be set dynamically to 6 days starting from current date - 3, to current date + 3. So, how do i go about doing this.

Looking forward to solutions from all the experienced developers. Your quick help will highly be appreciated. Thank you

Regards,

kartik

1 ACCEPTED SOLUTION

Kartik2
Contributor
0 Kudos

Thanks for spending your time and replying Mr. Kiran but i am afraid that it is not what i want, i request you to kindly go through the following link:

http://help.sap.com/saphelp_nw2004s/helpdata/en/c0/98039be58611d194cc00a0c94260a5/content.htm

and then let me know how to do the same thing programatically. Thank you

Regards

kartik

15 REPLIES 15

Former Member
0 Kudos

Hi,

use the code like this


l_date-sign = 'I'.
l_date-option = 'BT'.
L_date-high = sy-datum + 3. or "for adding 3 days from current date
l_date-low = sy-datum - 3."for less 3 days from current date
append l_date[]. "pass the value to the select option filed name

Regards,

Dhina..

Edited by: Dhina DMD on Jun 13, 2011 7:03 AM

Kartik2
Contributor
0 Kudos

Thanks Dhina fro a quick reply but i think i need to explain more about my requirement.

Here my requirement is to change the date dynamically, by writing your code the date range will be static but i want it to be dynamic, like whenever you display the values of the variant you should be able to find the range of current six days. i.e the range should be

current date - 3, current date + 3.

but not

variant creation dare - 3, variant creation date + 3

Hope you got my problem now. Developers please let me know if you have any solution for this problem.

Thank you.

Regards

kartik

Former Member
0 Kudos

Hi,

You can find the Date of the variant created from the table VARID.

Go to the table VARID, You can find the report name, Variant name, EDat(Date on which variant was created), you will also find the time stamp at which the variant is created.

Bassed on the edat filed you should use the calculation.

Hope its help full for you..

Regards,

Dhina...

Kartik2
Contributor
0 Kudos

Thanks for your quick reply again Dhina, but i am afraid that this will also not work and it is a very lengthy procedure. In the attributes of the variant we can specify it as dynamic date calculation. i want to program this process.

please go through the following link which explains how can we achieve dynamic date calculation manually, i want it done programatically:

http://help.sap.com/saphelp_nw2004s/helpdata/en/c0/98039be58611d194cc00a0c94260a5/content.htm

Hope you will go through the above link and then try to help me.

Thank you

Regards,

kartik

Former Member
0 Kudos

Hi,

make use of table VARID , and field EDAT.

get the varid-edat by passing your varient name.

write the code like this.

S_date-sign = 'I'.

s_date-option = 'BT'.

s_date-low = varid-edat - 3.

s_date-high - varid-edat + 3.

append s_date.

hope this will helps you,

Regards,

Kiran

Kartik2
Contributor
0 Kudos

Thanks for spending your time and replying Mr. Kiran but i am afraid that it is not what i want, i request you to kindly go through the following link:

http://help.sap.com/saphelp_nw2004s/helpdata/en/c0/98039be58611d194cc00a0c94260a5/content.htm

and then let me know how to do the same thing programatically. Thank you

Regards

kartik

0 Kudos

Dear experts,

I am eagerly waiting for your suggestions and replies. Please try to help me out. Looking forward to more messages. Thank you.

Regards

kartik

0 Kudos

Use Dhina's code and for your 6 or 8 or whatever the no.of days.... use TVARVC and select each time program runs and this number can be maintainable. Select the number from TVARVC and write the code dynamically. I hope you don't need to save this as variant.

If yes, explain further.

Former Member
0 Kudos

Hi Karthik,

I am not sure about the direct FM to create a variant with dynamic values, but you can use the FM "RS_VARIANT_VALUE_SAVE" to set the dynamic attributes to the variant parameters for an existing variant.May be you can create a normal variant and then change it to dynamic value. Please refer the below code to change the variant to dynamic values. To get an idea about tables parameters passed, call the FM "RS_VARIANT_FETCH" ( function - GET ) with a varaint which is already set to dynamic date.


ls_RSVARKEY-report = sy-repid.
ls_RSVARKEY-variant = 'VARIANT'.

CALL FUNCTION 'RS_VARIANT_VALUE_SAVE'
  EXPORTING
    rkey                = ls_RSVARKEY
    STATUS              = 'INT'
  tables
    selctab             = lt_selctab
    P_VARI              = lt_vari
    P_VARIVDAT          = lt_varidat
    P_VARISCREENS       = lt_variscreens
  EXCEPTIONS
   NOT_EXECUTED        = 1
   OTHERS              = 2.

Regards,

Suman Jagu

0 Kudos

Thank you Mr. Suman Jagu. This was exactly what i wated.

Thanks to all the developers who had spent time in reading my question. Hope to have a good learning experience with sdn.

Former Member
0 Kudos

Hi Kartik,

I'm also in need for something similar to what you needed. I'm trying to use the same solution and I need help in RS_VARIANT_FETCH. when ever I call it with "GET" as function, it opens a dialog window asking for selection of variant. how do I suppress it? is it something to do with other parameters like SUBMODE?

Thanks

Kartik2
Contributor
0 Kudos

The data already present in the variant is being overwritten

0 Kudos

HI Suman jagu,

i have a problem changing the variat attribute in the way u suggested because the function module is overwriting the data already stored in the variant and the variant is left with only the value of dynamic date calculation the rest all the other select options and paraeters are cleared. How to fix this problem. Thank you

Regards

kartik

Former Member
0 Kudos

As per you question, I thought you had to create variant with only the dynamic values. Anyhow, If you want to update the static values also, you may have to call the FM "RS_CHANGE_CREATED_VARIANT" with only the "vari_contents" after the "RS_VARIANT_VALUE_SAVE" call.

Kartik2
Contributor
0 Kudos

Thanks to all the dvelopers who have devoted their time in solving my problem. Hope we all have a great learning experiance through sdn.