cancel
Showing results for 
Search instead for 
Did you mean: 

Difference in execution logic of setVariableValue

kgaurav2k14
Participant
0 Kudos

Hi Friends,

Lately, I am trying to pass the values of the BEX variables on click of dropdown component. I noticed the different execution styles of setVariableValue function. Can you please try to explain what actually happens in background. I have seen several threads to understand the logic but still it is unclear as I read somewhere setvariablevalue function also load the datasource along with setting the value of the variable.

//Variable 0P_CALYE is a mandatory variable on 0CALYEAR.

var varyear = YEAR.getSelectedValue();

-----------------------------------------------------------------------------------

A

DS_2.loadDataSource();

DS_2.setVariableValue("0P_CALYE",varyear);

DS_2.setVariableValue("/PKG/HR_P_0CALMONTH_O", "");

DS_2.reloadData();

---------------------------------------------------------------------------------

B

DS_2.setVariableValue("0P_CALYE",varyear);

DS_2.setVariableValue("/PKG/HR_P_0CALMONTH_O", "");

DS_2.loadDataSource();

----------------------------------------------------------------------------------

C

DS_2.setVariableValue("0P_CALYE",varyear);

DS_2.setVariableValue("/PKG/HR_P_0CALMONTH_O", "");

----------------------------------------------------------------------------------

D

DS_2.setVariableValue("0P_CALYE",varyear);

Eventually, the code written in section A worked for my requirement. However, I dont understand why the other three did not work.

Thanks,

Gaurav

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Gaurav,

Contrary to what you mentioned, setVariableValue does NOT load data sources. It merely passes the value of the variable to the query and fetches the result set. I think you may have mistaken a phenomenon where, if prompts are merged, then every time a data source is initialized or a value is passed to one variable, all data sources having variables will be refreshed.

In your case:

  • B, C and 😧 These methods will not work - only when a data source is initialized is the list of variables/prompts belonging to that variable fetched. In these three methods, you are either trying to pass values to prompts before loading data sources, or not loading data sources at all.
  • A: This method will work for you as you are loading the data source first - the variables/prompts belonging to the data source is fetched. However, as Karthik Swaminathan has mentioned, the last line where you are reloading the data sources is unnecessary.

I hope you found this explanation satisfactory.

Thanks and Regards,

Eshwar Prasanna

kgaurav2k14
Participant
0 Kudos

Hi Eshwar,

Thanks for your reply. Please find my analysis and comments below.

1. SetVariableValue : I read about reloading of datasource from SAP help. May be I am not able to interpret it. Screenshot is attached for your reference. Please comment.

2. Reload datasource: As pointed by you and Karthik, If you I dont put the reload statement, my results differ. Infact, without reload statement, it gives me wrong results.

DS_2 is the datasource which is triggered on the selection of Year Listbox. DS_2 loading in script is set to "True". This means if is not loaded on application initialisation.

Please see the results when I have reload statement in my code of onselect event of Year Listbox.


var varyear = YEAR.getSelectedValue();

DS_2.loadDataSource();

DS_2.setVariableValue("0P_CALYE",varyear);

DS_2.setVariableValue("/PKG/HR_P_0CALMONTH_O", "");

DS_2.reloadData();

CALMON.setItems(DS_2.getMemberList("0CALMONTH", MemberPresentation.INTERNAL_KEY, MemberDisplay.TEXT, 20,"ALL"));

Now, see what happens when I dont put reload statement.

I am not sure what reload statement is doing in my case but it brings in right results. I am confused.

Best Regards,

Gaurav

Former Member
0 Kudos

Hi Gaurav,

In response to your reply:

1. setVariableValue() has to execute the query again to bring the fresh result set. But it DOES NOT load data sources if they have not been loaded. Please note that the key here in the SAP help is that it executes the query again (Meaning this should have been executed once; Query Execution is a little different from data source loading).

2.  Can you try making the following changes:

Use only the following script inside your dropdown:


var varyear = YEAR.getSelectedValue();

DS_2.loadDataSource();

DS_2.setVariableValue("0P_CALYE",varyear);

DS_2.setVariableValue("/PKG/HR_P_0CALMONTH_O", "");

Navigate to the properties of data source DS_2 and insert the following script in the event On Result Set Change:


CALMON.setItems(DS_2.getMemberList("0CALMONTH", MemberPresentation.INTERNAL_KEY, MemberDisplay.TEXT, 20,"ALL"));

If I am not mistaken, there is a delay in execution of your query post variable submission which the getMemberList statement overlaps. Please try this sequence and let me know if it works for you.

Thanks and Regards,

Eshwar Prasanna

kgaurav2k14
Participant
0 Kudos

Thanks Eshwar.

Regarding Point 2 - Reloadstatement - I have changed the code and settings according to your recommended one. This indeed makes the execution faster but here are my further observations :

1. I can see one error message at the bottom as soon as I select the Year and DS_2 is executed  which is shown below.

2. If I do further drill down which invloves loading of another datasource say DS_3, as soon as DS_3 is loaded, the listbox of Month also gets refreshed and it only displays selected month which is shown below. It is not showing Jan - Dec, it is only showing the value which was selected as a value for further drill down.

Regarding Point 1 - I am sorry but I am still not able understand it

Query Execution is a little different from data source loading - Can you please give me an idea.


Scenario 1 -  If I have not loaded a datasource in application loading. It means I have to load it manually.

I do it by DS_2.loaddatasource() statement, when I do this, the query associated with datasource is also executed - Is this correct?


Scenario 2 - If I have already loaded my datasource in application loading. Now if I write a setvariablevalue statement and assign a value to the variable of the datasource, then the query is executed again. I dont have to again write DS_2.loaddatasource before setvariablevalue statement. Please comment.


Thanks,

Gaurav

Former Member
0 Kudos

Hi Gaurav,

1. This may happen sometimes. I have never seen it have an impact on my application. You can hide the errors. I will also try to reproduce and come out with a solution for this.

2. Does DS_3 have the same variables? Are your prompts merged? And are you passing a value to a merged variable? It would be useful if you can either share your script or if you can export and share your application. Are you passing the selected value when loading DS_3?

3. If your data source has already been loaded, it means your application has a list of the variables used by the query bound to that data source. If your data source is not loaded, the application does not have a list of the variables used by the data source. This is because when the data source is loaded, there is an RFC call usually executed to get information about variables. With a BEx query, for example, you will see the following call:

When you submit variables, the data source has to execute the query with your variable value to bring back a new result set (if necessary). Data Source loading is done at the platform level - query execution is done at the database/source level.

Former Member
0 Kudos

I understand section A had worked for you, even then the last line DS2.reloadData(); is not necessary since the datasource is loaded and prompts have been passed.

Reload data script is used to bring in latest data from the backend which can be used ( if there is such requirement) sometime after the dashboard is launched by using a timer component.

Former Member
0 Kudos

Hi Gaurav,

Did you have load in script property set to TRUE for the data source?

If it is set to TRUE then you will have to load the data source before you can pass values to the variables of the query.

Regards,

Swapnil Koti