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

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

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

thanks

swaroop

5 REPLIES 5

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I would suggest NOT to try to update standard SAP tables. This is a pretty solid rule when it comes to customers writing custom programs. Instead you should use delivered APIs such as bapis. In your case, you should use the BAPI to change the material. The BAPI name is BAPI_MATERIAL_SAVEDATA

Regards,

Rich Heilman

Former Member
0 Kudos

Hi,

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

thanks

swaroop

Former Member
0 Kudos

Hi,

s u can..

declare the itab like makt table

data itab like table of makt with header line.

fill the itab (with the data u need to update).

now u can do it in two ways

modify/update makt from table itab. (updating at a strech).

or

loop at itab.

modify/update makt from itab.

endloop. (one by one here after each update u can check sy-subrc value if u need)

see the diff b/w modify & update in sap lib....

Cheers,

Will.

Former Member
0 Kudos

Hi,

it may help u.

We cant do changes directly on standard sap tables .so that make a copy of the table and try to do .

Views are based on the material type and so depending on the material type of your material, you can create certain views for a material.

If a view is allowed for a material type, you have to create the view using MM01, not MM02 even if it is an existing material. This is called extending the material as opposed to changing the material.

Go to SPRO and follow the path

SAP Customizing Implementation Guide

-->Logistics - General

-->Configuring the Material Master

-->Basic Settings

-->Material Types

-->Define Attributes of Material Types

If you pick the material type of the material that you are trying to extend, you will find the views that are allowed under "User Departments".

You can change material type using tcode MMAM.

regards,

vasavi.

kindly reward if helpful.

Former Member
0 Kudos

Hai.

U can updatethe standard table from your program.

Your code is also correct but make sure the structure of your internal table and workarea and table should be same .

(itab type table of table name with headerline.

wa type tablename ).

make sure whether you want to update the existing contents use update or you want to add records use modify.

Regards.

Sowjanya.b.