on 2022 Feb 16 8:13 PM
I am in the process of rewriting some queries in SAP and discovered select into. Not sure where it would help as many queries are over 10 years old.
Request clarification before answering.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jonathan,
It is important to understand that there are two types of temporary table:
Both types have their own pros and cons. SELECT INTO only works with #Table. The main advantage of SELECT INTO is that you do not need to declare/create the temporary table first. The SELECT clause will determine the fields and data types in the temporary table.
So for example:
SELECT i.ItemCode INTO #ITEMCODES
FROM OITM i
WHERE i.ItmsGrpCod = 10Will create a temporary table with field ItemCode NVARCHAR(50), and fill this table with all ItemCodes from Item Group 10.
Next I can use this temporary table in a followup query:
SELECT c.CardCode, c.CardName, cat.Substitute
FROM OCRD c
INNER JOIN OSCN cat ON c.CardCode = cat.CardCode
WHERE cat.ItemCode IN (select * from #ITEMCODES)Alternatively you could use the temporary table in another application all together, as it is written to disk, and thus available to any application that has access to the database.
However, every time you run the query, you will need to drop the temporary table or empty it.
You can do the same thing with a table in memory, but it is more complicated:
DECLARE @ITEMCODES TABLE (ItemCode NVARCHAR(50))
INSERT INTO @ITEMCODES (ItemCode)
(SELECT i.ItemCode
FROM OITM i
WHERE i.ItmsGrpCod = 10)
The @ITEMCODES table can then be usd in a followup query in the same manner, but it cannot be used outside the scope of this query.
Regards,
Johan
Hi,
INTO used to insert data from one table or multiple into temporary table for easy joining of tables.
Regards,
Nagarajan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Tcode ABAPDOCU may helpful for this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 31 | |
| 17 | |
| 16 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.