Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

insert statement

Former Member
0 Likes
766

hi,

Can we insert a single line from the database table(ex: lfa1) into an internal table body, if yes then what is the syntax 4

that paticular insert statement.

thanks.

5 REPLIES 5
Read only

Former Member
0 Likes
714

Hi,

Inserting a Single Line

To insert a single line into a database table, use the following:

INSERT INTO <target> VALUES <wa> .

The contents of the work area <wa> are written to the database table <dbtab>. The work area <wa> must be a data object with at least the same length and alignment as the line structure of the database table. The data is placed in the database table according to the line structure of the table, and regardless of the structure of the work area. It is a good idea to define the work area with reference to the structure of the database table.

If the database table does not already contain a line with the same primary key as specified in the work area, the operation is completed successfully and SY-SUBRC is set to 0. Otherwise, the line is not inserted, and SY-SUBRC is set to 4.

You can also insert single lines using the following shortened form of the INSERT statement:

INSERT <target> FROM <wa >.

Using FROM instead of VALUE allows you to omit the INTO clause. Shorter still is:

INSERT <dbtab>.

In this case, the contents of the table work area <dbtab> are inserted into the database table with the same name. You must declare this table work area using the TABLES statement. In this case, it is not possible to specify the name of the database table dynamically. Table work areas with the same name as the database table (necessary before Release 4.0) should no longer be used for the sake of clarity.

Hope this helps u,

Regards,

Arunsri

Read only

Former Member
0 Likes
714

hi,

if ur internal table already has data then

SELECT single *

INTO int

FROM zark_alv_test

where employee = 'XYZ'.

append int.

here the data from database will be the last record in the table

LOOP AT int.

write : / int-employee.

endloop.

i.e.

if ABC is already present in the table and after ur selct query and append stmt XYZ is coming into the table

your output of loop stmt will be

ABC

XYZ.

reward points if useful and mark the post answered once u get the answer...........

Read only

Former Member
0 Likes
714

HI,

DATA: t_lfa1 type table of lfa1.

  • yadda yadda code to fill your internal table

SELECT *

APPENDING TABLE t_lfa1

FROM lfa1

WHERE yadda yadda.

IF sy-subrc NE 0.

*more yadda

ENDIF.

You also can use a workarea to make the insert without a direct input from the DB:

DATA: t_lfa1 TYPE TABLE OF lfa1,

w_lfa1 TYPE lfa1.

  • yadda yadda code to fill your internal table

SELECT SINGLE *

INTO w_lfa1

FROM lfa1

WHERE yadda yadda.

IF sy-subrc NE 0.

*more yadda

ENDIF.

INSERT w_lfa1 TO t_lfa1.

Cheers,

Chandra Sekhar.

Read only

Former Member
0 Likes
714

Hi,

data : i_mara like mara occurs 0 with header line.

SELECT single *

INTO Table i_mara

FROM mara

where matnr = xxxx -


write you conditions here.

pls. rewar if useful..

Read only

0 Likes
714

hi,

sry but the select query given by u will give error

coz

select single *

cant be used with INTO TABLE......