Entering content frame

Syntax documentation Column Description  Locate the document in its SAP Library structure

The syntax rules listed here are components of the column description in the commands for loading and unloading application data.

Note

If you want to use keywords as column names, you must place them in double quotation marks.

Syntax

<load_column_spec_mlt> ::= <load_column_spec> <load_column_spec_mlt>
<load_column_spec> ::= <column_descriptor> [<null_condition]
| <column_assignment>

<column_descriptor> ::= <valCOLUMN_NAME> <field_pos> <format_spec>
<format_spec> ::= <field_format> [HEX] [<numerical_functions>]
<numerical_functions> ::= <scale_spec>
| <round_or_trunc_spec>
| <scale_spec> <round_or_trunc_spec>
<scale_spec> ::= SCALE <valSCALE_FACTOR>
<round_or_trunc_spec> ::= ROUND <valFRACTION> | TRUNC <valFRACTION>

<null_condition> ::= NULL [IF] <condition> | DEFAULT NULL

<column_assignment> ::= <valCOLUMN_NAME> '<valLITERAL>'
| <valCOLUMN_NAME> <generate_spec>

valCOLUMN_NAME

Column name
Specify this according to the SQL conventions. It can also contain the table name as a prefix (such as, customer.cno).

HEX

You can define HEX values.

valSCALE_FACTOR

Scaling factor, can be positive or negative

The value to which the syntax rule refers is multiplied by the corresponding power of ten.

valFRACTION

Number of decimal places

The value must be between 0 and 18. This function does not have any effect if the number does not have any decimal places.

valLITERAL

Constant

Explanation

<load_column_spec_mlt>, <load_column_spec

You use the syntax rule load_column_spec_mlt in a command for loading application data to specify the data records in the data stream that are to be loaded. You assign the data fields in the data stream to the columns in the target table and specify the external data types as well as the conditions for loading the data.

Example

Load commands

DATALOAD TABLE customer
  cno       1
  title     2
  firstname 3
  name      4
  zip       5
  address   6
INSTREAM 'customer.data'

DATALOAD TABLE reservation
  rno        01-04 INTEGER
  cno        05-08 INTEGER
  hno        09-12 INTEGER
  type       13-18 CHAR
  arrival    19-28 CHAR
  departure  29-38 CHAR
INSTREAM 'reservation.data' FORMATTED BINARY

Rules

Data must exist in the data stream for every column that you specify in the load command.

If you do not specify columns in the target table in the command, the entire column is populated with the default value defined for this column during the load operation. The NULL value is loaded if no specific default value is defined for the column.

Example

DATALOAD TABLE customer
  cno       1
  name      4
  address   6
INSTREAM 'customer.data'

titlefirstname, and zip are filled with the default value when the data is loaded.

Key columns and mandatory columns (columns that are defined as NOT NULL without a default value) must be specified in the load command. Otherwise, the processing terminates with an SQL error.

Example

DATALOAD TABLE customer
  name      4
  zip       5
  address   6
INSTREAM 'customer.data'

The command is terminated with an SQL error because the column cno is missing.

If you do not specify any columns for the target table in the load command, the table is loaded as if all columns in the target table were specified in the command. If this is the case, data must exist in the data stream for all of the columns in the target table.

Example

DATALOAD TABLE customer
INSTREAM 'customer.data'

Data must exist in the source file for all of the columns in the data stream.

<column_descriptor>

In a command for loading application data, you can use this syntax rule to assign a data field in the data stream to a column in the target table.

To do so, you specify the column name, the position, and the external data type of the data in the data stream.

Example

DATALOAD TABLE reservation
  rno           01-04 INTEGER
  cno           05-08 INTEGER
  hno           09-12 INTEGER
  type          13-18 INTEGER
  arrival       19-28 CHAR
  departure     29-38 CHAR
INSTREAM 'reservation.data' FORMATTED BINARY

<format_spec>

In a command for loading or unloading application data, use the format_spec syntax rule to specify the data fields in the data stream (external data type, position, and so on).

You can use the syntax rule numerical_function to scale (scale_spec), round, or truncate (round_or_trunc_spec) numeric data values when you load data from the data stream to the target table or unload data from the source table to the data stream.

Note

Note that you must always specify scale_spec before round_or_trunc_spec.

Example

DATALOAD TABLE distance
  ...

  cm 7 SCALE 2
  cm 7
SCALE -3 ROUND 1
...

INSTREAM 'meter.data'

Example

DATAEXTRACT * FROM distance
  cm    10-14 INTEGER
SCALE 2
  m     14-17 INTEGER
  km    18-21 INTEGER
SCALE -3 TRUNC 2
  
OUTSTREAM 'dimensions.bin' FORMATTED

You use the syntax rule round_or_trunc_spec to specify the number of decimal places for a number.

·        ROUND <valFRACTION>
The value is rounded off at the (
<valFRACTION>+1) th decimal place. If this number is >= 5, the value is rounded up. If it is < 5, the value is rounded down. The result is a number in which the (<valFRACTION>+1)th and all subsequent decimal places are equal to 0. The other digits in the number may have been changed if the value was rounded up.

·        TRUNC <valFRACTION>
The (
<valFRACTION>+1)th and all subsequent decimal places of the value are set to 0. The first <valFRACTION> decimal places remain unchanged.

<null_condition>

You use the syntax rule null_condition in a command for loading data, to specify the conditions under which the NULL value should loaded into a column of the target table.

When the condition (condition) is evaluated, the shorter of the comparison values (value in the data stream or the null value representation) is filled with blank characters.

A check is made before each line in the data stream is loaded to see whether the condition formulated for the columns applies. If it does, the NULL value is inserted in this column. If not, the value from the assigned field in the data stream is inserted.

You can use the DEFAULT-NULLcondition if the NULL value in the data stream is represented in the same way for all columns that you want to load from the target table. The character string that you need to specify after NULL IF POS is only entered once as NULL specification in the DEFAULT-NULL condition.

Note

You cannot load columns defined as key columns (KEY) or NOT NULL with the NULL value. If you do, the table load action terminates and the appropriate error message is displayed.

If, when you created the table in the database instance, you defined a default other than NULL for columns, you cannot load NULL values into the columns. In this case, the Loader uses the default value defined for the column instead of the NULL value.

Example

You want to load the data from the data stream room.data into the database instance. You want to load the NULL value into certain columns of the target table. Define a separate condition for each of these columns. The NULL value is entered if this condition is met.

DATALOAD TABLE room
  hno     1
  type    2
  free    3    
NULL IF POS 3 = '0'
  price   4    NULL IF POS 4 <> 'XXXX'
INSTREAM 'room.data'

Example

You want to load the data from the data stream room.datainto the database instance. You want to load the NULL value into certain columns of the target table. The same '?' representation of the NULL value applies to all columns in the command where DEFAULT NULL is specified.

DATALOAD TABLE room
  hno     1
  type    2
  free    3    
DEFAULT NULL
  price   4    DEFAULT NULL
INSTREAM 'room.data'
NULL '?'

<column_assignment>

You can use the syntax rule column_assignment to specify that a constant value is loaded into the specified column for each loaded data record, and which value this constant is to have.

In the command, enter the constant or the special constant generate_spec instead of a position specification. Now, data will not be loaded from the data stream for the appropriate column.

Note

If the data stream is empty, the constants specified in the command are not loaded.

See also:

Loading Constants and Special Constants

 

Leaving content frame