Friday, October 14, 2011

SE14: Database Utility Tool

If you are skeptical about altering transparent tables that already has data in it, then it is better to familiarize yourself with Database Utility tool (SE14). The alteration can be in the form of addition of new fields, change in field length, etc. Lets see how SAP alters table at database level.

Database Utility Tool: Transaction Code - SE14
When a table is created in SE11(ABAP Dictionary) upon activation of table definition, SQL statements are generated and sent to the RDBMS causing it to create an actual table in database. Database Utility Tool  is an interface between the ABAP Dictionary and underlying relational database system (RDBMS). It is used to examine or modify tables at database level.

When a transparent table is altered (standard/custom), it is first adjusted via SE14 and then activated. What exactly happens at database level, how a table is adjusted, what happens to table contents,.... is what we are going to unleash in following section!

Table Activation and Adjustment:
When you adjust table via SE14. It offers two adjustment options - Delete Date and Keep Data. 
Delete Data: Table is deleted in database and re-created with new definition. Data is lost.
Keep Data: ALTER TABLE is performed, if not possible then table conversion is triggered.

Say for instance we have changed a table(TAB) field's length from 50 to 25 then the steps performed to adjust database table (referred as TAB) with Keep Data option is as follows:

  1. Table (TAB) is locked. All the views that used table TAB are deleted
  2. TAB is renamed as QCMTAB in database
  3. TAB is activated in ABAP Dictionary with new definition. Activation of modified table TAB leads to creation of database table QCM8TAB in database with primary key but no data.
  4. Reload data -  data copied from QCMTAB to QCM8TAB (with MOVE-CORRESPONDING statement). Database commit is stored after 16MB. If a field length is reduced then field contents are truncated.
  5. Delete QCMTAB table
  6. Rename  QCMTAB to TAB. Secondary indexes are newly created and views deleted in Step 1 are re-created
  7. Remove Lock from TAB
This is how a database table is altered in SAP. It is evident that addition of fields or increasing field length doesn't corrupt table contents though reducing field size might lead to truncated field value and hence corrupt data.

No comments:

Post a Comment