Ansicht
Dokumentation

ABENITAB_HEADER_LINE - ITAB HEADER LINE

ABENITAB_HEADER_LINE - ITAB HEADER LINE

Fill RESBD Structure from EBP Component Structure   ABAP Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

Internal Tables with a Header Line

Outside classes, and if it is not a component of a structure or line of another internal table, it is still possible to create an internal table with a header line.

Declaration of Header Lines

Header lines of internal tables are created

  • by using the addition WITH HEADER LINE of the statement DATA when declaring internal tables,

Note

The statement CREATE DATA cannot be used to create internal tables with a header line.

Properties of Header Lines

A header line is a work area whose

  • data type is the same as the line type of the internal table
  • name is the same as the name of the internal table.

If a header line exists, therefore, an ABAP program has two identically named data objects, namely the actual internal table and the header line. The internal table and header line are accessed as follows:

  • Many processing statements for internal tables have obsolete short forms in which the header lines is used as an implicit work area if no explicit work area is specified.
  • In all other cases, the statement and operand position decide whether the table body or the header line is used when the table name is specified. The header line is the usual choice. The simple name of an internal table with header line is interpreted as the table body only in the following cases:

  • In the statement FREE.

  • In the obsolete statement SEARCH.

  • When a token is specified dynamically in (except when database tables are specified).

To force access to the table body in any operand position when a header line exists, square brackets can be specified directly after the name of an internal table in all operand positions (for example, itab[]). This does not apply, however, when specifying the internal table in a table expression.

Notes

  • When a LIKE reference is made to an internal table with header line, either the header line itself can be referenced or [] can be specified to reference the table body. It is not possible, however, to reference the internal table including the header line.
  • A field symbol, a formal parameter (except table parameters), or a data reference can only address either the table body or the header line. This means that a field symbol, a formal parameter (except table parameters), or a data reference is therefore never ambiguous.
  • Both the table body and the header line are passed when a table with header line is passed to table parameters.
  • [] can be specified for internal tables without a header line, but this is not necessary, since the simple name (without []) of an internal table without a header line is interpreted as the table body in all operand positions regardless.
  • In many operand positions that expect internal tables, the syntax check forces [] to be specified after the name of an internal table with a header line.
  • RTTS does not support internal tables with header lines. A type description object can describe either only the header line or the table body.
  • In very old programs, the use of the obsolete pseudo component *sys* is used to address the header line can also be found instead of [].

Use

The use of header lines is highly error-prone, due to the repeated use of a single name for two data objects. The creation and use of header lines must be avoided as much as possible, even outside of classes.

  • The use of table parameters should be avoided as much as possible.
  • In cases where the creation of a header line is unavoidable, such as in selection tables or in procedures that still require table parameters (generally only remote-enabled function modules), the header line should never be used, and always the additional explicitly work areas declared explicitly instead.

Notes

  • A work area for replacing a header line can be declared very easily by using the addition LINE OF of the statements TYPES, DATA, and so on.
  • The use of an additional work area should not be confused with the explicit completion of the implicit short forms, such as LOOP AT itab INTO itab. The latter case is also one of the undesired uses of a header line.
  • Tables with header lines do not offer any performance advantages.

Example

The following example shows a typical pitfall when handling internal tables with header lines: An internal table with a header line, in this case, the table parameter of a function module, is initialized using CLEAR, but the [] is not appended to the name. In this case, only the header line is cleared, which is usually noticed only at runtime.

FUNCTION work_with_tables.
*"---------------------------------
*"*"Local Interface
*"  TABLES
*"      table STRUCTURE  structure
*"----------------------------------

  CLEAR table.

  ...

ENDFUNCTION.






General Material Data   Vendor Master (General Section)  
This documentation is copyright by SAP AG.

Length: 10335 Date: 20240425 Time: 183926     sap01-206 ( 203 ms )