Tuesday, May 20, 2008

OPERATIONS ON TABLES

Making Changes to Tables

Procedure

Enter the table name in the initial screen of the ABAP Dictionary.
Select object class Database table.
Choose Change.
The maintenance screen for the table is displayed.

The following describe how to make changes to existing tables:

Adding an Append Structure
Inserting an Include
Inserting New Fields
Deleting Existing Fields
Changing the Data Type, Field Length and Decimal Places of Existing Fields
Changing the Table Category
Moving Fields
Copy Fields from Another Table
Copying Fields from an Entity Type.
Deleting Tables


Adding an Append Structure

Procedure

Go to change mode in the maintenance screen of the table where you want to add the append structure.
If the table contains a long field (data type VARC, LCHR or LRAW), you cannot add an append structure.

Choose Goto ® Append structures.
Either a dialog box appears in which you can enter the name of the append structure or a list of all the append structures. that were
already created for the table appears. If append structures already exist, you have to choose to get the dialog box for entering the name.

Enter the append structure name and choose . The name must lie in the customer namespace.
You go to the field maintenance screen of the append structure.

Define the fields of the append structure. You can proceed as when creating a normal structure with two restrictions (see Creating
Structures).
The fields of an append structure must lie in the customer namespace, that is the field names must begin with ZZ or YY. This prevents
conflicts with fields inserted in the table by SAP.

An append structure must be flat, that is each field of the append structure must either refer to a data element or be directly assigned a
data type, length, decimal places and short text.

If you want to create foreign keys or search help attachments for table fields that already exist, you can display these fields with Show
appending objects. Proceed as if you wanted to create the foreign key or search help attachment in the underlying table (see Creating
Tables).
If a foreign key or search help attachment is already defined for a field in the table, you cannot change this definition with the append
structure.

Choose .
Result

The table will also be activated when the append structure is activated. The fields of the append structure are appended to the table in the
database. Foreign keys or search help attachments for the fields that are already in the table and that were defined with the append
structure are also activated.

You can display information about the activation process with Utilities ® Activation log. Errors occurring when the append structure is
activated are displayed directly in the activation log.

Inserting an Include

Prerequisites

Only flat structures may be included in a table. No field refers to another structure in a flat structure. All the fields of a flat structure
therefore refer either to a data element or were directly assigned a data type, field length and decimal places.

A field name may not have more than 16 places in a table. A structure therefore can only be included in a table if none of the field names of
the structure are longer than 16 places.

Procedure

Place the cursor under the line in which you want to insert the include and choose Edit ® Include ® Insert.
A dialog box appears.

Enter the structure name. You can optionally enter a group name (see Named Includes) or a three-place suffix.
With the group name, you can access the fields in the include together in ABAP programs.

The suffix can be used to avoid name collisions between fields of the include and fields already in the table. The suffix is added to all the
fields of the include, whereby the field name is first truncated if necessary.

Choose .
A line with .INCLUDE in the Fields field and the name of the include in the Field type field is inserted in the field maintenance screen for the
table.

Select column Key if all the fields in the include should be key fields of the table.
The table key must be at the start of the field list. If you select column Key, you must insert the include after the last key field or between
the existing key fields of the table.

If you do not select column Key, none of the included fields is a key field of the table.

Choose .
Result

The fields of the include are added to the table in the database. If you inserted the fields of the include as key fields, the primary index of
the table is built again.

You can find information about the activation flow in the activation log, which you can display with Utilities ® Activation log. The activation
log is displayed immediately if errors occur when the table is activated.

Other Options

You can display the fields contained in an include by placing the cursor on the line of the include and choosing . The fields of the include are
now shown below this line. You can cancel this action with .

You can expand all the includes contained in a table with . Cancel this action with .

You can copy the fields contained in the include directly to the table with Edit ® Include ® Copy components. The fields of the include
become table fields. They are no longer adjusted to changes in the include.

Inserting New Fields

Procedure

In the maintenance screen for the table, place the cursor on the field in front of which the new field should be inserted and choose Insert
line. You can append several new fields at the end of the table with New lines.
An empty line appears in which you can insert the new field. Creating Tables. describes how to add a field to a table.

Set the Init flag if the new field should be created in the database as NOT NULL.
In this case the entire is scanned during activation and the new field is filled with the initial value. This can be very time-consuming for large
tables.

Key fields are always defined as NOT NULL. When a new key field is inserted, the primary index of the table is built again in the database.

Choose .
Result

