This website is not affiliated with, sponsored by, or approved by SAP AG.

SQL command as string

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

SQL command as string

Postby Abraxas » Thu Feb 13, 2014 10:26 am

Hello everybody!

I´m wondering if there´s a way to store/generate an SQL command in a string variable and execute it like:

Code: Select all

What, if the SQL command looks something like this?

Code: Select all
SELECT DISTINCT t005t~landx AS val sflconn~countryto AS key
  FROM t005t INNER JOIN sflconn
    ON t005t~land1 = sflconn~countryto
  WHERE t005t~spras = 'EN'
  ORDER BY val.

Using dynamic SQL doesn´t allow this, or am I wrong...?

The work area would then have to be created dynamically - but that´s another problem....
Posts: 4
Joined: Wed Feb 12, 2014 7:13 am

Re: SQL command as string

Postby Grogan » Thu Feb 13, 2014 3:33 pm

You can code it dynamically like this:
SELECT (column_syntax)
FROM (dbtab_syntax)
INTO target
WHERE (sql_cond_syntax)

Each of the variables in parenthesis is a character or string variable or a table containing the equivalent ABAP syntax.

Check out the online help on SELECT - it also includes an example of doing this.

If you need to create the target data area dynamically this is readily done using RTTS classes such as CL_ABAP_STRUCTDESCR and CL_ABAP_TABLEDESCR.

Award cash if useful.
Posts: 365
Joined: Thu Aug 04, 2005 7:16 pm
Location: Australia

Re: SQL command as string

Postby androb » Sun Feb 16, 2014 4:53 pm


Grogan is right, this is possible. Until 7.00 not all syntax variations were accepted thoug. For example, subqueries are not supported. I'm not sure about 7.02 and 7.40.

Posts: 2
Joined: Tue Feb 11, 2014 4:20 am

Re: SQL command as string

Postby foessleitnerj » Wed Mar 05, 2014 11:02 am


Same in 7.02 and 7.40 - Subqueries are still not supported. The only way is to use a abap subroutine pool.


Posts: 2
Joined: Wed Mar 05, 2014 4:41 am

Return to ABAP

Who is online

Users browsing this forum: No registered users and 7 guests

This website is not affiliated with, sponsored by, or approved by SAP AG.