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

Update database table

Former Member
0 Likes
774

Hi ,

I have a table with 10 fields. 8 of them are key fields. In program when I am trying to update the table it fails.

data: wa_ztable type zsd_table.

update zsd_table from wa_ztable.

the issue is I am not setting all the 8 fields each time. some of the 8 key fields will be blank some time.

What exactly is the issue with this.

Thanks,

Gopi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
746

>

> Hi ,

>

> I have a table with 10 fields. 8 of them are key fields. In program when I am trying to update the table it fails.

>

> data: wa_ztable type zsd_table.

>

> update zsd_table from wa_ztable.

>

> the issue is I am not setting all the 8 fields each time. some of the 8 key fields will be blank some time.

>

> What exactly is the issue with this.

>

> Thanks,

> Gopi

You already know the issue, you have to set all the key fields, i.e if you want to change only one line in the db , otherwise use a where clause if it has to update multiple records.

[See here|http://help.sap.com/erp2005_ehp_04/helpdata/EN/43/41341147041806e10000000a1553f6/frameset.htm]

regards,

Advait

5 REPLIES 5
Read only

Former Member
0 Likes
746

HI,

While updating the database key fields should not be blank. you must pass the key fields.

regards,

S>Chaitanya.

Read only

Former Member
0 Likes
746

what you can do is when you Read the data from the database table. catch the table index (sy-tabix) to some variable and then use that index to update the table.

* your select
lv_tabix = sy-tabix.
update zsd_table from wa_ztable index lv_tabix.

Regards,

Lalit Mohan Gupta.

Read only

Former Member
0 Likes
746

Hi,

Updating multiple entries

Examle updating the field zchecked to 'X'


UPDATE zcostcheck set zchecked = 'X'      
  WHERE zcostcheck-zaar     = zaar and      
                 zcostcheck-zmaaned  = zmaaned and  
                 zcostcheck-zbukrs   = zbukrs and   
                 zcostcheck-zsaknr   = zsaknr2 and  
                 zcostcheck-zgsber   = zgsber.    
if sy-subrc  = 0.
   commit work.
else.
  roll back.
endif.

or try to use modify statement..

  • Read records from the database table where name is space, into an internal table

select * from personal into table itab

where name = space.

  • Update name in the internal table to Unknown

loop at itab.

itab-name = 'Unknown'

endloop.

  • Modify records in the database table. Only records with the same key values as then

  • internal table is modified

MODIFY personel from table itab.

Regards,

prabhudas

Read only

Former Member
0 Likes
746

Gopi,

You can not change the contents of the key fields. If some of them were blank when inserted, they should remain blank. Only non-key field values can be changed.

I believe this is not a restriction placed by the underlying database system, but by ABAP Open SQL engine.

I had a similar requirement in one of my programs. The way I implemented it is to delete the existing record and insert the new record. You have to make sure that there will not be any referential integrity issues.

Read only

Former Member
0 Likes
747

>

> Hi ,

>

> I have a table with 10 fields. 8 of them are key fields. In program when I am trying to update the table it fails.

>

> data: wa_ztable type zsd_table.

>

> update zsd_table from wa_ztable.

>

> the issue is I am not setting all the 8 fields each time. some of the 8 key fields will be blank some time.

>

> What exactly is the issue with this.

>

> Thanks,

> Gopi

You already know the issue, you have to set all the key fields, i.e if you want to change only one line in the db , otherwise use a where clause if it has to update multiple records.

[See here|http://help.sap.com/erp2005_ehp_04/helpdata/EN/43/41341147041806e10000000a1553f6/frameset.htm]

regards,

Advait