SAP NEW CONSTRUCTOR PARAMS ITAB

Get Example source ABAP code based on a different SAP table
  


ARTICLE

NEW - Internal Tables

Syntax
... NEW dtype|#( ( ... ) ( ... ) ... ) ...

Effect
If dtype is a tabular data type or # represents a type like this, further parentheses can be added at the top level in the parentheses after dtype. Each inner parenthesis inserts a row into the new internal table.
In jeder inneren Klammer können mit einer Ausnahme genau die Angaben gemacht werden, wie in der Klammer eines Ausdrucks NEW ltype( ... ) , wobei ltype der Zeilentyp der internen Tabelle ist. The exception to this rule are tabular row types. The syntax in the inner parenthesis does not allow further parentheses to be nested directly.
Für jede innere Klammer wird gemäß der angegebenen Parameter ein Wert konstruiert und nach den Regeln für die Anweisung INSERT ... INTO TABLE direkt in die interne Tabelle eingefügt. The object is inserted in the order of the parentheses. The constructed value must mee the requirements of the statement INSERT for inserting work areas using table keys and therefore be compatible with the row type. There is one exception to this: When constructing a standard table, where the rows are only appended, the value can be shorter than the row length (for row types c and x), in which case it is padded on the right with blanks or hexadecimal 0.

Short Form for Structured Row Types
If the row type of the internal table is a structured type, the following short form can be used: NEW dtype|#( col1 = dobj11 ... ( col2 = dobj12 col3 = dobj13 ... )
( col2 = dobj22 col3 = dobj23 ... )
...
col1 = dobj31 col2 = dobj32 ... ( col3 = dobj33 ... )
( col3 = dobj43 ... )
... ).
This has the same semantics as the following: NEW dtype|#( ( col1 = dobj11 ... col2 = dobj12 col3 = dobj13 ... )
( col1 = dobj11 ... col2 = dobj22 col3 = dobj23 ... )
...
( col1 = dobj31 col2 = dobj32 ... col3 = dobj33 ... )
( col1 = dobj31 col2 = dobj32 ... col3 = dobj43 ... )
... ).
Values can be assigned to individual structure components outside of the inner parentheses. An assignment of this type applies to all following inner parentheses until the next assignment is made to the component in question. Assignments outside of the inner parentheses must be followed by at least one inner parenthesis. A component cannot be assigned a value more than once in the construction of a structure, which means that a component assigned a value outside of the inner parentheses can no longer be specified in an inner parenthesis. A component can be specified again outside the inner parentheses and any components previously specified in an inner parenthesis can also be listed outside the parenthesis.

Notes
The restriction that the content of tabular row types cannot be constructed directly in the inner parentheses applies for reasons of legibility (human and machine) and is not a functional restriction. Um den Inhalt einer tabellarischen Zeile zu konstruieren, kann einfach der Ausdruck VALUE ltype( ... ) angegeben werden, wobei ltype der tabellarische Zeilentyp ist.
Über die Angabe von VALUE ltype( ... ) oder CONV ltype( ... ) für die einzufügenden Werte kann, die Forderung nach Kompatibilität mit dem Zeilentyp erfüllt werden.
The short form for structured row types enables columns of internal tables that are to be given an identical value in blocks to be filled more easily.

Example
Constructs an anonymous internal table with an elementary row type and fills it with three rows. The second row inserted is initial. TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY.

DATA dref TYPE REF TO data.

dref = NEW t_itab( ( 1 ) ( ) ( 3 ) ).

Beispiel
Constructs an anonymous internal table with a structure row type with substructures and tabular components. TYPES: BEGIN OF t_struct1,
col1 TYPE i,
col2 TYPE i,
END OF t_struct1,
BEGIN OF t_struct2,
col1 TYPE i,
col2 TYPE t_struct1,
col3 TYPE TABLE OF t_struct1 WITH EMPTY KEY,
END OF t_struct2,
t_itab TYPE TABLE OF t_struct2 WITH EMPTY KEY.

DATA dref TYPE REF TO data.

dref = NEW t_itab( ( col1 = 1
col2-col1 = 1
col2-col2 = 2
col3 = VALUE #( ( col1 = 1 col2 = 2 )
( col1 = 3 col2 = 4 ) ) )
( col1 = 2
col2-col1 = 2
col2-col2 = 4
col3 = VALUE #( ( col1 = 2 col2 = 4 )
( col1 = 6 col2 = 8 ) ) ) ).

Examples
See also the examples for the value operator VALUE.