ABAP - Keyword Documentation →  ABAP - Programming Language →  Creating Objects and Values →  NEW, Instance Operator →  NEW, Internal Tables → 
Mail Feedback

NEW, line_spec

Syntax

... line
  | {LINES OF jtab [FROM idx1] [TO idx2] [STEP n] [USING KEY keyname]} ...


Alternatives:

1. ... line

2. ... LINES OF jtab [FROM idx1] [TO idx2] [STEP n] [USING KEY keyname]

Effect

Specification of one or more lines to be inserted when constructing an internal table with the instance operator NEW.

Alternative 1  

... line




Effect

Specification of a line. For line, the exact same specifications can be made as in the parentheses of an expression NEW line_type( ... ), where line_type is the line type of the internal table and a corresponding line is constructed. The following special features apply here:

Short Form for Structured Line Types  

If the line type of the internal table is a structured type, the following short form can be used:

NEW dtype|#( [let_exp]
             [BASE itab]
             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 form:

NEW dtype|#( [let_exp]
             [BASE itab]
             ( 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 subsequent inner parentheses until the next assignment is made to the corresponding component. Assignments outside of the inner parentheses must be followed by at least one inner parenthesis. Since a component cannot be assigned a value more than once in the construction of a structure, a component that has been assigned a value outside of the inner parentheses can no longer be listed 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.

Hints



Example

Construction of an anonymous internal table with a structured line type with a short form for the first column:

TYPES:
  BEGIN OF t_line,
    col1 TYPE i,
    col2 TYPE i,
  END OF t_line,
  t_itab TYPE TABLE OF t_line WITH EMPTY KEY.

FINAL(dref) = NEW t_itab( col1 = 1 ( col2 = 11 )
                                  ( col2 = 12 )
                                  ( col2 = 13 )
                         col1 = 2 ( col2 = 21 )
                                  ( col2 = 22 )
                                  ( col2 = 23 ) ).

cl_demo_output=>display( dref->* ).

Alternative 2  

... LINES OF jtab [FROM idx1] [TO idx2] [STEP n] [USING KEY keyname]




Effect

Specification of multiple lines. The lines are taken from the internal table jtab and inserted into the target table as a block. The same applies to jtab and the additions FROM, TO, STEP and USING KEY as to the addition LINES OF of the statement INSERT and the block is inserted in accordance with these rules. jtab is a functional operand position.

Hints

Example

Construction of an internal table itab that contains the first three lines and last three lines of the previously constructed internal table alpha.

DATA:
  alpha TYPE TABLE OF string WITH EMPTY KEY,
  itab  LIKE REF TO alpha.

FINAL(abcde) = `abcdefghijklmnopqrstuvwxyz`.
alpha = VALUE #(  FOR j = 0 UNTIL j >= strlen( abcde )
                  ( substring( val = abcde
                               off = j
                               len = 1  ) ) ).

itab = NEW #( ( LINES OF alpha FROM 1 TO 3 )
              ( `-` )
              ( LINES OF alpha FROM lines( alpha ) - 2
                               TO   lines( alpha ) ) ).
cl_demo_output=>display( itab->* ).

Example

Construction of an internal table itab that contains lines of the previously constructed internal table jtab. The additions FROM and STEP define the step size for processing the table jtab: First, every second line starting at the third line is read, second, every third line starting at the second line is read.

TYPES: t_itab TYPE TABLE OF i WITH EMPTY KEY.

FINAL(jtab) = VALUE t_itab( FOR i = 1 UNTIL i > 10 ( i ) ).

FINAL(itab) = NEW t_itab( ( LINES OF jtab FROM 3 STEP 2 )
                         ( LINES OF jtab FROM 2 STEP 3 ) ).