Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Creating Objects and Values →  NEW - Instance Operator →  NEW - Internal Tables 

NEW - line_spec

Other versions: 7.31 | 7.40 | 7.54

Syntax


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

Alternatives

1. ... line
2. ... LINES OF jtab [FROM idx1] [TO idx2] [USING KEY keyname]

Effect

Specifies one or more rows to be inserted when constructing an internal table with the instance operator NEW.

Alternative 1

... line

Effect

Specifies a row. line can be specified in exactly the same way as in the parenthesis of an expression NEW line_type( ... ), with one exception. Here, line_type is the row type of the internal table and a corresponding row is constructed.

The exception to this rule are tabular row types. The syntax in the inner parenthesis does not allow further parentheses to be nested directly.

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|#( [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:

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 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. The expression VALUE line_type( ... ) can be specified to construct the content of a tabular row, where line_type is the tabular row type.

  • Specifying CONV line_type( ... ) for the inserted values is also a way of meeting the compatibility requirement with the row type.

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

Alternative 2

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

Effect

Specifies multiple rows. The rows 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, 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.


Notes

  • The rows from jtab are inserted into the target table using the table key only, which means that jtab must be compatible with the target type.

  • If there is a conflict with an existing unique table key, a non-handleable exception is always raised when inserting multiple rows from an internal table using the statement INSERT.

  • When standard tables are created, the rows of the table jtab are appended to the target table in the same way as with the statement APPEND LINES OF.

Example

Constructs an internal table itab containing the first and last three rows of the previously constructed table alpha.

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

alpha = VALUE #(  FOR j = 0 UNTIL j >= strlen( sy-abcde ) 
                 ( substring( val = sy-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->* ).