2008 Jan 17 4:32 PM
What should be taken care of for Database updates in ABAP?
2008 Jan 17 4:37 PM
All Database manipulations in SAP (UPDATE, INSERT, DELETE) can be executed one record at a time or through an 'Array' operation.
Example:
No good
LOOP AT T_MAT.
Assign value to material group MARA-MATKL
UPDATE MARA SET MATKL = T_MAT-MATKL.
WHERE MATNR = T_MAT-MATNR.
ENDLOOP.
GOOD
LOOP AT T_MAT.
Assign value to material group MARA-MATKL
ENDLOOP
UPDATE MARA FROM TABLE T_MAT.
After the execution of the array update, the following system fields are populated:
SY-SUBRC - Contains 0 if all updates were successfully executed
SY-DBCNT -Contains the number of successfully updated records
Restrictions:
The Array update function can't be combined with UPDATE SET
Recommendation:
Array updateIf a large number of fields are changed in multiple records
Update setIf a small number of fields are changed in one record
If a small number of fields are changed in multiple records
-> Define a modifiable view using the key fields and the fields which are to be changed
Updating Key fields
Key fields can be updated for transparent tables just like any other table.
Exception:
If synchronous match codes exist for the table, the key field update will be unsuccessful.
2008 Jan 17 4:37 PM
All Database manipulations in SAP (UPDATE, INSERT, DELETE) can be executed one record at a time or through an 'Array' operation.
Example:
No good
LOOP AT T_MAT.
Assign value to material group MARA-MATKL
UPDATE MARA SET MATKL = T_MAT-MATKL.
WHERE MATNR = T_MAT-MATNR.
ENDLOOP.
GOOD
LOOP AT T_MAT.
Assign value to material group MARA-MATKL
ENDLOOP
UPDATE MARA FROM TABLE T_MAT.
After the execution of the array update, the following system fields are populated:
SY-SUBRC - Contains 0 if all updates were successfully executed
SY-DBCNT -Contains the number of successfully updated records
Restrictions:
The Array update function can't be combined with UPDATE SET
Recommendation:
Array updateIf a large number of fields are changed in multiple records
Update setIf a small number of fields are changed in one record
If a small number of fields are changed in multiple records
-> Define a modifiable view using the key fields and the fields which are to be changed
Updating Key fields
Key fields can be updated for transparent tables just like any other table.
Exception:
If synchronous match codes exist for the table, the key field update will be unsuccessful.