INSERT with SELECT

Index

 

ABAP HANA 7.51: INSERT with SELECT

With new ABAP, it is now possible to INSERT in a database table by SELECTing and INSERTing together in one statement.

  • INSERT statement is followed by an immediate SELECT statement. SELECT statement can be any valid SELECT statement and can vary from a simple select to complex SELECT consists of JOINS and UNIONs.
  • This strategy can reduce database overhead because it hits database once

Sample Source Code:

“Insert from SELECT

INSERT zdemo_table FROM

  (

  SELECT *
FROM 
demo_expressions

  ).


It is evident from the above code that SELECTed data is directly inserted into another table ZDEMO_TABLE!

The SELECT query can be complex and can consist of UNION and JOINS. Number, column sequence and type of column selected should be similar to Table to inserted.

 

Output:

Code inserts all records of table DEMO_EXPRESSIONS to table ZDEMO_TABLE

Index

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s