Creating a Directory of a Data Cluster 

To create a directory of a data cluster from an ABAP cluster database, use the following statement:

Syntax

IMPORT DIRECTORY INTO <dirtab>
                 FROM DATABASE <dbtab>(<ar>)
                 [CLIENT <cli>] ID <key>.

This creates a directory of the data objects belonging to a data cluster in the database <dbtab> in the internal table <dirtab>. You must declare <dbtab> using a TABLES statement.

To save a data cluster in a database, use the EXPORT TO DATABASE statement (refer to Saving Data Objects in a Cluster Database). For information about the structure of the database table <dbtab>, refer to the section Structure of Cluster Databases.

For <ar>, enter the two-character area ID for the cluster in the database. The name <key> identifies the data in the database. Its maximum length depends on the length of the name field in <dbtab>. 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.

The IMPORT statement also reads the contents of the user fields from the database table.

If the system is able to create a directory, SY-SUBRC is set to 0, otherwise to 4.

The internal table <dirtab> must have the ABAP Dictionary structure CDIR. You can declare it using the TYPE addition in the DATA statement. CDIR has the following components:

Field name

Type

Description

NAME

CHAR

Name of the object in the cluster

OTYPE

CHAR

Object type:

F: elementary field

R: structure

T: internal table

FTYPE

CHAR

Data type of object: Structured data types return type C

TFILL

INT4

Number of filled lines in internal tables

FLENG

INT2

Length of field or structure

 

PROGRAM SAPMZTS2.

TABLES INDX.

DATA DIRTAB LIKE CDIR OCCURS 10 WITH HEADER LINE.

IMPORT DIRECTORY INTO DIRTAB FROM DATABASE
                                  INDX(HK) ID 'Table'.

IF SY-SUBRC = 0.
  WRITE: / 'AEDAT:', INDX-AEDAT,
         / 'USERA:', INDX-USERA,
         / 'PGMID:', INDX-PGMID.
  WRITE  / 'Directory:'.
  LOOP AT DIRTAB.
    WRITE: / DIRTAB-NAME,  DIRTAB-OTYPE, DIRTAB-FTYPE,
             DIRTAB-TFILL, DIRTAB-FLENG.
  ENDLOOP.
ELSE.
  WRITE 'Not found'.
ENDIF.

This example creates a directory of the contents of the data cluster created using the example program in the section Saving Data Objects in Cluster Databases. The output appears as follows:

The directory DIRTAB contains one line, showing that the data cluster contains an internal table called ITAB, with 3000 lines, each of length 8.