Application Development 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: 

Can we use insert command with a where clause.

former_member130219
Participant
0 Kudos

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

Former Member
0 Kudos

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.

6 REPLIES 6

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

jayanthi_jayaraman
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

former_member130219
Participant
0 Kudos

Thank you for the answers.

Regards

Abhinandan Kumar