Sei sulla pagina 1di 16

Changes to Database Tables

Audio Transcript
ABAP programs can only access a database table correctly if the runtime object
of the table is consistent with the structure of the table in the database. Each
time the table is changed in the ABAP Dictionary, the system checks during the
activation (when the runtime object is updated) whether it has to adjust the
database object to the changed ABAP dictionary definition of the table.
The database structure does not have to be changed for certain changes to the
ABAP Dictionary. For example, you do not have to change the database
structure when the order of the fields (except key fields) in the ABAP Dictionary
is changed. In this case, the changed structure is activated in the ABAP
Dictionary and the database structure remains unchanged.

Structure Adjustment in the ABAP Dictionary


Audio Transcript

The database table can be adjusted to the changed definition in the ABAP
Dictionary in the following ways:

 By deleting the database table and creating it again. The table in the
database is deleted, the inactive table is activated in the ABAP Dictionary,
and the table is created again in the database. The existing data in the table
is lost.
 By changing the database catalog ALTER TABLE. The definition of the table
in the database is simply changed. The existing data is retained. However,
indexes of the table may have to be built again.
 By converting the table. This is the most time-consuming way of adjusting a
database table.
If the table does not contain any data, it is deleted from the database and
created again with its new structure. If data exists in the table, the system
attempts to adjust the structure with ALTER TABLE. If the database system
used is not able to do so, the structure is adjusted by converting the table.
The Table Conversion Process

Audio Transcript

The following example illustrates the steps carried out by the system
during a conversion:

 Starting situation
The table TAB was changed in the ABAP Dictionary. The length of field 3
was reduced from 60 to 30 places.
As a result, the ABAP Dictionary has an active (field 3 with a length of 60
places) and an inactive (field 3 with a length of 30 places) version of the
table.
The table in the database corresponds to the active version in the ABAP
dictionary, which means that field 3 currently has 60 places in the database.
A secondary index with the ID A11, which was also created in the database,
is defined for the table in the ABAP Dictionary.
The table already contains data.
Conversion Process 2

Audio Transcript

The following steps are illustrated in figure “Conversion process 2”:

 Step 1
The table is locked to prevent further structure changes. If the conversion
terminates due to an error, the table remains locked. Before the conversion
is completed correctly, this lock mechanism prevents any further structure
changes which may lead to loss of data. Moreover, all views dependent on
the table are inactivated and therefore blocked.

 Step 2
The database table TAB is renamed QCMTAB. The new name of the table
is defined by the prefix QCM and the original table name TAB. During the
renaming all secondary indexes of the table are deleted.
Conversion Process 3

Audio Transcript

The following steps are illustrated in figure “Conversion process 3”:

 Step 3
The inactive version of table TAB is activated in the ABAP Dictionary. The
table is created in the database as table QCM8TAB with the new structure
and a primary index. After this step, the database contains the following
tables:

 Table QCMTAB with the old structure. This table contains the business
data.
 Table QCM8TAB with the new structure. This table is empty.
Caution: The table does not exist in the database with its original name during
conversion. As the programs that access this table cannot be executed, make
sure that no applications access the table to be converted during conversion.
Conversion Process 4

Audio Transcript

The following steps are illustrated in figure “Conversion process 4”:

 Step 4
The data is loaded back from table QCMTAB to table QCM8TAB. The
conversion is done using statement MOVE-CORRESPONDING.
Both tables contain the data after this step. If you reduce the size of the
fields, for example, the extra places are truncated when you reload the data.
Since the data is in both tables QCM8TAB and QCMTAB during the
conversion, there are greater storage requirements. Before converting large
tables, therefore, you should check whether sufficient space is available in
the corresponding tablespace.
A database commit is performed after 16 MB when you copy the data from
table QCMTAB to table QCM8TAB. A conversion process therefore needs
16 MB of resources in the rollback segment. The existing database lock is
released with the Commit and then requested again before the next data
area to be converted is edited.
When you reduce the size of keys, only one record can be reloaded if there
are several records whose key cannot be distinguished. It is not possible to
say which record this will be. In this case, you should clean up the data in
the table before converting it.
Conversion Process 5

The following steps are illustrated in figure “Conversion process 5”:

 Step 5
Table QCMTAB is deleted.

 Step 6
Table QCM8TAB is renamed to TAB. The secondary indexes defined in the
ABAP Dictionary for the table are created again. The views on the table that
we deactivated in the first step of the conversion are reactivated in the
database.

 Step 7
The lock set at the beginning of the conversion is removed.
Conversion Errors
During a conversion, the data is copied back to the database table from the
temporary table with the ABAP statement MOVE-CORRESPONDING. This
means that only those type changes that can be executed with MOVE-
CORRESPONDING are allowed. All other type changes cause the conversion
to be terminated when the data is loaded back to the original table. In this case,
you have to recreate the old state prior to conversion. Using database tools, you
have to delete the table, change the name of the QCM table to its old name,
reconstruct the runtime object in the database utility, set the table structure in
the ABAP Dictionary back to its old state, and then activate the table.
Audio Transcript
As the data exists in both the original and temporary tables during conversion,
the storage requirements increase. If the tablespace overflows when you reload
the data from the temporary table, the conversion terminates. In this case, you
must extend the tablespace and start the conversion in the database utility
again.
If you shorten the key of a table (for example, when you remove a key field or
shorten the field length of key fields), this may result in duplicate records with
the same key. When you reload the data from the temporary table, only one of
these duplicate records can be loaded back to the table. It is not possible to
predict which record is loaded back to the table. If you want to copy certain
records, you have to clean up the table before the conversion.

