SQL command as string

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
Abraxas
Posts: 4
Joined: Wed Feb 12, 2014 7:13 am

SQL command as string

Post by 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

SELECT (sql_string) INTO CORRESPONDING FIELDS OF wa.
...
ENDSELECT.
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....

Grogan
Posts: 365
Joined: Thu Aug 04, 2005 7:16 pm
Location: Australia

Re: SQL command as string

Post by 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.
Grogan

Award cash if useful.

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

Re: SQL command as string

Post by androb » Sun Feb 16, 2014 4:53 pm

Hi,

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.

Regards,
Andy

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

Re: SQL command as string

Post by foessleitnerj » Wed Mar 05, 2014 11:02 am

Hi!

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

Regards,

Johann

Post Reply