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

Can we use insert command with a where clause.

former_member130219
Participant
0 Likes
4,810

Hi

I am trying to insert data from a work area into an internal table using a where condition.

And facing a error in using this .the error says :

".", "INDEX numlike-field", "ASSIGNING <fs>", "REFERENCE INTO

data-reference", or "ASSIGNING <fs> CASTING" expected after "IT_SCARR".

my code is:

insert wa_scarr into table it_scarr where it-scarr-carrid = 'AA'.

please help.

Thank u in advance.

Regards.

Abhinandan.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,421

Hello,

Its not correct,

Try this

first loop the internal table which contains the data and move to the work area keep where condition wa_scarr = 'AA' then append to the internal table ie. append wa_scarr into it_scarr.

Hi

I am trying to insert data from a work area into an internal table using a where condition.

And facing a error in using this .the error says :

".", "INDEX numlike-field", "ASSIGNING <fs>", "REFERENCE INTO

data-reference", or "ASSIGNING <fs> CASTING" expected after "IT_SCARR".

my code is:

insert wa_scarr into table it_scarr where it-scarr-carrid = 'AA'.

please help.

Thank u in advance.

Regards.

Abhinandan.

6 REPLIES 6
Read only

Former Member
0 Likes
2,421

HI,

You cannot use Where Clause with INSERT Statement.

http://help.sap.com/saphelp_46c/helpdata/en/34/8e72c56df74873e10000009b38f9b8/content.htm

You need read the internal table and get the index where to insert.

READ TABLE ITAB WITH KEY carrid = 'AA'.
IF SY-SUBRC EQ 0.
insert wa_scarr into table it_scarr index sy-tabix.
ENDIF.

Read only

Former Member
0 Likes
2,422

Hello,

Its not correct,

Try this

first loop the internal table which contains the data and move to the work area keep where condition wa_scarr = 'AA' then append to the internal table ie. append wa_scarr into it_scarr.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
2,421

Hi,

Insert command is to create a new line in the internal table.

If you want to change a line, use update statement.

If you are not sure about changing/inserting, use modify statement.

Use F1 help for syntax.

Read only

Former Member
0 Likes
2,421

Hi

'Where' Condition cannot be used along with Insert statement .

instead you can use

1. INSERT (wa INTO|INITIAL LINE INTO) itab (INDEX

idx) (ASSIGNING <fs>|REFERENCE INTO dref).

2. INSERT (wa INTO|INITIAL LINE INTO) TABLE itab

(ASSIGNING <fs>|REFERENCE INTO dref).

3. INSERT LINES OF itab1 (FROM idx1] [TO idx2)

INTO itab2 (INDEX idx3).

4. INSERT LINES OF itab1 (FROM idx1) (TO idx2)

INTO TABLE itab2.

you can also check the keyword help document or if you want to know how they inserted the data with sample codes,

check the tcode - ABAPDOCU. U can find lot of sample codings.

Read only

Former Member
0 Likes
2,421

Hi..

ur code is not correct..

in place of : insert wa_scarr into table it_scarr where it-scarr-carrid = 'AA'.

Try Following Code :

But before following code data (single record) must be there in wa_scarr.



if wa_scarr-carrid eq 'AA'.

       append wa_scarr into it_scarr.

endif.

Hope this helps..

Regards,

Chintan.

Read only

former_member130219
Participant
0 Likes
2,421

Thank you for the answers.

Regards

Abhinandan Kumar