ABAP
Interne Tabellen
Suche…
Arten von internen Tabellen
DATA: <TABLE NAME> TYPE <SORTED|STANDARD|HASHED> TABLE OF <TYPE NAME>
WITH <UNIQUE|NON-UNIQUE> KEY <FIELDS FOR KEY>.
Standardtabelle
In dieser Tabelle werden alle Einträge linear gespeichert, und auf Datensätze wird linear zugegriffen. Bei großen Tabellengrößen kann der Tabellenzugriff langsam sein.
Sortierte Tabelle
Erfordert den Zusatz WITH UNIQUE | NON-UNIQUE KEY . Die Suche ist aufgrund der binären Suche schnell. Einträge können nicht an diese Tabelle angehängt werden, da dies die Sortierreihenfolge INSERT . Sie werden daher immer mit dem Schlüsselwort INSERT eingefügt.
Hash-Tabelle
Erfordert den Zusatz WITH UNIQUE | NON-UNIQUE KEY . Verwendet einen proprietären Hash-Algorithmus, um Schlüsselwertpaare zu erhalten. Theoretisch kann die Suche so langsam sein wie die STANDARD Tabelle, aber praktisch sind sie schneller als eine SORTED Tabelle, die unabhängig von der Größe der Tabelle eine konstante Zeit benötigt.
Deklaration interner ABAP-Tabellen
Interne Tabellendeklaration basierend auf lokaler Typdefinition
" Declaration of type
TYPES: BEGIN OF ty_flightb,
id TYPE fl_id,
dat TYPE fl_date,
seatno TYPE fl_seatno,
firstname TYPE fl_fname,
lastname TYPE fl_lname,
fl_smoke TYPE fl_smoker,
classf TYPE fl_class,
classb TYPE fl_class,
classe TYPE fl_class,
meal TYPE fl_meal,
service TYPE fl_service,
discout TYPE fl_discnt,
END OF lty_flightb.
" Declaration of internal table
DATA t_flightb TYPE STANDARD TABLE OF ty_flightb.
Deklaration basierend auf Datenbanktabelle
DATA t_flightb TYPE STANDARD TABLE OF flightb.
Interne Deklaration der Inline-Tabelle
Erfordert ABAP-Version> 7.4
TYPES t_itab TYPE STANDARD TABLE OF i WITH EMPTY KEY.
DATA(t_inline) = VALUE t_itab( ( 1 ) ( 2 ) ( 3 ) ).
Interne Tabelle mit Headerzeilen-Deklaration
In ABAP gibt es Tabellen mit Kopfzeilen und Tabellen ohne Kopfzeilen. Tabellen mit Kopfzeilen sind ein älteres Konzept und sollten bei Neuentwicklungen nicht verwendet werden.
Interne Tabelle: Standardtabelle mit / ohne Kopfzeile
Dieser Code deklariert die Tabelle i_compc_all mit der vorhandenen Struktur von compc_str .
DATA: i_compc_all TYPE STANDARD TABLE OF compc_str WITH HEADER LINE.
DATA: i_compc_all TYPE STANDARD TABLE OF compc_str.
Interne Tabelle: Hash-Tabelle mit / ohne Kopfzeile
DATA: i_map_rules_c TYPE HASHED TABLE OF /bic/ansdomm0100 WITH HEADER LINE
DATA: i_map_rules_c TYPE HASHED TABLE OF /bic/ansdomm0100
Deklaration eines Arbeitsbereichs für Tabellen ohne Kopf
Ein Arbeitsbereich (im Allgemeinen als wa abgekürzt) hat dieselbe Struktur wie die Tabelle, kann jedoch nur eine Zeile enthalten (ein WA ist eine Struktur einer Tabelle mit nur einer Dimension).
DATA: i_compc_all_line LIKE LINE OF i_compc_all.
Lesen, Schreiben und Einfügen in interne Tabellen
Lesen, Schreiben und Einfügen in interne Tabellen mit Kopfzeile:
" Read from table with header (using a loop):
LOOP AT i_compc_all. " Loop over table i_compc_all and assign header line
CASE i_compc_all-ftype. " Read cell ftype from header line from table i_compc_all
WHEN 'B'. " Bill-to customer number transformation
i_compc_bil = i_compc_all. " Assign header line of table i_compc_bil with content of header line i_compc_all
APPEND i_compc_bil. " Insert header line of table i_compc_bil into table i_compc_bil
" ... more WHENs
ENDCASE.
ENDLOOP.
Zur Erinnerung: Interne Tabellen mit Kopfzeilen sind in objektorientierten Kontexten verboten. Die Verwendung interner Tabellen ohne Kopfzeilen wird immer empfohlen.
Lesen, Schreiben und Einfügen in interne Tabellen ohne Kopfzeile:
" Loop over table i_compc_all and assign current line to structure i_compc_all_line
LOOP AT i_compc_all INTO i_compc_all_line.
CASE i_compc_all_line-ftype. " Read column ftype from current line (which as assigned into i_compc_all_line)
WHEN 'B'. " Bill-to customer number transformation
i_compc_bil_line = i_compc_all_line. " Copy structure
APPEND i_compc_bil_line TO i_compc_bil. " Append structure to table
" more WHENs ...
ENDCASE.
ENDLOOP.
" Insert into table with Header:
INSERT TABLE i_sap_knb1. " insert into TABLE WITH HEADER: insert table header into it's content
insert i_sap_knb1_line into table i_sap_knb1. " insert into HASHED TABLE: insert structure i_sap_knb1_line into hashed table i_sap_knb1
APPEND p_t_errorlog_line to p_t_errorlog. " insert into STANDARD TABLE: insert structure / wa p_t_errorlog_line into table p_t_errorlog_line