cancel
Showing results for 
Search instead for 
Did you mean: 

INSERT and DELETE not actually updating the internal table SAP ABAP.

emilymcox13
Participant

I created an internal table in SAP ABAP using /SE16n, and SELECT command is working perfectly fine, it displays whatever records are in there. But when I use INSERT or DELETE statement, it doesn't actually do anything to the internal table.

Here is my code and screenshot of the internal table after I run.

DATA:
      IS_cus TYPE TABLE OF ZSU_CUSTOMERDATA,
      WA_cus TYPE ZSU_CUSTOMERDATA.

WA_cus-cusid = 6.
WA_cus-cusname = 'Jkl'.
WA_cus-cusemail = 'jkl@gmail.com'.
WA_cus-cusphone = '2345678966'.
WA_cus-cusdob = '19190908'.

INSERT WA_cus INTO IS_cus INDEX 2.

WRITE: / 'ADDED!', / WA_cus-cusid, WA_cus-cusname, WA_cus-cusemail, WA_cus-cusphone.

DELETE IS_cus INDEX 2.

OUTPUT:

INTERNAL TABLE (the data is prefilled and did not updated after execution) :

I don't know what I am missing. any help would be appreciated.

matt
Active Contributor

"I created an internal table in SAP ABAP using /SE16n"
Internal tables and SE16n have nothing to do with other. SE16n is to do with database tables, not internal tables.

Are you sure you're using the correct terminology?

Accepted Solutions (1)

Accepted Solutions (1)

chau1995
Active Participant

Hi,

Because IS_cus doesn't have any row when you initial. So, you can't insert at index 2

Replace by

APPEND WA_cus INTO IS_cus.
emilymcox13
Participant
0 Kudos

Oh okay it worked!

when will insert work? Because my internal table has 3 rows that I populated manually. I thought INSERT would just insert a new row at index 2.

Also, why does this not work?

DELETE IS_cus INDEX2.

Do i have to write a where clause?

DELETE IS_cus WHERE IS_cus-cusid = 1.
Sandra_Rossi
Active Contributor

This one also works on an empty standard internal table:

INSERT WA_cus INTO IS_cus INDEX 1.

These ones also work:

INSERT wa_cus INTO TABLE is_cus.
is_cus = VALUE #( ( wa_cus ) ).

NB: do you really use prefix Hungarian notation? is it really "IS" for internal tables?

Answers (1)

Answers (1)

former_member235395
Contributor

Hi Emily,

Try this:

DATA:
      IS_cus TYPETABLEOF ZSU_CUSTOMERDATA,
      WA_cus TYPE ZSU_CUSTOMERDATA.

WA_cus-cusid =6.
WA_cus-cusname ='Jkl'.
WA_cus-cusemail ='jkl@gmail.com'.
WA_cus-cusphone ='2345678966'.
WA_cus-cusdob ='19190908'.
INSERT WA_cus INTO TABLE IS_cus.
WRITE:/'ADDED!',/ WA_cus-cusid, WA_cus-cusname, WA_cus-cusemail, WA_cus-cusphone.
DELETE IS_cus INDEX 1.

When you want add records on Internal Table, you need to use: append or insert sentences(Check this sentences on Help). Based on your code, WA_CUS structure just will be insert 1 record, so, in your last sentence needs delete the record 1. Now, try this:

DATA:
      IS_cus TYPETABLEOF ZSU_CUSTOMERDATA,
      WA_cus TYPE ZSU_CUSTOMERDATA.

WA_cus-cusid =6.
WA_cus-cusname ='Jkl'.
WA_cus-cusemail ='jkl@gmail.com'.
WA_cus-cusphone ='2345678966'.
WA_cus-cusdob ='19190908'.
INSERT WA_cus INTO TABLE IS_cus.

WA_cus-cusid =6.
WA_cus-cusname ='Jkl'.
WA_cus-cusemail ='jkl@gmail.com'.
WA_cus-cusphone ='2345678966'.
WA_cus-cusdob ='19190908'.
append WA_CUS to IS_cus.
WRITE:/'ADDED!',/ WA_cus-cusid, WA_cus-cusname, WA_cus-cusemail, WA_cus-cusphone.
DELETE IS_cus INDEX 1.
write 1.

Do debug, and check the records number on internal table.

Regards,

emilymcox13
Participant
0 Kudos

I have an internal Table with pre-populated data. It has 3 rows that i manually filled. even then INSERT query didnt work and APPEND works perfectly fine and appends a new row at the end of the table. Also, delete does not work even if i write it as you did,

should i write a where statement in that?

former_member235395
Contributor
0 Kudos

For DELETE sentences, you can use WHERE Option, but for WHERE option, you need specify a field of your Internal Table, but if you use DELETE INDEX, you can specify the ROW on Internal Table.

DELETE IS_CUS where cusid = 6.

Regards,