Application Development and Automation 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: 
Read only

how to write SQL statement for EXEC with multiple select-options as condition

former_member625844
Participant
0 Likes
1,243

we have a program with three select-options S1,S2,S3. All of them are not obligatory. Now I want to connect to an oracle DB and fetch data with these select-options as condition.

The code is like:

EXEC SQL.
    select * into :WS from ODB 
    where o1 between s1-low and s1-high
    and o2 between s2-low and s2-high
    and o3 between s3-low and s3-high
ENDEXEC.

My question is if user did not input value for selection options, how to let it work? Suppose S2 is empty, I tried to assign s2-low and s2-high value of '%' but it didn't work. Thx.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
1,008
  1. Don't use EXEC SQL. Use the CL_SQL_STATEMENT classes
  2. There is a class method that converts select options. Read all about it here: https://blogs.sap.com/2015/03/30/handling-of-select-options-parameters-within-amdp/ (The blog is AMDP, but it still applies).
1 REPLY 1
Read only

matt
Active Contributor
1,009
  1. Don't use EXEC SQL. Use the CL_SQL_STATEMENT classes
  2. There is a class method that converts select options. Read all about it here: https://blogs.sap.com/2015/03/30/handling-of-select-options-parameters-within-amdp/ (The blog is AMDP, but it still applies).