Zoeken…


Typen interne tabellen

DATA: <TABLE NAME> TYPE <SORTED|STANDARD|HASHED> TABLE OF <TYPE NAME> 
      WITH <UNIQUE|NON-UNIQUE> KEY <FIELDS FOR KEY>.

Standaard tafel

In deze tabel worden alle items lineair opgeslagen en worden records op een lineaire manier geopend. Voor grote tafelformaten kan de toegang tot de tafel traag zijn.

Gesorteerde tabel

Vereist de toevoeging WITH UNIQUE | NON-UNIQUE KEY . Zoeken gaat snel vanwege het uitvoeren van een binaire zoekopdracht. Vermeldingen kunnen niet aan deze tabel worden toegevoegd, omdat hierdoor de sorteervolgorde kan worden onderbroken, dus ze worden altijd ingevoegd met het trefwoord INSERT .

Hashed-tafel

Vereist de toevoeging WITH UNIQUE | NON-UNIQUE KEY . Gebruikt een eigen hash-algoritme om sleutel / waarde-paren te onderhouden. Theoretisch kunnen zoekopdrachten zo langzaam zijn als STANDARD tabel, maar praktisch zijn ze sneller dan een SORTED tabel die een constante hoeveelheid tijd in SORTED neemt, ongeacht de grootte van de tabel.

Verklaring van interne ABAP-tabellen

Interne tabelverklaring op basis van lokale typedefinitie

" 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.

Verklaring op basis van databasetabel

DATA t_flightb TYPE STANDARD TABLE OF flightb.

Inline interne tabelverklaring

Vereist ABAP-versie> 7.4

TYPES t_itab TYPE STANDARD TABLE OF i WITH EMPTY KEY.

DATA(t_inline) = VALUE t_itab( ( 1 ) ( 2 ) ( 3 ) ).

Interne tabel met headerregels

In ABAP zijn er tabellen met kopregels en tabellen zonder kopregels. Tabellen met kopregels zijn een ouder concept en mogen niet worden gebruikt bij nieuwe ontwikkeling.

Interne tabel: standaardtabel met / zonder kopregel

Deze code declareert de tabel i_compc_all met de bestaande structuur van 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 tabel: gehashte tabel met / zonder kopregel

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

Aangifte van een werkgebied voor tabellen zonder kop

Een werkgebied (meestal afgekort wa ) heeft exact dezelfde structuur als de tabel, maar kan slechts één regel bevatten (een WA is een structuur van een tabel met slechts één dimensie).

DATA: i_compc_all_line LIKE LINE OF i_compc_all.

Lezen, schrijven en invoegen in interne tabellen

Lezen, schrijven en invoegen in interne tabellen met een kopregel:

" 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.

Herinnering: interne tabellen met kopregels zijn verboden in objectgeoriënteerde contexten. Gebruik van interne tabellen zonder kopregels wordt altijd aanbevolen.

Lezen, schrijven en invoegen in interne tabellen zonder kopregel:

" 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


Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow