Skip to Content
author's profile photo Former Member
Former Member

Update table on certain conditions

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 01:53 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 01:55 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 02:00 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 03:30 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.