cancel
Showing results for 
Search instead for 
Did you mean: 

Set Filter + isResultSetEmpty On Startup?

0 Kudos

I have a requirement to set the filter on the data to the current year and current quarter at start up, only if there is data for the time period. If there is no data for that time period, then set the filter to the previous year.

In application start up I did have

DS_1.setFilter("INVOICE_YEAR","2016");

if (!DS_1.isResultSetEmpty())

{

DS_1.setFilter("INVOICE_QUARTER","01");

if (DS_1.isResultSetEmpty())

{

DS_1.clearFilter("INVOICE_QUARTER");

}

}

else

{

DS_1.setFilter("INVOICE_YEAR","2015");

if (!DS_1.isResultSetEmpty())

{

DS_1.setFilter("INVOICE_QUARTER","04");

if (DS_1.isResultSetEmpty())

{

DS_1.clearFilter("INVOICE_QUARTER");

}

}

}

The problem is that even though there is no data for 2016, DS_1 says that it is not empty and the else does not happen.

I then put that code into the DS_1 On Result Set Change and the I get the same result.

What am I doing wrong? Is this not possible? If this is not possible, then what is the work around?

Thanks for your help with this,

Pete

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

That leaves you the getData with another datasource to check your years and quarters

0 Kudos

Hi Franck/Pete,

I am also facing same kind of issue as Pete. I also have a requirement in a design studio 1.5 report using BEx as data source. In there I have a "Dimension Filter". In that Dimension filter I need to show latest month-Year if a certain data-source is having data for latest month. If not then I need to show the last month-year.

I was trying to write similar type of code which Pete tried in the "On StartUp" script.

I calculated current month and last month based on system date in two global variables.

LYYMM = Last Month Year

CYYMM = Current Month Year

Then I was trying to do the below code:

DS_1.setFilterExt("0CALMONTH", CYYMM);

if(DS_1.isResultSetEmpty())

{

  DS_1.clearFilter("0CALMONTH");

  DS_1.setFilterExt("0CALMONTH", LYYMM);

}

But it is not working. The "if" condition is getting executed even if DS_1 is not empty for latest month. As a result I am seeing that the dimension filter is actually showing Last Month-Year as default value.

Can you please suggest how to proceed regarding this.

Thanks,

Shaunakh

0 Kudos

Well, it's been a few months, but if I recall correctly the issue that I was having seemed related to this, but in fact was not and this may be the case for you as well Shaunakh.

The issue that I had was that the DS_1.isResultSetEmpty() was always false, however after looking at all of the members in DS_1 I realized that I was wrong.  Here is an example:

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

DS_1 has the following fields:

  • first name
  • last name
  • street
  • month
  • total income (measure)

I wanted to verify that the datasource (DS_1) had values using DS_1.isResultSetEmpty(). If it had values then I wanted to do some calculation on total income. The issue for me was that while DS_1 had values for one or more if it's fields it did not always have values for total income. As a result the isResultSetEmpty() would always return false, however when I checked on the value of total income I did not get what I expected to get.

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


Here is one way to see if you are experiencing the same problem that I was experiencing. In your code where you expect the result to be empty and it's not the "if (DS_1.isResultSetEmpty())" do something like this (my syntax may not be 100% correct for this code)


===================

if (!DS_1.isResultSetEmpty())      // note the ! in the if, this means NOT

{

     var mDimensions = DS_1.getDimensions();     // get all of the dimensions in the result set

     for (i = 0; i < mDimensions.length; i++)     // loop though the result set

     {

          textBox1.setText(textBox1.getText() + " \n DS_1[" + mDimensions + "]  = " + DS_1[mDimensions]);     //output the result from the loop

     }

}

===================


Essentially you are looping through all of the dimensions in the data source and displaying the value for each one. I haven't use Design Studio for more then a month, so my syntax may not be 100% correct.


Pete

Former Member
0 Kudos

Try changing the setFilter function to setVariableExt (But make sure your on 1.5 SP2P1 or 1.6P1 or you might encounter a wild dump). DS will really give you empty or not.

The downside is you'll need to reload the datasource, therefore go back to the database.

0 Kudos

Sorry, I should have mentioned that I'm using DS 1.6, which came out late November 2015. Is there already a service pack for 1.6?

0 Kudos

setVariableExt cannot be used, as this is not a variable in the view. By the way I also tried setVariable.

Former Member
0 Kudos

Can't you add it as optional variable ?

It worked for me.

0 Kudos

I have not been given the authority to modify any of the views that I'm using. There is a team which  is working on this and they are working in a different time zone then me, so they have already started their weekend. Aside from that they have many other changes yet to do to the views, some of which are include fixing broken views (the views cannot be executed via HANA Studio).

TammyPowlas
Active Contributor
0 Kudos

Pete:

I am not following this line:

"if (!DS_1.isResultSetEmpty())"

What purpose does the exclamation point serve?  Or is that a typo?

Former Member
0 Kudos

Tammy: Not

Not(DS_1.isResultSetEmpty)

0 Kudos

Exactly Franck, thanks. You know, I not too sure if "NOT" can be used in BIAL, but that is beside the point. I'm still experiencing this issue of the DS not reporting that it is empty when it is.

Former Member
0 Kudos

Hello,

My guess is you're not using BW but Universes as source right ?

If so, not that, by design by SAP, setFilter return everything if no data. On BW, this unexpected is not here, and the dataset would be empty.

I would suggest to create a separated datasource with aggregated data on with your years and use the getData function to check if you have something meaningfull, and implement your behavior.

We have a incredibly hard time with the setFilter on universes ...

If you're using only charts, you can also use setDataSelection instead , whereas no data will be displayed (but you will not be able to know it ...).

Hope it helps.