Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
thorebedey
Product and Topic Expert
Product and Topic Expert
2,047

Problem description

When integrating data via Remote Table in SAP Datasphere, filtering is limited. The limitations depend on the complexity of the SQL the DPAgent is able to push down to the source. An often seen requirement is to add a filter where the data should be filtered dynamically. This Blog shows a workaround to achieve a dynamic filtering.

For this use case, we use the ABAP Table MSEG which is not delta enabled. The MSEG table contains information about materials whenever a material movement occurs. We want to determine all materials that have a "Best-Before date" which is exactly 200 days in the future. For that, we want to add a dynamic filter on the"Best-Before date" field, which is called "VFDAT". It is being loaded into Datasphere as a String(8) in the format YYYYMMDD.

2024-09-03_11-05-33.png

Inside the remote table itself we can only define a hard filter on a specific date. What we want instead is a dynamic filter so the integrated data changes as time goes on.

1st approach

The easiest approach is to build a view on top of the unpersisted remote table. The SQL can look like this:

 

 

select "MANDT","MBLNR","MJAHR","VFDAT" from QS4_MSEG where "VFDAT" = ADD_DAYS(CURRENT_DATE, 200)

 

 

basicSQLView.png

The result set consists of 3 records. But when looking at the Remote Query of this View, the WHERE clause is not being sent to the source. The we get 3 records in the end but there are 34,516 records moving between the source system and Datasphere. So Datasphere queries the entire dataset and then filters afterwards to show the correct result because it is unable to push the WHERE clause to the source, as it is too complex.

2024-09-03_11-25-32.png

When working with huge amounts of data, we want to limit the amount of data moving between the systems.
For that, we need to find a way to push the WHERE clause to the source.

2nd approach

We can do so by declaring variables in an SQL Script view. The SQL Script can look like this:

 

 

DECLARE myDate DATE = ADD_DAYS(CURRENT_DATE, 200);
DECLARE myDateString NVARCHAR(8) = TO_NVARCHAR(myDate, 'YYYYMMDD');
return select "MANDT","MBLNR","MJAHR","VFDAT" from QS4_MSEG where "VFDAT" = myDateString;

 

 

Instead of trying to push the complex WHERE clause, this script resolves the WHERE clause first when declaring the variable. The result set consist of the same 3 records as before, but when looking at the remote query, we can see that there WHERE clause is being pushed. It cannot visualise the WHERE clause in the remote query, so a "?" is being displayed but we can see in that only 3 records are being pulled.

2024-09-03_13-18-37.png

Conclusion

It is apparent that the query from approach 2 is faster and leaner than the query from approach 1. It is possible that the data volume requires the leanness and pace of approach 2. This seems like a valid workaround for all use cases that depend on a dynamic filtering when integrating data via remote table.

 

8 Comments
Zerosnow
Advisor
Advisor
0 Kudos

OMG..
I've been struggling because I couldn't dynamically execute the filter of the remote table.. I didn't know there was a way like this..
It was a huge help.
I have to let my customer working on the Datasphere project with quickly...

Thanks!

thorebedey
Product and Topic Expert
Product and Topic Expert

@Zerosnow glad i could help 🙂

DirkO
Participant
0 Kudos

Hi Thore,

at least for a HANA backend you can also try to achieve this by changing the connection in DSP from DPA to Cloud Connector.

Br.,

Dirk

chrisesco
Explorer
0 Kudos

Great workaround. thanks.

I tried to check if it worked for me but it did not. I try to push down to a S4HANA CDS. Unfortunately push downs are mostly needed for transactional data.


However this option is very good for master data tables.

thorebedey
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi @DirkO ,

when using a HANA backend you can switch to SDA with the Cloud Connector, correct. Here, you cannot filter in the remote table itself, as that is not supported but at least you dont need the 2nd approach from the blog, 1st approach should be enough to push down the filter.

BR,

Thore

thorebedey
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi @chrisesco ,

for me, approach 2 works for CDS views as well. But for CDS-Views, you can also build in a change data capture (cdc) to load the data with a delta.

BR,

Thore

RG20
Discoverer
0 Kudos

Hi @thorebedey 

Awesome!!!

I tried your approach, and it works for SAP, Oracle, MySQL source systems. But I couldn't make this work when Snowflake is a source. Any idea how to pass the date filter when Snowflake is the source?

Thanks

RG

thorebedey
Product and Topic Expert
Product and Topic Expert

Hi @RG20 ,

sadly i am not sure. Maybe you can test some variances like different data types or expressions to push down.
BR,

Thore