Types Type Table of With KEY Data Type Ref To Create Data NEW NEW
Types Type Table of With KEY Data Type Ref To Create Data NEW NEW
The new declaration operators DATA and FIELD-SYMBOL make inline declarations.
Example1
Before: 7.4 DATA: lv_text TYPE STRING.
lv_text = ‘Vistex’.
After 7.4: Data(lv_text) = ‘Vistex’.
Constructor Operators:
1. New: This constructor expression with the instance operator NEW creates an anonymous
data object or an instance of a class.
Example:
TYPES ty_itab TYPE TABLE OF t100 WITH EMPTY KEY.
DATA ref_data TYPE REF TO ty_itab.
ref_data = NEW t_itab( ). We can also provide the dtype after NEW
2. Value: This constructor expression with the VALUE operator creates a result of a data type
specified using type.
Syntax: … VALUE type( )…
Example 1:
TYPES:
BEGIN OF ty_data,
kunnr TYPE kunnr,
name1 TYPE name1,
ort01 TYPE ort01,
land1 TYPE land1,
END OF ty_data.
TYPES: tt_data TYPE STANDARD TABLE OF ty_data WITH DEFAULT KEY.
DATA(lt_multi_comp) =
VALUE tt_data( ( kunnr = '123' name1 = 'ABCD' ort01 = 'LV' land1 = 'NV' )
( kunnr = '456' name1 = 'XYZ' ort01 = 'LA' land1 = 'CA' )
).
Example 2:
TYPES: BEGIN OF ty_nest,
key1 TYPE i,
key2 TYPE i,
END OF ty_nest.
*Option1
DATA(lwa_struct1) = VALUE ty_struct( key1 = 'Vistex'
key2-key1 = 1
key2-key2 = 2 ).
*Option2
DATA(lwa_nest) = VALUE ty_nest( key1 = 2
key2 = 3 ).
DATA(lwa_struct2) = VALUE ty_struct( key1 = 'Asia'
key2 = lwa_nest ).
*Option3
DATA(lwa_struct3) = VALUE ty_struct( key1 = 'Pacific'
key2 = VALUE #( key1 = 1
key2 = 2 ) ).
Example1:
DATA: lt_data LIKE SORTED TABLE OF lwa_data WITH UNIQUE KEY field1.
DATA: lv_index TYPE i VALUE '1'.
DATA: lv_temp TYPE string.
lwa_data-field1 = 1.
lwa_data-field2 = 'Vistex'.
APPEND lwa_data to lt_data.
lwa_data-field1 = 2.
lwa_data-field2 = 'Asia'.
APPEND lwa_data to lt_data.
Actual parameters specified after call function have now become a general expression position.
The table function line_index can be used to identify a row number in an index of an internal
table.
Syntax:
... LET {var1 = rhs1}|{<fs1> = wrexpr1}
{var2 = rhs2}|{<fs2> = wrexpr2} ... IN ...
Example:
Syntax:
Example:
BEGIN OF ty_temp1,
col1 TYPE ty_de,
col2 TYPE ty_de,
END OF ty_temp1,
BEGIN OF ty_temp2,
col2 TYPE ty_de,
col3 TYPE ty_de,
END OF ty_temp2,
BEGIN OF ty_data1,
col1 TYPE ty_de,
col2 TYPE ty_de,
col3 TYPE STANDARD TABLE OF ty_temp1 WITH EMPTY KEY,
END OF ty_data1,
BEGIN OF ty_data2,
col2 TYPE ty_de,
col3 TYPE STANDARD TABLE OF ty_temp2 WITH EMPTY KEY,
col4 TYPE ty_de,
END OF ty_data2.
ls_struct1 = VALUE #(
col1 = 'A1'
col2 = 'A2'
col3 = VALUE #( ( col1 = 'A11' col2 = 'A12' )
( col1 = 'A21' col2 = 'A22' ) ) ).
ls_struct2 = VALUE #(
col2 = 'B1'
col3 = VALUE #( ( col2 = 'B11' col3 = 'B12' )
( col2 = 'B21' col3 = 'B22' ) )
col4 = 'B2' ).
MOVE-
CORRESPONDING ls_struct1 to ls_struct2. " Here col4 retains its values.
The col3 is changed entirely
MOVE-
CORRESPONDING ls_struct1 to ls_struct2 EXPANDING NESTED TABLES. " Here col4
retains its values. Since COL3 has col2 as same node only col2 is moved and
col3 is cleared in struct2
Syntax:
MOVE-CORRESPONDING itab1 TO itab2 [EXPANDING NESTED TABLES] [KEEPING TARGET LINES].
Example:
lt_tab1 = VALUE #(
( col1 = 'A11'
col2 = 'A12'
col3 = VALUE #( ( col1 = 'A11' col2 = 'A12' )
( col1 = 'A21' col2 = 'A22' ) ) )
( col1 = 'B11'
col2 = 'B12'
col3 = VALUE #( ( col1 = 'B11' col2 = 'B12' )
( col1 = 'B21' col2 = 'B22' ) ) )
( col1 = 'C11'
col2 = 'C12'
col3 = VALUE #( ( col1 = 'C11' col2 = 'C12' )
( col1 = 'C21' col2 = 'C22' ) ) ) ).
lt_tab2 = VALUE #(
( col2 = 'X11'
col3 = VALUE #( ( col2 = 'X11' col3 = 'X12' )
( col2 = 'X21' col3 = 'X22' ) )
col4 = 'X12' )
( col2 = 'Y11'
col3 = VALUE #( ( col2 = 'Y11' col3 = 'Y12' )
( col2 = 'Y21' col3 = 'Y22' ) )
col4 = 'Y12' )
( col2 = 'Z11'
col3 = VALUE #( ( col2 = 'Z11' col3 = 'Z12' )
( col2 = 'Z21' col3 = 'Z22' ) )
col4 = 'Z12' ) ).
MOVE-
CORRESPONDING lt_tab1 to lt_tab2. " Here Col4 is get cleared and nested
table gets copied fully.
MOVE-
CORRESPONDING lt_tab1 to lt_tab2 keeping target lines. " the new results are
appended to the previous values
MOVE-
CORRESPONDING lt_tab1 to lt_tab2 expanding nested tables. " the nested table
is get checked and moved only the columns matched fields
MOVE-
CORRESPONDING lt_tab1 to lt_tab2 expanding nested tables keeping target lines
Table Comprehensions:
Table comprehensions are an enhancement of the NEW and VALUE operator and are used to create the
content of the internal tables.
Example:
TYPES: BEGIN OF ty_line1,
col1 TYPE i,
col2 TYPE i,
col3 TYPE i,
col4 TYPE i,
END OF ty_line1,
BEGIN OF ty_line2,
col1 TYPE i,
col2 TYPE i,
END OF ty_line2.
DATA: lt_tab1 TYPE STANDARD TABLE OF ty_line1 with empty key with unique sort
ed key key components col1,
lt_tab2 TYPE STANDARD TABLE OF ty_line1 with empty key,
lt_tab3 TYPE STANDARD TABLE OF ty_line1 with empty key,
lt_tab4 TYPE STANDARD TABLE OF ty_line2 with empty key,
lt_tab5 TYPE STANDARD TABLE OF i with empty key.
lt_tab1 = value #(
FOR j = 41 then j - 10 UNtil j < 10
( col1 = j col2 = j + 1 col3 = j + 2 col4 = j + 3 ) ).
lt_tab2 = value #(
FOR lwa_tab2 IN lt_tab1 where ( col1 < 30 )
( lwa_tab2 ) ).
lt_tab3 = value #(
FOR lwa_tab2 IN lt_tab1 INDEX INTO lv_index where ( col1 = 21 )
( lines of lt_tab1 from lv_index ) ).
lt_tab4 = value #(
for lwa_tab2 IN lt_tab1 from 2 to 3
( col1 = lwa_tab2-col2 col2 = lwa_tab2-col3 ) ).
Example 2:
TYPES: BEGIN OF ty_line1,
key TYPE c LENGTH 1,
col1 TYPE i,
col2 TYPE i,
END OF ty_line1,
ty_tab1 TYPE STANDARD TABLE OF ty_line1 with empty key,
BEGIN OF ty_line2,
key TYPE c LENGTH 1,
col1 TYPE i,
col2 TYPE i,
END OF ty_line2,
ty_tab2 TYPE STANDARD TABLE OF ty_line2 with empty key,
BEGIN OF ty_line3,
key TYPE c LENGTH 1,
col11 TYPE i,
col12 TYPE i,
col21 TYPE i,
col22 TYPE i,
END OF ty_line3,
ty_tab3 TYPE STANDARD TABLE OF ty_line3 WITH empty key.
lt_tab2 = value #(
( key = 'a' col1 = 13 col2 = 14 )
( key = 'a' col1 = 23 col2 = 24 )
( key = 'a' col1 = 33 col2 = 34 ) ).
Table Filtering:
Filter operator is used to filter the contents of an internal table.
... FILTER type( itab [EXCEPT] [IN ftab] [USING KEY keyname]
WHERE c1 op f1 [AND c2 op f2 [...]] ) ...
DATA: lt_tab1 TYPE TABLE OF z205_emphd WITH EMPTY KEY WITH NON-
UNIQUE SORTED KEY emp COMPONENTS empid fname,
lv_empid TYPE /ngv/bptremply VALUE '009',
lv_fname TYPE /ngv/b0fname VALUE 'LEELA PRASAD'.
ls_filter-eid = '009'.
ls_filter-fnm = 'LEELA PRASAD'.
APPEND ls_filter to lt_filter.
Union:
It is used to combine the result from 2 different tables using Union
operator.
Switch Operator:
DATA: lv_flag TYPE c value 'X'.