11.4 Data Clusters
Data clusters are a type of storage that can only be used by ABAP programs. A data cluster is a group of data objects that stored in a storage medium. The data of data objects can be stored in different media using data clusters, and this data can then be read by ABAP programs.
Data clusters are in an ABAP-specific format and can only be accessed using IMPORT and EXPORT statements. A data cluster consists of an administration section and a data section. The administration section stores administration information about the data cluster, and the data section contains the compressed data objects. The administrative information that is stored in a data cluster varies based on the storage medium.
The following media support data clusters:
- Byte string
- Internal table
- ABAP memory
- Database
- Cross-transaction application buffers
The following statements are used when working with data clusters:
-
EXPORT
Allows data objects to be written to the storage medium. -
IMPORT
Allows data objects to be extracted from the storage medium. -
DELETE
Deletes any storage medium. -
FREE
Can be used to delete ABAP memory. -
IMPORT DIRECTORY
Generates a list of all data objects that have previously been exported to a database table.
A data cluster stored in a database table is stored persistently, so it can be imported later by ABAP programs. In this section, we’ll discuss storing data clusters in a database table.
When storing data clusters in database tables, the table should have a specific structure. These structures are called INDX structures (see Figure 11.11), because they’re based on the standard table INDX provided by SAP.
The table structure should satisfy the following conditions:
- The first field of a table should be the MANDT field if you want to store data objects specific to a client, and it should be a key field. You don’t need to include the MANDT field if the data cluster is to be stored cross-client.
- The second field must be a key field named RELID of TYPE CHAR and LENGTH 2. It stores the two-character area specification supplied while exporting the data cluster. The area specification splits up the rows of the database table into several areas so that data clusters with the same ID can exist multiple times in the database table.
- The table should contain one key field of TYPE CHAR with any name to store the identifier specified in the EXPORT statement.
- The next field must be a key field named SRTF2 of TYPE INT4. It contains the row numbers of a stored data cluster that can extend over several rows and is filled automatically by the system.
- Any number of components with any names and types may follow. The components will be passed with the EXPORT statement. The IMPORT TO statement reads these fields out again.
- The last two components must be named CLUSTR and CLUSTD and be of types INT2 and LRAW of any length. In CLUSTR, the current length of field CLUSTD of each row is stored, whereas CLUSTD contains the actual data cluster.
11.4.1 Exporting Data Clusters to Databases
The EXPORT TO DATABASE statement exports the data cluster to the special database that is of table INDX.
With the EXPORT statement, a two-character area specification and ID are supplied. The area specification splits up the rows of the database table into several areas so that data clusters with the same ID can exist multiple times in the database table.
Listing 11.14 shows sample code using the EXPORT statement.
DATA: it_kna1 TYPE STANDARD TABLE OF kna1.
SELECT * FROM kna1 INTO TABLE it_kna1 UP TO 10 ROWS.
EXPORT tab = it_kna1
TO DATABASE zdemo_dc(SA)
ID 'TABLE'.
11.4.2 Importing Data Clusters
Using the IMPORT statement, the data cluster that was written to the database table dbtab in the area ar and under the ID specified in id using the EXPORT statement is imported.
Listing 11.15 shows an example of importing data clusters using the IMPORT statement.
DATA: it_kna1 TYPE STANDARD TABLE OF kna1.
IMPORT tab = it_kna1
FROM DATABASE zdemo_dc(SA)
ID 'TABLE'.