Resuming Terminated Conversions

If a conversion terminates, the following options are displayed as


pushbuttons in the database utility:

 Continue adjustment
After correcting the error, you can resume the conversion where it
terminated with the Continue adjustment pushbutton.

 Unlock table
The Unlock table pushbutton deletes only the existing lock entry for the
table. You should never choose Unlock table for a terminated conversion if
the data exists only in the temporary table, for example, if the conversion
terminated in Step 3 or 4.
Audio Transcript

If a conversion terminates, the lock entry for the table set in step 1 of the
conversion process is retained. The table cannot be edited anymore with the
maintenance tools of ABAP Dictionary (Transaction SE11).
A terminated conversion can be analyzed with the database utility (Transaction
SE14) and then resumed. The database utility provides an analysis tool that you
can use to find the cause of the error and the current state of all the tables
involved in the conversion.
You can usually find the precise reason for the termination in the object log. If
the object log does not provide any information about the cause of the error,
you have to analyze the System Log (transaction SM21) or the ABAP Dump
Analysis (transaction ST22).

Enhancement of SAP Standard Tables


Audio Transcript

Append structures allow you to append fields to standard SAP tables and
structures without modifying the table definition.
An append structure is a structure that is assigned to exactly one table. There
can be several append structures for a table.
When a table is activated, all the active append structures for the table are
found and their fields are appended to the table. If an append structure is
created or changed, the table to which it is assigned is also activated.
Like all structures, an append structure defines a type that can be used in ABAP
programs.
As of Release 4.6C, you can define foreign keys for fields that already exist in
the table using an append structure. Search helps can also be attached to fields
that already exist in the table.
Hint: If you copy a transparent table in the ABAP Dictionary to which an append
structure has been added, the fields of the append structure are converted to
normal table fields.
Append Structures 2

Audio Transcript

Customers create append structures in their namespace. The append


structures are thus protected against overwriting during an upgrade.
The new versions of the standard tables are imported during the upgrade.
When the standard tables are activated, the fields contained in the active
append structures are appended to the new standard tables. When append
structures are added to a table, you do not have to manually adjust the
customer modifications to the new SAP version of the table (transaction SPDD)
during the upgrade.
As the order of the fields in the ABAP Dictionary can differ from the order on the
database, a conversion is not necessary when you add an append structure or
insert fields in an existing append structure. The structure is adjusted when the
database catalog is adjusted (ALTER TABLE). When you activate a structure in
the ABAP Dictionary, the definition of the table is changed and the new field is
appended to the database table.
Append Structures 3

Audio Transcript

The new version of the standard SAP table is activated and the new field is
appended to the database table.
Note the following restrictions regarding append structures:

 No append structures may be created for pooled and cluster tables.


 Tables containing a long field (data type LCHR or LRAW) cannot be
extended with appends structures.
This extension is not possible because long fields have to be the last field of
the table.

 The fields in the append structure must be in the customer namespace


beginning with YY or ZZ. Using the customer namespace prevents name
conflicts with future table fields delivered by SAP.
 If, as a partner, you have your own reserved namespace, it is recommended
that you choose the names for your append structures from your
namespace.
Enhancement of Tables

Audio Transcript

Structures and tables that have been defined by SAP in the ABAP
Dictionary can be enhanced by the customer in the following ways:

 Customizing includes
With this variant, certain places within a standard structure or table are
reserved by SAP for customer enhancements. The Customizing
environment supports customers using these Customizing includes.

 Using appends
With this variant, any fields without previous reservation are appended to the
end of structures or tables.
Enhancements using append structures may cause the following
problems:

 Structure enhancements affect not only the enhanced structure itself, but
also all dependent structures that use the enhanced structure as an include
or substructure.
However, when the enhanced structure is included in a dependent structure,
this can lead to fields in the dependent structure being displaced. This is the
case, for example, when the include appears in the middle of the dependent
structure. The field displacement can prevent ABAP programs from reading
the structure correctly.

 In programs with de-activated Unicode checks, structure enhancements can


lead to syntax and runtime errors.
These errors are generally found in type checks and in connection with deep
structures.

 In programs with activated Unicode checks, structure enhancements affect


additionally value assignments, operand checks and accesses with offset
and length. For example, numerical or deep components are inserted into a
purely character-like structure. Enhancements may also cause some issues
because the fragment view is changed, and checks in assignments and
comparisons that are based on this are affected as a result.

Enhancement categories

Audio Transcript
With structures and tables with includes or substructures, the enhancement
categories of the Includes and substructures cannot be larger than those of the
initial structure. For example, if the initial structure contains an Include of level
4, levels 2 and 3 are not permitted for the initial structure.
Structure enhancements in the Dictionary can also have an effect on internal
structures in ABAP programs if Dictionary structures in the source text are used
as type, include or substructure. These dependencies are considered implicitly
in the ABAP program check. These dependencies also relate to non-classified
structures that contain enhanceable includes or substructures.

Potrebbero piacerti anche