Q
Problem solve Get help with specific problems with your technologies, process and projects.

Dynamically create the where clause of a select statement

Ideas for creating the where clause of a select statement.

I would be very grateful for your help. I want to dynamically create the where clause of a select statement. I...

am able to do it when the actual where clause is static but it fails when using results from an internal table.

* define the internal table which will
* hold the where clause
data w_clause_b(80) occurs 10 with header line.

data : count_rec type i.

* select the transaction which will be * used in the select statement
select-options: s_trx for tstc-tcode no intervals obligatory
default 'va01'.

move 'tcode in s_trx' to where_tab.
append where_tab
clear where_tab.

SELECT COUNT( * ) INTO COUNT_REC
FROM ZALEPRSTAT
WHERE STARTDATE GE RAW_DATE_FR
AND STARTDATE LE RAW_DATE_TO
AND (WHERE_TAB).

It works when I use:
concatenate 'tcode =' '''VA01''' into where_tab separated by space.

I have also tried various combinations including:
concatenate 'tcode in' s_trx into where_tab separated by space.

I can't tell why yours isn't working! I've created the following small program which does pretty much what yours does and it works fine.

TABLES: tstc.

DATA where_tab(80) OCCURS 10 WITH HEADER LINE.
DATA : count_rec TYPE i.

SELECT-OPTIONS: s_trx FOR tstc-tcode NO INTERVALS OBLIGATORY
DEFAULT 'va01'.

MOVE 'tcode in s_trx' TO where_tab.
APPEND where_tab.
CLEAR where_tab.
SELECT COUNT( * ) INTO count_rec
FROM tstc.
WHERE (where_tab).
WRITE: count_rec.

This was last published in July 2006

Dig Deeper on SAP interface technologies

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close