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: 

Update table on certain conditions

Former Member
0 Kudos
1,069

Hi Guys,

I have the following condition i have to update the DB table from the Internal table but i will be having only 4 fields to update from Internal table depending on the match on the first field that is the key field. Its urgent and its a small query..

Thanks,

David.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
916

Hi david,

1. i will be having only 4 fields to update from Internal table depending on the match on the first field that is the key field

Use this kind of logic.

LOOP AT ITAB.

CLEAR WORKAREA.

select single * from DBTAB

INTO WORKAREA

where primarykey = itab-field1.

if sy-subrc = 0.

WORKAREA-FIELD1 = ITAB-FIELD1.

WORKAREA-FIELD2 = ITAB-FIELD2.

WORKAREA-FIELD3 = ITAB-FIELD3.

WORKAREA-FIELD4 = ITAB-FIELD4.

MODIFY DBTAB FROM WORKAREA

ENDIF

ENDLOOP.

regards,

amit m.

5 REPLIES 5

Former Member
0 Kudos
917

Hi david,

1. i will be having only 4 fields to update from Internal table depending on the match on the first field that is the key field

Use this kind of logic.

LOOP AT ITAB.

CLEAR WORKAREA.

select single * from DBTAB

INTO WORKAREA

where primarykey = itab-field1.

if sy-subrc = 0.

WORKAREA-FIELD1 = ITAB-FIELD1.

WORKAREA-FIELD2 = ITAB-FIELD2.

WORKAREA-FIELD3 = ITAB-FIELD3.

WORKAREA-FIELD4 = ITAB-FIELD4.

MODIFY DBTAB FROM WORKAREA

ENDIF

ENDLOOP.

regards,

amit m.

Former Member
0 Kudos
916

Hi David,

This should work for updating the DB table.

UPDATE ztable SET: firstfield = '003',

secondfield = '0621/444444'

thirdfield = '0621/4444'

fourthfield = '0621/44'

WHERE primaryfield = '00017777'.

Regards,

Vicky

PS: Award points if helpful

Former Member
0 Kudos
916

Hi David

Loop at itab into wa_itab

update dbtbase set f1 = wa_itab-f1

f2 = wa_itab-f2

f3 = wa_itab-f3

f4 = wa_itab-f4

where key field = wa_itab-keyfield

Endloop.

commit work.

Award points if helpful

0 Kudos
916

Hi there,

Its working for me but my only concern is i will have nearly 4000 records to update..So will it be a performance issue to loop thru them??..

Thanks in advance,

David.

Former Member
0 Kudos
916

If there are only 4000 records it will not be a problem.

Just make sure that the <b>COMMIT WORK</b> is outside the loop so that the database is not updated inside the loop.