01-28-2008 11:28 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.
01-28-2008 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.
01-28-2008 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
01-28-2008 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.
01-28-2008 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.
01-28-2008 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
01-28-2008 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
01-28-2008 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.
01-28-2008 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.
01-28-2008 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