TYPES - key - ABAP Keyword Documentation (2024)

SAP NetWeaver AS ABAP Release 750, ©Copyright 2016 SAP AG. All rights reserved.

ABAP - Keyword Documentation→ABAP - Reference→Declarations→Declaration Statements→Data Types and Data Objects→Declaring Data Types→TYPES→TYPES - TABLE OF→TYPES - tabkeys→

TYPES - key

Quick Reference

Syntax

... { [UNIQUE | NON-UNIQUE]
{ {KEY [primary_key [ALIAS key_name] COMPONENTS] comp1 comp2 ...}
| {DEFAULT KEY} }}
| { EMPTY KEY } ...

Alternatives:

1. ... [UNIQUE|NON-UNIQUE] {KEY ...}|{DEFAULT KEY}

2. ... EMPTY KEY

Alternative 1

... [UNIQUE|NON-UNIQUE] {KEY ...}|{DEFAULT KEY}

Additions

1. ... primary_key COMPONENTS

2. ... ALIAS key_name

Effect

Defines the primary table key of an internal table by specifying components or as a standard key.

Name of the Primary Key

Like secondary keys, the primary key also hasa name with which it is addressed. This name cannot be freely selected and is predefined as "primary_key".It does not have to be explicitly specified when the table is defined since it is always set implicitly. However, it can also be specified before the addition COMPONENTS.

Key Fields

The key fields of the primary key can be defined in the following ways; the order is significant:

  • Individual components comp1 comp2 ... of the row type are specified afterKEY. The row type must be structured and the components cannot be table typesand cannot contain table types as components. For elementary row types, table_line is the only component that can be specified.
  • If the whole table row is to be defined as a key, thepseudo component table_line can be declared as the only component comp after KEY. This is possible for all row types that are not table types or that do not contain tabletypes as components. For structured row types, table_line operates like a listing of each individual component.
  • Specifying the standard keyDEFAULT KEY. The standard key fields of a structured row type are all fieldswith non-numeric elementary data type. The standard key for non-structured row types is the entire tablerow, if the row type itself is not a table type. If there is no corresponding component or if the row type is itself a table type, the standard key isempty – this applies to standard tables only.

The key fields of the primary table key are generally read-only in all operations that change the content of individual rows of a sorted table or hashed table.

Uniqueness of the Primary Key

The UNIQUE or NON-UNIQUE declarations specifythe uniqueness of the primary table key. In the case of a primary table key specified with UNIQUE,a row with specific content of the key fields can appear only once in an internal table of this type. Only NON-UNIQUE can be used forstandard tables; UNIQUE must be used forhashed tables; both can be declared forsorted tables.

The uniqueness declaration can be omitted, which makes the table type partially generic with respect to the primary key declaration. The table type can then only be used fortypings of formal parameters or field symbols. The differences between the table categories are as follows:

  • The addition NON-UNIQUE is expanded implicitly in the case of types for standard tables. A standard table is never generic with respect to uniqueness.
  • Types for sorted tables can be completely generic with respect to uniqueness.
  • Types for hashed tables can be completely generic with respect to uniqueness; a fixed hashed table, however, always has a unique primary key.
  • No uniqueness declaration can be made for the generic table categories ANY TABLE or INDEX TABLE.

Notes

  • The declaration of the primary table key as a standard key can becritical for various reasons. It is best to specify key fields explicitly instead.
  • Structured components in particular can be explicitly specified as key fields, provided that the components meet the other requirements. When a structured key field is evaluated, the rules forstructure comparisons apply.
  • Note that the addition DEFAULT KEY must not be confused with the addition EMPTY KEY. A standard key declared using the addition DEFAULT KEY can beempty unexpectedly in a standard table, whereas EMPTY KEY declares empty primary table keys explicitly for tables with any row types.
  • Static boxes and their components can be key fields of internal tables.

Example

Defines a primary key without an explicitly specified name. The statement has the same meaning as in the following example.

TYPES sbook_tab
TYPE SORTED TABLE
OF sbook
WITH UNIQUE KEY carrid connid fldate bookid.

Addition 1

... primary_key COMPONENTS

Effect

If the key fields are defined by specifying components, the name of the primary key can be specifiedexplicitly in the statement TYPES. However, the predefined name "primary_key"must be specified for primary_key. The addition COMPONENTS must then also be specified before the component is specified.

Note

Explicitly specifying the name primary_key does not enable predefined name"primary_key" to be changed, but does enable an alias name to be specified by using the addition ALIAS.

Example

Defines a primary key with an explicitly specified name. The statement has the same meaning as in the previous example.

TYPES sbook_tab
TYPE SORTED TABLE
OF sbook
WITH UNIQUE KEY primary_key
COMPONENTS carrid connid fldate bookid.

Addition 2

... ALIAS key_name

Effect

An alias name key_name can be defined for the primary key when using sortedtables and hashed tables, as long as the primary key is not generic. The alias name is in the namespace of the secondary key, must comply with thenaming conventions, and must be unique. It enables the primary key to be addressed like a secondary key by means of a self-defined name.

The syntax requires the name primary_key to also be declared explicitly in the definition of the alias name.

Alternative 2

... EMPTY KEY

Effect

Defines an empty primary key of a table type. This variant is possible for standard tables only. An empty table key does not contain any key fields.

Notes

  • When an empty table key is defined explicitly, this means that the internal table is to be handled like an array that is not subject to being ordered by key values.
  • The ordering of a standard table with an empty primary key is determined for the most part by theprimary index. There are no restrictions on related index accesses and loop processing.
  • In statements that evaluate the primary table key to identify rows, an empty table key generally produces unexpected behavior and a syntax check warning. For a list of these statements, seeEmpty Table Key.
  • A table key where EMPTY KEY is used to declare an empty table key explicitlyis not generic with respect to its primary key. This means that the addition EMPTY KEY can be used to prevent a table type from being too generic with respect to its primary key.
  • The explicit declaration of an empty table key using EMPTY KEY is independent of the row type.
  • A standard table with an empty primary key can have non-empty secondary keys.
  • Empty table keys can also be created implicitly when thestandard key is used for standard tables. If anempty table key is to be used, however, it is better to declare it explicitly using EMPTY KEY.

Example

The table in the example below is only intended for a loop in which all rows of the table are processed in a random order.

TYPES addresses TYPE STANDARD TABLE OF scustom-email WITH EMPTY KEY.

DATAemail_tab TYPE addresses.

FIELD-SYMBOLS <email> LIKE LINE OF email_tab.

...

SELECT email
FROM scustom
INTO TABLE @email_tab.

...

LOOP AT email_tab ASSIGNING <email> USING KEY primary_key.
mail_manager->send( address = <email> text = ... ).
ENDLOOP.

TYPES - key - ABAP Keyword Documentation (2024)
Top Articles
How to Read Stock Charts Like a Boss: Beginners Guide +pdf
6 Best Books on Investing
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 6296

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.