Use DATA-to define an Internal Table

Source: Internet
Author: User

DATA-Defining an Internal Table

Variants:

1.Data itab type itabtype [with header line].

2.Data itab {typeTabkindOf Linetype |
LikeTabkindOf lineobj}

With [unique | NON-UNIQUE]Keydef
[Initial size N] [with header line].

3.Data itab {type table of Linetype | like table of lineobj }.

4.Data itab type range of type.
Data itab like range of F.

5.Data itab [type linetype | like lineobj] occurs n
[With header line].

6.Data: Begin of itab occurs N,
...
End of itab [valid between F1 and F2].

In an ABAP Objects context, a more severe syntax check is already med that in other ABAP areas. SeeNew naming conventionsAndLIKEReferences to dictionary types not allowed.

Effect

DefinesInternal table.

To fill and process internal tables, use the statementsINSERT,APPEND,READ TABLE,LOOP,SORT, And so on.

TheOccursOrInitial sizeParameter (OccursValue) determines the number of lines that are created when the table itself is created. However, the table is extended dynamically on demand. For details, referPerformance notes for internal tables.OccursValue, has no other semantic meaning (apart from one exception inAPPEND SORTEDStatement). If you do not specifyInit ial size, The system uses the default value 0.

If you specifyWith header line, The table is created with a header line, that is, a field with the same name. It has the same type as the line type of the table.

This addition is not allowed in an ABAP Objects context. SeeTables with header line not allowed.

Variant 1

Data itab type itabtype [with header line].

Effect

ItabtypeMust be an internal table type that you have already defined usingTYPES. The statement creates an internal table in the program with this type.

In general, the type specification for the table object must be complete. the exception to this is a standard table, in which the key definition may be missing. in this case, the system automatically usesDefault key.

Example

Creating a hashed table by referring to an existing table Type:

Types: Begin of struc, name (10), age type I, end of struc,
Htab type hashed table of struc with unique key name.
Data: Persons type htab.

Variant 2

Data itab {type tabkind of Linetype | like tabkind of lineobj} with [unique | NON-UNIQUE] keydef
[Initial size N] [with header line].

Effect

Creates an internal table in the program with the typeTabkind. Since there are no generic field definitions, you cannot use the table typesAny tableOrIndex Table.

The structure of the table lines is defined by the TypeLinetypeIf you useTypeReference) or by the type of the referred objectLineobj(When you useLikeReference ).

The same rules apply toUNIQUEAndNON-UNIQUEAdditions inDATAStatement as inTYPESDefinition. You may only omit the definition when defining a standard table.

If you do not specifyINITIAL SIZEThe system uses a default initial size of 0.

Variant 3

DATA itab {type table of linetype | like table of lineobj }.

Effect

This is a shortened form of the definition of a standard table. It corresponds

DATA itab {type standard table of linetype |
Like standard table of lineobj} with default key.

Or the old definition (compare variant 4)

DATA itab {TYPE linetype | LIKE lineobj} OCCURS 0.

Variant 4

DATA itab type range of type. DATA itab like range of f.

Additions:

1.... Initial size n
2.... WITH HEADER LINE

Effect

Creates an internal tableItabWith table typeSTANDARD. The line type is a structure with the following components:

SIGN (1) TYPE C
OPTION (2) TYPE C
Low type type bzw. LIKE f
High type type bzw. LIKE f

Addition 1

... Initial size n

Effect

TheINITIAL SIZESpecification determines how many table lines are created when the table itself is created. The table is also dynamically expanded as required. For further information, referPerformance Notes for Internal Tables.INITIAL SIZEValue has no semantic meaning (apart from one exception in the eiAPPEND SORTEDStatement). If you do not specifyINITIAL SIZE, The system uses the default value 0.

Addition 2

... WITH HEADER LINE

This addition is not allowed in an ABAP objects context. SeeTables with Header Lines Not Allowed.

Effect

Creates an internal table and a header line for it, that is, a field with the same name as the internal table and the same type as the line type of the internal table.

Variant 5

DATA itab [TYPE linetype | LIKE lineobj] OCCURS n [with header line].

This variant is not allowed in an ABAP objects context. SeeDeclarationOCCURSNot allowed.

Effect

This variant exists to ensure compatibility with Release 3. X. If you do not specify a line type, the system uses typeCWith length 1. Otherwise, the variant is the same

DATA itab {type standard table of linetype |
Like standard table of lineobj}
Initial size n [with header line].

Example

Types: Begin of line_type,
Name (20) type C,
Age type I,
End of line_type.
Data: Persons type line_type occurs 20,
Persons_wa type line_type.

PERSONS_WA-NAME = 'michael'. PERSONS_WA-AGE = 25.
Append persons_wa to persons.
PERSONS_WA-NAME = 'Gabriel '. PERSONS_WA-AGE = 22.
Append persons_wa to persons.

The internal tablePersonsNow contains two entries.

Variant 6

Data: Begin of itab occurs N ,...
End of itab [valid between F1 and F2].

This variant is not allowed in an ABAP objects context. SeeDeclarationOCCURSNot allowed.

Effect

Creates an internal tableItabWith TypeSTANDARDAnd a header line. The line type consists of the fields"Begin of itab OCCURS n"And"End of itab".

UseValid between f1 AND f2Addition to specify that the componentsF1AndF2Of the internal tableItabContain a line-based validity interval. You can only use this addition in conjunction withPROVIDEStatement.

Example

DATA: begin of persons occurs 20,
NAME (20 ),
Age type I,
End of persons.
PERSONS-NAME = 'Michael '.
PERSONS-AGE = 25.
Append persons.
PERSONS-NAME = 'Gabriel '.
PERSONS-AGE = 22.
Append persons.

The internal table consists of two entries.PERSONSAlso has a header line (Work area), which is an interface between the program and the actual table contents.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.