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

How to update a standard table

Hi all,

I want to update table makt with a program from table itab.

Loop at itab into wa.

modify makt from wa.

endloop.

I even can not debug the loop...

Is it not possible to update sap tables?

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 11:34 AM

    You can definitely modify Standard Database table from ABAP Program.

    1.Syntax for modifying Database table from Workarea is,

    MODIFY dbtab FROM workarea.

    Effect

    When a wa work area that is not table-type is specified, which meets the requirements for use in Open SQL statements, a line is searched for in the database table that has the same content in the primary key as the corresponding beginning part of the work area.

    If such a line is not found, a new line is inserted according to the same rules as for the INSERT statement.

    If such a line is found, this line is overwritten according to the same rules as for the UPDATE statement.

    If the change would lead to a double entry in a unique secondary index, then it is not executed and sy-subrc is set to 4.

    Notes

    The wa work area should always be declared with reference to the database table or the view in the ABAP Dictionary.

    If the the database table or view is specified statically, then you the specification of the work area using FROM wa can be ommitted outside of classes if a dbtab table work area is declared for the corresponding database table or for the view using the TABLES statement. The system enhances the MODIFY statement implicitly with the FROM dbtab addition.

    Eg. :

    DATA message_wa TYPE t100.

    message_wa-sprsl = 'EN'.

    message_wa-arbgb = 'MYMSGCLASS'.

    message_wa-msgnr = '100'.

    message_wa-text = 'Some new message ...'.

    MODIFY t100 FROM message_wa.

    2. Syntax for changing Database table from internal table is ,

    MODIFY dbtab FROM TABLE itab.

    Effect

    If an itab internal table is specified, the system processes all lines in the internal table according to the rules for the wa work area. The line type of the internal table has to meet the requirements for use in Open SQL statements.

    If the change to a line in the internal table would lead to a double entry in a unique secondary index, the corresponding line is not inserted and sy-subrc is set to 4. If the internal table is empty, sy-subrc is set to 0. The sy-dbcnt system field is always set to the number of lines that were actually processed

    Reward if helpful.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 28, 2008 at 11:33 AM

    hi Deniz,

    you can do without LOOP, this will update in single lines (from the internal table) in one go:

    UPDATE makt FROM TABLE itab.

    hope his helps

    ec

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 11:38 AM

    HI

    you can update the standard sap tables by small report program

    modifying datbase table useing internal table

    advises before updating this datbase table plz lock that table to avoid incosistency

    write the logic for modifying

    Modify the database table as per new dunning procedure

    MODIFY fkkvkp FROM TABLE lt_fkkvkp .

    and finally unlock the table

    example

    *To lock table for further operations

    constants: lc_tabname TYPE rstable-tabname VALUE 'FKKVKP' . "FKKVKP

    CALL FUNCTION 'ENQUEUE_E_TABLE'

    EXPORTING

    tabname = lc_tabname

    EXCEPTIONS

    foreign_lock = 1

    system_failure = 2

    OTHERS = 3.

    IF sy-subrc EQ 0.

    To fetch all the contract accounts for customers of the segment

    Households/SME.

    PERFORM fetch_contract_accounts using lc_tabname .

    ENDIF. " IF sy-subrc EQ 0.

    *wrote the logic

    Modify the database table as per new dunning procedure from internal table

    MODIFY fkkvkp FROM TABLE lt_fkkvkp .

    *unlock the tbale

    CALL FUNCTION 'DEQUEUE_E_TABLE'

    EXPORTING

    TABNAME = uc_tabname .

    Reward Points if found helpfull..

    Cheers,

    Chandra Sekhar.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 28, 2008 at 11:38 AM

    Prerequisites.

    Is the WA same structure as MAKT?

    May be, there is no match for the MATNR in the table and the matnr in the itab. Check the leading zeroes in the matnr field of the ITAB.

    But why do you want to update standard tables?

    Standard tables are never meant to be updated using custom programs.

    Regards,

    Ravi Kanth Talagana

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 11:39 AM

    Of course, we can upadte the standard table using the UPDATE statement from ani WORK AREA.

    But it is strongly recommended that we should not update the standard tables directly.

    If u do so, only onle table will be updated, all other related tables won't get updated.

    So, u have to use Transaction (BDC) or FM (BAPI) to update the standard tables.

    Do not update by writing a UPDATE query.

    Narendra

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 11:40 AM

    Hi all,

    I want to update table makt with a program from table itab.

    Loop at itab into wa.

    modify makt from wa.

    endloop.

    I even can not debug the loop...

    Is it not possible to update sap tables?

    Thanks.

    Ofcourse. You can modify SAP standard tables also.

    The above code should work and is possible to debug also.

    the problem may be because of your debugger settings.For more better performance you can use the code-

    modify makt from table itab.

    but the itab should have the same structure as makt.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 11:41 AM

    Hi,

    u can use update/modify syntax

    update updates the DB table ie if only a record exists in ur DB tab with same Key....

    modify does as update but creates a record if there is no record with the same key(key fields).

    use this syntax

    update/modify makt from table itab.

    ( this happens only if itab has same structure dat of makt)

    Cheers,

    Will.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 12:00 PM

    Hi

    Try to find a Fm or BAPI.

    or update using BDC.

    It is not recommended to update the master tables using the UPDATE INSERT OR MODIFY.

    the changes wont reflect in rel;ated tables

    Try to use BDC for the same

    Regards

    Shiva

    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.