Entering content frame

Background documentation The DATAEXTRACT Command Locate the document in its SAP Library structure

You can use this Loader command to control the process for unloading application data from database tables.

Prerequisite

You must have access authorization for the tables from which you want to unload data.

You must be owner of the table to use the second variant of the DATAEXTRACT command.

Syntax

<dataextract_command> ::=
  DATAEXTRACT <select_expression> [OUTFIELDS] [<output_column_list>] <extract_files_spec>
| DATAEXTRACT <restore_spec> TABLE <table_name> [<order_clause] <extract_files_spec>

<select_expression> ::= SELECT Statement

<output_column_list> ::= <output_column>
| <output_column> <output_column_list>

<restore_spec> ::= FOR DATALOAD| FOR FASTLOAD| FOR DATAUPDATE

<order_clause> ::= ORDER BY <column_names>
<column_names> ::= <valCOLUMN_NAME>
| <valCOLUMN_NAME>,<column_names>

<extract_files_spec> ::= <outstream_spec> [<longfile_spec_mlt>]
| <command_outstream_spec> <outstream_spec> [<longfile_spec_mlt>]
<command_outstream_spec> ::= <outstream_spec>

FOR DATALAOD

The data is to be loaded using the DATALOAD command.

FOR FASTLOAD

The data is to be loaded using the FASTLOAD command.

FOR DATAUPDATE

The data is to be loaded using the DATAUPDATE command.

valCOLUMN_NAME

Column name

outstream_spec

Definition of the data stream for application data

command_outstream_spec

Only variant 2 of the DATAEXTRACT command: table definitions are unloaded to a command file.

You can also use the keywords EXTRACT DATA instead of the keyword DATAEXTRACT.

Explanation

The Loader offers you the following variants of the DATAEXTRACT command.

Variant 1: DATAEXTRACT <select_expression> [OUTFIELDS]…

You can use this variant of the command to:

·        Define the columns of the table that is to be unloaded

·        Link multiple tables that you want to unload

·        Specify a sort sequence for the extracted data

<select_expression>

You use the syntax rule select_expression to specify which columns in a table are to be extracted. This database query is formulated in the same way as a SELECT statement, however the keyword  DATAEXTRACT replaces the keywords EXTRACT DATA. All options of a SELECT statement are permitted:

·        Select the result columns and determine their order in the result table

·        Join multiple tables

·        Use qualifications to select result lines

·        Specify sort order

·        Specify locks and isolation level (WITH LOCK, see LOCK Option (lock_option))

Example

DATAEXTRACT cno, title, name, firstname FROM customer WITH LOCK
OUTFIELDS
  cno         1
  title       2
  name        3
  firstname   4
OUTSTREAM 'customer.data'

Example

DATAEXTRACT cno, title, name, firstname FROM customer
WITH LOCK ISOLATION LEVEL 0
OUTSTREAM 'customer.data'

<output_column_list>

If you specify the syntax element output_column_list, you describe the columns in a source table that are to be unloaded and how the data records are represented in the data stream.

·        The columns can be in any order in the column description.

·        The column list can only contain columns from the SELECT statement or a subset of them.

·        Values are output only for those columns in the column list. If the column list contains more columns than the SELECT statement, the Loader generates an error and terminates the command.

·        If you do not describe the columns of the source table in the command, you do not have to specify the OUTFIELDS keyword. The data is output as plain text values.

·        If you have defined the COMPRESSED format for the data stream, the values of the columns to be extracted are output in the order in the SELECT statement, and separated with separators.

·        If you have defined the FORMATTED format for the data stream, the values of the columns to be extracted are formatted and output in the order in the SELECT statement. The length of the individual output values depends on the defined sizes of the individual columns in the source table.

·        If the SELECT statement does not contain any column names (DATAEXTRACT * FROM ...), the columns are formatted according to the format of the data stream. They are output in the order specified by the database for processing the command.

Example

DATAEXTRACT * from hotel
  OUTFIELDS  hno        01-10
             name       11-25
             zip        26-30
             address    31-55
OUTSTREAM 'hotel.data' FORMATTED

<extract_files_spec>

The syntax rule extract_files_spec ::= <outstream_spec> [<longfile_spec_mlt>] only applies to variant 1 of the DATAEXTRACT command.

Example

DATAEXTRACT cno, name, zip, address FROM customer
OUTSTREAM 'customer.data'

Variant 2: DATAEXTRACT <restore_spec> TABLE <table_name>…

You can only use this variant of the command to unload complete single tables. You unload table definitions in the database catalog to the data stream command_outstream_spec  and all application data in a table to the data stream outstream_spec. You can use these two data streams to recreate the unloaded table and load all application data.

The Loader uses the information from the DATAEXTRACT command to generate an internal SELECT command and constructs a results table. The data in this results table is then unloaded into the target data stream, as instructed by the command.

All tables from which data is being unloaded are write-protected while the DATAEXTRACT command is being executed. This means that other users cannot make changes to this table while it is being unloaded.

<restore_spec>

You use the syntax rule restore_spec to specify which command for loading the data is to be generated in the command file.

If a FASTLOAD command is generated, this command contains the value of 80% for the fill level of the database (usage_spec). This is the default used by the Loader.

Example

DATAEXTRACT FOR DATALOAD TABLE customer
OUTSTREAM 'customer.command'
OUTSTREAM 'customer.data'

<order_clause>

You use the syntax rule order_clause to specify the order in which the columns are to be unloaded.

Example

DATAEXTRACT FOR DATALOAD TABLE reservation ORDER BY arrival, departure
  OUTSTREAM 'reservation.command'
  OUTSTREAM 'reservation.data'

<extract_files_spec>

The syntax rule extract_files_spec ::= <command_outstream_spec> <outstream_spec> [<longfile_spec_mlt>] only applies to variant 2 of the DATAEXTRACT command. The table definitions in the database catalog are stored in the data stream command_outstream_spec.

Example

DATAEXTRACT FOR DATALOAD TABLE reservation
  OUTSTREAM 'reservation.command'
  OUTSTREAM 'reservation.data'

Data stream for the definition from the database catalog: reservation.command
Data stream for application data:
reservation.data

Result

The data is unloaded from the tables to be unloaded into the target data stream(s).

You can use a DATALOAD and/or FASTLOAD command to reload the table data back into the database instance.

Errors

The unload process cannot be successfully completed. In this case, the Loader logs the number of data records that have been successfully unloaded in the log file.

 

Leaving content frame