cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Executing Dynamic SQL from a Parameterized View in SAP Datasphere

MayuraNalawade
Explorer
0 Likes
514

Hello SAP Community,

I am working with SAP Datasphere and facing challenges executing dynamic SQL statements that are generated and stored in a parameterized view. I wanted to share my problem in detail and clarify the limitations I encountered, in case it helps others.

 

Scenario

I have a parameterized view DQ_RULE_GENERATED_VW that generates SQL statements dynamically based on some input parameters.

The view returns a column called GENERATED_SQL along with other metadata.

MayuraNalawade_0-1763630514847.png

 

My goal is to execute these SQL statements dynamically within SAP Datasphere and capture the results in a table for downstream processing.

 

Challenges

1. Script Operators in Data Flows cannot execute arbitrary SQL:

    • Datasphere Python Script Operators only process DataFrames from upstream sources.
    • You cannot call a parameterized view directly or run SQL dynamically using sql.execute_query inside a Script Operator.

2. Parameterized views cannot be used as sources:

    • Script Operators and many Datasphere operators only accept materialized tables or non-parameterized views.

3. No direct write access to space-owned tables:

    • Even if I fetch results externally (e.g., with a Python script using a HANA connection), I cannot write the results back into Datasphere UI due to lack of privileges on space-owned tables.
    • MayuraNalawade_1-1763630558284.png

       

    • I tried writing a stored procedure that executes the SQL statements dynamically, but it cannot write the results into the target table for the same reason. It seems DML operations can only be performed inside the Datasphere UI, not externally.
    • MayuraNalawade_2-1763630579587.png

       

4. External execution works but is not automated:

  • I was able to fetch the GENERATED_SQL column using an external Python script, execute each statement dynamically, and get the results.
  • However, I cannot send the results back into Datasphere without write access.
  • Exporting results as CSV and manually uploading them is possible, but I would like a fully automated solution without manual steps.

 

Request for Community Input

I would like to know:

  1. Is there a fully supported way in Datasphere to execute SQL dynamically from a parameterized view?
  2. Are there recommended best practices for dynamically executing rules generated from parameterized views in Datasphere, especially when you don’t have write access to space-owned tables?

Any guidance or insights would be greatly appreciated!

Thanks,
Mayura

Accepted Solutions (0)

Answers (0)