The new field is added to the table when it is activated in the database. This does not depend on the position of the new field in the field
list of the table, that is the order of the fields in the ABAP Dictionary does not have to be the same as in the database.



If the table is a check table of a foreign key, new key fields can only be appended to the previous primary key. When the table is activated,
the foreign keys concerned are defined as generic with regard to the new key fields. The foreign keys changed in this way are listed in the
activation log.



Inserting a client field results in a table conversion (see Adjusting Database Structures). The data in the table is copied to all the clients
listed in client table T000.

If the table is a check table of a foreign key, it is not possible to insert a client field. In this case you must first delete the existing foreign
keys.


Deleting Existing Field

To delete one field from a table, place the cursor on the corresponding line and choose Delete line. Choose .



If the table in the database already contains data, you have to convert the table after deleting existing fields (see Adjusting Database
Structures).

If you delete key fields of the table, data could be lost during conversion. If the table contains data records that only differ in the deleted
key field, only one of these data records can be loaded back into the table.



You cannot delete a field used as a reference field in another table. In this case you must first remove all the uses of the field as a
reference field (see Reference Fields and Reference Tables).

You cannot delete key fields of the table if the table is the check table. In this case you must first delete the corresponding foreign keys.

You can determine all the tables that use the particular table as check table or reference table with .

Changing Data Types and Lengths of Existing Fields

If a data element is assigned to the field, you must change the technical field attributes (data type, length, number of decimal places) in
the domain of the data element.

Procedure for Fields with Data Elements

Double-click on the name of the data element.
The data element maintenance screen appears.

Double-click on the name of the domain.
The domain maintenance screen appears.

Choose Domain ® Display ® Change.
Make the required changes and save your entries.

Note that this change affects all the table fields that refer to the particular domain. Foreign keys could become inconsistent and conversions
required. You should therefore consider the effects of this action before changing the domain by choosing in the maintenance screen of the
domain and checking if the domain is used in other tables.

Choose .
The table is activated again and the table field is adjusted to the domain change.

Procedure for Fields with Direct Type Entry

Place the cursor on the field and choose Data element / Direct type.
Values can now be entered in fields Data type, Length, DecPlaces and Short text.

Change the entries for the data type, length and possibly the number of decimal places.
Save your entries.

activate.

Changing the Table Category

Prerequisites

Depending on the category of the change, note the following features:

Transparent to structure: The table is deleted from the database at activation. Existing data is lost. Any technical settings for the table are
also lost.
Pooled/cluster to transparent: Since technical settings are meaningless for pooled and cluster tables, you must maintain them before
activating the transparent table.
Transparent to pooled/cluster: You must define the assignment to the table pool or table cluster in which the table data should be stored.
Procedure

In the field maintenance screen of the table, choose Extras ® Change table category.
A dialog box appears in which the current table category (transparent database table, structure, pooled table, cluster table) is selected.

Select your table category and choose Select.
You return to the field maintenance screen for the table.

activate

Moving Fields

Procedure

Place the cursor on the field to be moved and choose .
The selected field is deleted and copied to the clipboard.

Place the cursor on the field in front of which you want to insert the selected field and choose .
The field is inserted in the table at the new position.



The order of the fields in the ABAP Dictionary can differ from the order of the fields in the database. Changing the order of the fields (with
the exception of key fields) in the ABAP Dictionary therefore does not result in a change in the database. In particular, a table conversion is
not required (see Adjusting Database Structures).

If the table is a check table, you cannot change the order of the key fields. In this case you must first delete the corresponding foreign keys.

Copying Fields from Another Table

You can copy fields or blocks of fields from another table.

Procedure

In the maintenance screen of the table choose Edit ® Copy fields.
Enter the name of the table from which you want to copy the fields in the next dialog box.

Choose Field selection.
A list of the fields contained in this table appears.

Place the cursor on the first field of the block to be copied and choose Select block.
If you want to copy only single fields, place the cursor on these fields and choose Select.

Place the cursor on the last field of the block to be copied and again choose Select block.
All the fields of the selected block are highlighted.

Choose Copy.
The selected block or the selected single fields are copied to a buffer, and you return to the field maintenance screen.

Place the cursor on the field in front of which you want to insert the new fields and choose .
The selected fields are inserted in the table.

activate

Copying Fields from an Entity Type

Procedure

In the field maintenance screen of the table choose Edit ® Att. from ent. type.
A dialog box appears.

Enter the name of the entity type from which you want to copy attributes to the table. Choose Field selection.
A dialog box appears listing all the attributes of the entity type.

