TYPE KEY WARD IN ABAP

TYPE KEY WARD IN ABAP:

TYPES - Defining an Internal Table Type

Variants:

1. TYPES itabtype {TYPE tabkind OF linetype|
LIKE tabkind OF lineobj}
[WITH [UNIQUE|NON-UNIQUE] keydef[INITIAL SIZE n].

2. TYPES itabtype TYPE RANGE OF type.
TYPES itabtype LIKE RANGE OF f.

3. TYPES itabtype {TYPE linetype|LIKE lineobj} OCCURS n.

Effect

Defines a user-defined type (abap type concept for an internal table

Variant 1

TYPES itabtype {TYPE tabkind OF linetype|
LIKE tabkind OF lineobj}
[WITH [UNIQUE|NON-UNIQUE] keydef] [INITIAL SIZE n].

Effect

Defines the type itabtype for an internal table without header line in a program with table type tabkind and line type linetype (if you use a TYPE reference) or the type of the referred object lineobj (if you use a LIKE reference). Internal tables without a header line consist of any number of table lines, each of which has the structure defined by the line type.

You may also define a table key. If you do not, the system creates a generic table type with any key. You can use generic types to specify the type of generic subroutine parameters.

The UNIQUE and NON-UNIQUE additions allow you to specify whether a table with type itabtype may contain two or more records with the same key or not. The following rules apply:

  • STANDARD TABLE:
    The key is always NON-UNIQUE by default. You cannot use the UNIQUE addition with a standard table.
  • SORTED TABLE:
    There is no default setting for sorted tables. If you do not specify UNIQUE or NON-UNIQUE, the system creates a generic table type without a particular uniqueness attribute. You can use generic types to specify the types of generic subroutine parameters.
  • HASHED TABLE:
    There is no default setting for hashed tables. However, you must define a UNIQUE key. The NON-UNIQUE addition is not permitted.

The optional INITIAL SIZE addition allows you to specify how much memory should be allocated to the table when you create it. This corresponds to the OCCURS specification in variant 2 (see also Performance Notes for Internal Tables). The value n is not taken into consideration in the type check.

Example

The following type definitions define tables using the line type STRUC and the key NAME:

TYPES: BEGIN OF STRUC,
NAME(10) TYPE C,
AGE TYPE I,
END OF STRUC.

TYPES: TAB1 TYPE STANDARD TABLE OF STRUC WITH DEFAULT KEY,
TAB2 TYPE SORTED TABLE OF STRUC
WITH NON-UNIQUE KEY NAME,
TAB3 TYPE HASHED TABLE OF STRUC WITH UNIQUE KEY NAME.

Unlike the above types, the following types are generic. This means that you can use them to specify the type of a generic subroutine parameter, but not to create a table object uisng the DATA statement. The only exception to this is that the system allows you to use a generic standard table type in a DATA statement - the type description is completed automatically by the system according to the rules described under DATA.

TYPES: GEN_TAB1 TYPE STANDARD TABLE OF STRUC,
GEN_TAB2 TYPE SORTED TABLE OF STRUC WITH KEY NAME,
GEN_TAB3 TYPE HASHED TABLE OF STRUC.

The following example shows the definition of a sorted table using a LIKE reference to the ABAP Dictionary structure SFLIGHT:

TYPES: FLTAB LIKE SORTED TABLE OF SFLIGHT
WITH NON-UNIQUE KEY CARRID CONNID FLDATE.

Variant 2

TYPES itabtype TYPE RANGE OF type. TYPES itabtype LIKE RANGE OF f.

Addition:
... INITIAL SIZE n

Effect

Crates a table type itab with table type STANDARD. The line type is a structure, made up as follows:

SIGN(1) TYPE C
OPTION(2) TYPE C
LOW TYPE type or LIKE f
HIGH TYPE type or LIKE f

Addition

...INITIAL SIZE n

Effect

INITIAL SIZE specifies how many lines of the table are created along with the table. The table size increases dynamically as required - for further information, refer to Performance Notes for Internal Tables. The INITIAL SIZE value has no semantic meaning except in the APPEND SORTED BY statement. If you do not specify an INITIAL SIZE, the system uses 0 as the default value.

Variant 3

TYPES itabtype {TYPE linetype|LIKE lineobj} OCCURS n.

Defines the type itabtype as the type for a standard table without a header line. The key is the default key for internal tables.

This variant is the same as the following type definition:

TYPES itabtype {TYPE STANDARD TABLE OF linetype|
LIKE STANDARD TABLE OF lineobj}
WITH DEFAULT KEY INITIAL SIZE n.

Note

Type names

A type name can be up to 30 characters long. The name may only consist of alphanumeric characters and the underscore character. It may not consist entirely of digits. Special characters such as German umlauts are not allowed. As well as these characters, certain special characters are used internall. However, these should not be used in application programs. SPACE is a reserved name, and cannot therefore be used. Furthermore, you should not use a field in a statement if it has the same name as one of the additions of the keyword (for example: PERFORM SUB USING CHANGING.).

Recommendations for Type Names:

  1. Always start the name with a letter.

  2. Use the underscore to separate compound names (for example, NEW_PRODUCT.)

RELATED POSTS

TABLE TYPES IN SAP

0 comments:

Post a Comment

Privacy Policy

The articles are copyrighted to Technical Information and can only be reproduced given the author's permission.Information furnished in the blog is collected from various Resources.This blog does not host any files on its server. Please report any broken links in comment. If u have any queries contact me at technicalinformation.websites@gmail.com