Saving Data Objects in Cluster Databases Locate the document in its SAP Library structure

To save data objects from an ABAP program in a cluster database, use the following statement:

Syntax

EXPORT <f1> [FROM <g 1>] <f 2> [FROM <g 2>] ...
       TO DATABASE <dbtab>(<ar>) [CLIENT <cli>] ID <key>.

This statement stores the data objects specified in the list as a cluster in the cluster database <dbtab>. You must declare <dbtab> using a TABLES statement. If you do not use the option FROM <f i >, the data object <f i > is saved under its own name. If you use the FROM <g i > option, the data objet <g i > is saved under the name <f i >.

<ar> is the two-character area ID for the cluster in the database
(refer to point to in
Structure of a Cluster Database).

The name <key> identifies the data in the database. Its maximum length depends on the length of the name field in <dbtab>.
(See also point 3 in
Structure of a Cluster Database).

The CLIENT <cli> option allows you to disable the automatic client handling of a client-specific cluster database, and specify the client yourself. The addition must always come directly after the name of the database.
(See also point 1 in
Structure of a Cluster Database).

The EXPORT statement also transports the contents of the user fields of the table work area <dbtab> into the database table. You can fill these fields yourself beforehand.
(See also point 5 in
Structure of a Cluster Database).

The EXPORT statement always completely overwrites the contents of any existing data cluster in the same area <ar> with the same name <key> in the same client <cli>.

Note

If you are using internal tables with header lines, you can only store the table itself, not the header line. In the EXPORT statement, the table name is interpreted as the table. This is an exception to the general rule, under which statements normally interpret the table name as a table work area (see Choosing a Table Type).

Example

PROGRAM SAPMZTS1.

TABLES INDX.

DATA: BEGIN OF ITAB OCCURS 100,
        COL1 TYPE I,
        COL2 TYPE I,
      END OF ITAB.

DO 3000 TIMES.
  ITAB-COL1 = SY-INDEX.
  ITAB-COL2 = SY-INDEX ** 2.
  APPEND ITAB.
ENDDO.

INDX-AEDAT = SY-DATUM.
INDX-USERA = SY-UNAME.
INDX-PGMID = SY-REPID.

EXPORT ITAB TO DATABASE INDX(HK) ID 'Table'.

WRITE: '    SRTF2',
     AT 20 'AEDAT',
     AT 35 'USERA',
     AT 50 'PGMID'.
ULINE.

SELECT * FROM INDX WHERE RELID = 'HK'
                   AND   SRTFD = 'Table'.

  WRITE: / INDX-SRTF2 UNDER 'SRTF2',
           INDX-AEDAT UNDER 'AEDAT',
           INDX-USERA UNDER 'USERA',
           INDX-PGMID UNDER 'PGMID'.

ENDSELECT.

This example fills an internal table ITAB with 3000 lines, assigns values to some of the user fields in INDX, and then exports ITAB to INDX.

Since INDX is a relational database, you can address it using Open SQL statements. The SELECT statement in the example uses appropriate WHERE conditions to select lines transferred to the database in the EXPORT statement.

The output of some of the database fields is as follows:

This graphic is explained in the accompanying text

This shows that the user fields AEDAT, USERA, and PGMID were transferred in the EXPORT statement, and that the data cluster contained in ITAB extends over 6 lines. If you change the figure 3000 in the DO statement, the number of lines occupied by the data cluster would also change.

 

 

 

 

Leaving content frame