Select the attributes that you want to copy. Select the corresponding entry in the list and choose Choose.
The entry is highlighted.

Note that only the explicit attributes of the entity type can be copied with this function. Only these explicit attributes are displayed. Explicit
attributes are the attributes that were not copied from the table assigned to the entity type. This means that only those attributes that
were entered directly in the Data Modeler can be copied.

Select all the fields you want and choose Copy.
The attributes are now copied to the clipboard.

Place the cursor on the field in front of which you want to insert the fields and choose .
The selected fields are inserted in the table.

Deleting Tables

Prerequisites

A table can only be deleted in the ABAP Dictionary when it is no longer used in any other objects (for example views or programs).

Procedure

In the initial screen of the ABAP Dictionary, select the object type Database table and enter the name of the table.
With the where-used list , check if the table is still used in programs or other objects of the ABAP Dictionary.

Choose .
A dialog box appears in which you are asked to confirm the deletion request. This dialog box tells you if the table still contains data.

Confirm the deletion request.
Result

The table is now deleted if it is no longer being used in other objects of the ABAP Dictionary



ABAP DICTIONARY

Purpose

Data definitions (metadata) are created and managed in the ABAP Dictionary. The ABAP Dictionary permits a central description of all the
data used in the system without redundancies. New or modified information is automatically provided for all the system components. This
ensures data integrity, data consistency and data security.

You can create the corresponding objects (tables or views) in the underlying relational database using these data definitions. The ABAP
Dictionary therefore describes the logical structure of the objects used in application development and shows how they are mapped to the
underlying relational database in tables or views.

The ABAP Dictionary also provides standard functions for editing fields on the screen, for example for assigning a screen field an input help.

What Information is Stored in the ABAP Dictionary?

The most important object types in the ABAP Dictionary are tables, views, types, domains, search helps and lock objects.

Tables are defined in the ABAP Dictionary independently of the database. A table having the same structure is then created from this table
definition in the underlying database.

Views are logical views on more than one table. The structure of the view is defined in the ABAP Dictionary. A view on the database can
then be created from this structure.

Types are used in ABAP programs. The structure of a type can be defined globally in ABAP programs. Changes to a type automatically take
effect in all the programs using the type.

Lock objects are used to synchronize access to the same data by more than one user. Function modules that can be used in application
programs are generated from the definition of a lock object in the ABAP Dictionary.

Different fields having the same technical type can be combined in domains. A domain defines the value range of all table fields and
structure components that refer to this domain.

The ABAP Dictionary also contains the information displayed with the F1 and F4 help for a field in an input template. The documentation
about the field is created for a data element that describes the meaning of the contents of a table field. The list of possible input values
that appears for the input help is created by a foreign key or a search help.

Integration in the ABAP Workbench

The ABAP Dictionary is completely integrated in the ABAP Workbench. The R/3 System works interpretatively, permitting the ABAP Dictionary
to be actively integrated in the development environment. Instead of the original objects, the interpreters see only internal representations
of these objects.

These internal representations are adjusted automatically when the system finds that changes have been made in the ABAP Dictionary.
This ensures that the screen and ABAP interpreters, input help, database interface, and development tools always access current data.

The following ABAP program lists the airline carriers (see Flight model) and carrier IDs contained in table SCARR.
DATA: SCARR_TAB TYPE SCARR.

SELECT * INTO SCARR_TAB FROM SCARR.

WRITE: / SCARR_TAB-CARRID, SCARR_TAB-CARRNAME.

ENDSELECT.

Only structure SCARR_TAB is declared in the program. All the information about this structure, such as the field names, data types and field
lengths, are copied from table SCARR, which is defined in the ABAP Dictionary. This information about table SCARR is called from the ABAP
Dictionary when the program is generated.

This means that the source text of the program need not be adjusted when a change is made to table SCARR, for example when the length
of a table field is changed. The next time the program is called, the system automatically determines that the structure of table SCARR has
changed. The program is simply regenerated, thereby retrieving up-to-date information about table SCARR from the ABAP Dictionary.


When you work on development projects, objects of the ABAP Dictionary can be changed any number of times before being activated and
made available to the operative components of the system. Objects can have both an active and an inactive version in the ABAP Dictionary
at the same time.

Inactive ABAP Dictionary objects have no effect on the runtime system (ABAP processor, database interface). This permits greater changes
to several objects without impairing the executability of the system. The objects can only be activated together when they have all been
changed.