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: 

Dynamic start where in select hierarchy

BhargavaReddy
Active Participant
0 Kudos
673

Hello Experts,

Would it be possible to write a hierarchy select statement (in ABAP / CDS / CTE) with dynamic start where-conditions?

below is a sample code

    SELECT FROM HIERARCHY( SOURCE demo_cds_parent_child_source
                           CHILD TO PARENT ASSOCIATION _relat
                           START WHERE id = 'A'
                                    OR id = 'D'
                           SIBLINGS ORDER BY id
                           MULTIPLE PARENTS ALLOWED)
           FIELDS id,
                  parent
           INTO TABLE @DATA(asql_result).

Below is the code I'm expecting. But it won't work and shows a syntax error like 'A Boolean expression was expected'

. DATA(lv_where) = | ID = 'A' OR ID = 'D' |.

SELECT FROM HIERARCHY( SOURCE demo_cds_parent_child_source
                           CHILD TO PARENT ASSOCIATION _relat
                           START WHERE(lv_where)
                           SIBLINGS ORDER BY id
                           MULTIPLE PARENTS ALLOWED )
           FIELDS id,
                  parent
           INTO TABLE @DATA(asql_result).

Thank you.

Best Regards,

Bhargava

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos
469

Missing spaces + missing @ ? (NB: parentheses are optional)

WHERE @lv_where 

lenapadeken
Product and Topic Expert
Product and Topic Expert
469

Based on the syntax diagram of START WHERE and testing, it seems that dynamically specified relational expressions cannot be used here.

Sandra_Rossi
Active Contributor
469

Lena is right, only fixed values are permitted, not dynamic values!