on 09-27-2020 12:32 AM
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.