2010 Nov 07 11:56 AM
Dear all,
I've a question about SQL WITH AS clause and I would like to know whether something similar exists in ABAP programming language. When I use oracle, I can run the following
WITH MYTEMPTBL AS
(
SELECT 'a1' AS cola, 'b1' AS colb, 'c1' AS colc FROM DUAL UNION
SELECT 'a2' AS cola, 'b2' AS colb, 'c2' AS colc FROM DUAL UNION
SELECT 'a3' AS cola, 'b3' AS colb, 'c3' AS colc FROM DUAL UNION
SELECT 'a4' AS cola, 'b4' AS colb, 'c4' AS colc FROM DUAL UNION
SELECT 'a5' AS cola, 'b5' AS colb, 'c5' AS colc FROM DUAL UNION
SELECT 'a6' AS cola, 'b6' AS colb, 'c6' AS colc FROM DUAL UNION
SELECT 'a7' AS cola, 'b7' AS colb, 'c7' AS colc FROM DUAL
)
SELECT *
FROM MYTEMPTBL;
COLA COLB COLC
----- ------ ------
a1 b1 c1
a2 b2 c2
a3 b3 c3
a4 b4 c4
a5 b5 c5
a6 b6 c6
a7 b7 c7
7 lines returned
SQL>
So I don't need to define a table by CREATE TABLE statement and then write several INSERT statements, I can just define a table dynamically for my sql query.
If I want to do the same thing in ABAP, first I define a structure type with three entries (cola, colb and colc) and a standard (internal) table of type of this structure. Finally I define a variable of type of structure and I assign for each of the above mentioned rows in my example, the entries of the structure followed by an INSERT into my defined internal table variable.
Is there an easier way to do this in ABAP? I mean without needing to write INSERT several times and define several types?
Thanks in advance,
Kind Regards,
Dariyoosh
2010 Nov 07 12:04 PM
Hi
No, but you can try to use the native SQL in order to replace the same statament
Max
2010 Nov 07 12:16 PM
Hello there,
Thanks for your help
No, but you can try to use the native SQL in order to replace the same statament
I'm sorry, I didn't understand what do you mean.
2010 Nov 07 12:43 PM
Hi
I don't know exactly what your code does, so it's hard to indicate an alternative in ABAP: can you explain it to me?
Anyway In abap it's possible use an SQL statament native of the database used (I suppose ORACLE in your case), it's usually used in prgram based on a DBLINK, in this situation it can use the SQL supported by database called, but it can use internally in SAP.
See the help for EXEC SQL/ENDEXEC.
EXEC SQL.
+------> Here native sql statament
ENDEXEC.
The abap skips the syntax error check for the code into EXEC SQL/ENDEXEC, it can realize an error at runtime only
Max
2010 Nov 07 12:45 PM
I think you want to fetch records and display them. If right then we have internal tables.
Nabheet
2010 Nov 08 7:38 AM
>
> If I want to do the same thing in ABAP, first I define a structure type with three entries (cola, colb and colc) and a standard (internal) table of type of this structure. Finally I define a variable of type of structure and I assign for each of the above mentioned rows in my example, the entries of the structure followed by an INSERT into my defined internal table variable.
>
> Nabheet
insted of this u can directly create internal table and fetch data in to it directly...
or insert data in to it....
2010 Nov 08 8:19 AM
I meant the same thing structure means types in program only.
Thanks
Nabheet