Strings in Database Tables

You can use Open SQL to store character strings and binary data as strings in database columns. There are two kinds of strings in the database, short strings and long strings, which differ in the form how the data is stored in the database. Whether a string column is a short or a long string, is determined in the ABAP Dictionary.

Short Strings

Short strings are only available for character strings (DDIC type SSTRING). They are normally implemented as VARCHAR fields in the database and stored in the data record. Short strings must always have a length restriction in the ABAP Dictionary which may not exceed 255 characters. Closing blanks are ignored by the database.

In Open SQL statements you can use short strings wherever you can use C fields.

Long Strings

Long strings (also: "LOB columns") are available for character strings (DDIC type STRING) and binary data (DDIC type RAWSTRING). They are normally implemented as LOB in the database. The system only stores an LOB locator in the data record while the actual string data is stored outside the data record. You can define a length restriction for long strings in the ABAP Dictionary. For columns of the type STRING, closing blanks are retained.

Long strings are subject to the following restrictions:

  1. They must not be used in key fields.
  2. They must not be used in logical conditions of the WHERE clause and HAVING clause as well as in the ON conditions of the FROM clause.
  3. They must not be used in aggregate functions.
  4. They must not be used in database indexes.
  5. They must not be used in the SELECT- clause in combination with the addition DISTINCT.
  6. They must not be used in a GROUP BY clause.
  7. They must not be used in an ORDER BY clause.
  8. If you change a string column using UPDATE ... SET, the primary key must be specified completely.

Length Restriction

It is possible for long strings and mandatory for short strings to define a length restriction for them in the ABAP Dictionary. If this restriction is violated when data is written to the database, the system triggers an exception of the class CX_SY_OPEN_SQL_DB. Any truncation of the string when data is read from the database into a target field is ignored. You can get the value of the length restriction using the function DBMAXLEN( ).

Notes:

  1. Any database can choose to represent an empty string by a NULL value.
  2. If a database table dbtab or a work area wa contains strings, then the work area wa must be compatible with the line structure of the database table dbtab in case of the following statements:
    - SELECT * FROM dbtab INTO wa
    - INSERT dbtab FROM wa oder INSERT INTO dbtab VALUES wa
    - UPDATE dbtab FROM wa
    - MODIFY dbtab FROM wa
    - DELETE dbtab FROM wa
    Similarly, if you use the following set operations, the line structure of the internal table itab must be compatible with the line structure of the database table dbtab if itab or dbtab contains strings:
    - SELECT * FROM dbtab INTO TABLE itab
    - INSERT dbtab FROM TABLE itab
    - UPDATE dbtab FROM TABLE itab
    - MODIFY dbtab FROM TABLE itab
    - DELETE dbtab FROM TABLE itab

Performance:

Since the data of long strings is stored outside the data record, access to long strings is slower than to other data types. This applies particularly to set operations. This note is not applicable if you use short strings.