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: 

INSERTING A VALUES IN A DDIC TABLE AT A PARTICULAR INDEX VIA WORKAREA

Former Member
0 Kudos

HI ALL

Can I INSERT a value at a particular index in a DDIC table via a workarea with similar structure.??

like if I have a DDIC table with four feilds and creating a internal table and a workarea with similar structure.

after fetching the values from DDIC table to our internal table and making some changes or wants to insert a values at a particular index. Then Cal I write like:

INSERT WA INTO zMARA INDEX 2.

IS IT WRITE?

OR PLEASE SUGGEST ME THE CORRECT CODE.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

You can insert or rather update the row of table desired by using Primary key combination..

A Db table will have at least one primary key. So first select the desired record to be updated using

unique combination of primary key to get the row you want to modify in work area then change the

value of that field in work are and then use MODIFY db table from workarea.. Remembr you can't change primary key

If key combination is not found in DB table mentioned in work area then it will insert the row in ZABC..

Code..

consider ZABC having 2 fileds AA and BB, then consider AA as primary key.. and BB as normal field..

Consider row having value AA = 1 and BB = 2.

data: wa_ZABC type ZABC.

data: i_zabc type table of zabc with header line.

Select single * from ZABC into wa_zabc where AA = '1'.

wa_zabc-bb = '3'.

modify ZABC from wa_zabc.

if you want to change multiple lines in internal table and then update in DB table then use

Modify ZABC from table i_zabc. after selecting value of zabc in i_zabc and then change

value by loop .. endloop and then apply the Modify statement..

Hope this solves your query..

Regards,

Uday Desai.

6 REPLIES 6

Former Member
0 Kudos

put cursor on INSERT and press F1 or select ABAP help... yes, you can insert...or append and do a sort at the end of the process.

Former Member
0 Kudos

You can insert or rather update the row of table desired by using Primary key combination..

A Db table will have at least one primary key. So first select the desired record to be updated using

unique combination of primary key to get the row you want to modify in work area then change the

value of that field in work are and then use MODIFY db table from workarea.. Remembr you can't change primary key

If key combination is not found in DB table mentioned in work area then it will insert the row in ZABC..

Code..

consider ZABC having 2 fileds AA and BB, then consider AA as primary key.. and BB as normal field..

Consider row having value AA = 1 and BB = 2.

data: wa_ZABC type ZABC.

data: i_zabc type table of zabc with header line.

Select single * from ZABC into wa_zabc where AA = '1'.

wa_zabc-bb = '3'.

modify ZABC from wa_zabc.

if you want to change multiple lines in internal table and then update in DB table then use

Modify ZABC from table i_zabc. after selecting value of zabc in i_zabc and then change

value by loop .. endloop and then apply the Modify statement..

Hope this solves your query..

Regards,

Uday Desai.

0 Kudos

Hi

Thanks a lot for ur help

But I would like to revise the question.

I m not looking for any update or modify the table.

I am looking to insert totaly a new value at a particular index by using work area.

0 Kudos

1. You cannot change the key field values. If you are trying to do so forget about it

2. In the actual DB there is no such thing as index of a particular record. You identify the record using the key fields, once done you can modify that particular record.

BR,

Suhas

0 Kudos

@ Suhas

Hi Suhas

I think u r right, but just tell me if we cannot insert a value on a particular index in a DB table. Then How can v read DB table for a particular index?

As you said, there is no index in DB table and we identify the records from there KEY fields

thanks

Lalit Gupta

0 Kudos

>

> ... Then How can v read DB table for a particular index? ...

What do you mean by this ? And how do you read a DB table based on a "particular index" ?