New ABAP Statements [>ABAP 7.40]
- Value Operator
- Move Corresponding
- Inline Declarations
- Conversion Operator
- Instance Operator
- Object References
- Group Iterations
- Iteration Expression
- Table Expression
- String Operations
- Reduction Operator
Value Operator
VALUE type|#( )
Structure
- With # ( # represents a type like this )
TYPES: BEGIN OF ty_blog_head,
key TYPE int4,
title TYPE string,
END OF ty_blog_head.
DATA: ls_blog_head TYPE ty_blog_head.
ls_blog_head = VALUE #( key = 1001
title = 'New ABAP Commands'
).
- With Type ( structured data type )
DATA(ls_new_head) = VALUE ty_blog_head( key = 1002
title = 'Value Operator'
).
- With BASE ( Base object is assigned before individual component is assigned )
In below scenario, ls_new_head value will be updated from ls_blog_head first, then title component value will be assigned.
ls_blog_head = VALUE #( key = 1001 ).
DATA(ls_new_head) = VALUE ty_blog_head( BASE ls_blog_head
title = 'Value Operator'
).
Internal Table
TYPES: tt_blog_heads TYPE STANDARD TABLE OF ty_blog_head
WITH EMPTY KEY.
DATA: lt_blog_heads TYPE tt_blog_heads.
" With #
lt_blog_heads = VALUE #( ( ls_blog_head ) ).
" With Type Specification
DATA(lt_new_heads) = VALUE tt_blog_heads( ( ls_new_head ) ).
" With Base
" First BASE object lt_blog_heads data is updated
" Then Other records are updated
lt_new_heads = VALUE #( BASE lt_blog_heads ( ls_new_head ) ).
Move Corresponding
CORRESPONDING type|#( )
- Without Mapping Rule
Components with Similar Names are assigned
DATA: ls_target_head TYPE ty_blog_head,
ls_source_head TYPE ty_blog_head.
ls_target_head = CORRESPONDING #( ls_source_head ).
- With Mapping Rule
We need to map source field to target field
DATA: BEGIN OF ls_diff_source_head,
diff_key TYPE int4,
diff_title TYPE string,
END OF ls_diff_source_head.
ls_target_head = CORRESPONDING #( ls_diff_source_head
MAPPING key = diff_key
title = diff_title ).
Inline Declarations
- DATA
DATA(lv_text) = 'Inline Declarations'.
DATA(ls_inl_head) = ls_source_head.
DATA(lt_inl_heads) = lt_blog_heads.
" With Loop
LOOP AT lt_blog_heads INTO DATA(ls_temp_blog_head).
ENDLOOP.
" With Select
SELECT
FROM t001w
FIELDS *
INTO TABLE @DATA(lt_plant).
" Importing
CALL METHOD lo_blog->get_blog_data
IMPORTING
it_data = DATA(lt_blog_tab).
- FIELD SYMBOL
ASSIGN lo_blog_ref->* TO FIELD-SYMBOL(<fs_blog_ref>).
" With Loop
LOOP AT lt_blog_heads ASSIGNING FIELD-SYMBOL(<fs_blog_loop>).
ENDLOOP.
" With Read
READ TABLE lt_blog_heads ASSIGNING FIELD-SYMBOL(<fs_blog_read>)
WITH KEY key = '1001'.
Conversion Operator
CONV type|#( )
DATA lv_value TYPE int4.
" Result is 17 integer part of 17.28
lv_value = '5.4' * '3.2'.
" Result is 15, product of Integer 5 & 3
lv_value = CONV i('5.4') * CONV i('3.2').
" Convert Char to String
DATA: lv_conv_text TYPE char20 VALUE 'Conversion Operator'.
DATA(lv_conv_string) = CONV string( lv_conv_text ).
" Conversion allows to pass value between two Internal Tables
" If tables has same row type but different keys
" Or different Category
DATA: lt_diff_heads TYPE STANDARD TABLE OF ty_blog_head WITH KEY key.
lt_blog_heads = CONV #( lt_diff_heads ).
Instance Operator
NEW type|#( )
NEW generates a Data Object or Instance of a Class
- Data Object
" String Object
DATA: lo_ref_string TYPE REF TO string.
lo_ref_string = NEW string( 'Instance' && 'Operator' ).
" Internal Table
DATA: lo_ref_t001w TYPE REF TO t001w_tab.
SELECT * FROM t001w INTO TABLE @DATA(lt_t001w).
" With # ( type like this )
lo_ref_t001w = NEW #( lt_t001w ).
" With Type
DATA(lo_ref2_t001w) = NEW t001w_tab( lt_t001w ).
- Instance of Class
" Without Parameter
DATA: lo_obj TYPE REF TO zcl_class.
lo_obj = NEW #( ).
" With Parameter
DATA: lo_cont TYPE REF TO cl_gui_custom_container.
lo_cont = NEW #( container_name = 'InstanceOperator' ).
" With Type
DATA(lo_grid) = NEW cl_gui_alv_grid( i_parent = lo_cont ).
Object References
REF type|#( )
Creates a data reference variable
DATA: ls_blog_ref TYPE ty_blog_head.
DATA(lo_ref3_blog) = REF #( ls_blog_ref ).
Group Iterations
LOOP AT GROUP
Group the rows then iterate on each group rows.
LOOP AT lt_blog_heads ASSIGNING FIELD-SYMBOL(<fs_blog>)
GROUP BY <fs_blog>-key ASCENDING
ASSIGNING FIELD-SYMBOL(<fs_key>).
LOOP AT GROUP <fs_key> ASSIGNING FIELD-SYMBOL(<fs_rec>).
ENDLOOP.
ENDLOOP.
Iteration Expression
FOR
FOR process an internal table sequentially and return multiple records
- Controlled move of records from Source internal table to Target internal table
lt_blog_heads = VALUE #( FOR <fs_diff> IN lt_diff_heads
WHERE ( key GE 2000 AND key LT 3000 )
( key = <fs_diff>-key
title = <fs_diff>-title )
).
Table Expression
Internal table followed by row specifications in bracket [ ].
In case, specified row is not found, exception of class CX_SY_ITAB_LINE_NOT_FOUND is raised.
" Key Index Read
ls_blog_head = lt_blog_heads[ KEY key INDEX 1 ].
" Free Key Read
ls_blog_head = lt_blog_heads[ title = 'Free Key Read' ].
" Specified Row
ls_blog_head = lt_blog_heads[ 2 ].
String Operations
" Respect Trailing Blanks
DATA(lv_text1) = 'Respect Trailing ' & 'Blanks'.
"Ignore TrailingBlanks
DATA(lv_text2) = 'Ignore Trailing ' && 'Blanks'.
" String Templates
DATA(lv_text3) = |String Templates|.
" & - && have same effect
DATA(lv_text4) = |String | & |Templates|.
DATA(lv_text5) = |String | && |Templates|.
" Place Holder ( Counter = 12 )
DATA(lv_count) = 12.
DATA(lv_text6) = |Counter = { lv_count } |.
" For Key 1001 title is New ABAP Commands
DATA(lv_text7) = |For Key { ls_blog_head-key } title is | &&
|{ lt_blog_heads[ key = ls_blog_head-key ]-title }|.
Reduction Operator
REDUCE type|#( INIT FOR NEXT )
Generates result of type mentioned at type position using single or multiple expressions. Used to reduce set of data objects to single data object. If objective use to REDUCE then do not use VALUE.
" Dleivery Item Detail
SELECT pstyv, lfimg
FROM lips
WHERE werks = '1001'
INTO TABLE @DATA(lt_lips).
" Reduce Table Data to Variable
DATA(lv_sum_qty) = REDUCE lfimg(
INIT lv_qty = 0
FOR <fs_lips> IN lt_lips
NEXT lv_qty = lv_qty + <fs_lips>-lfimg ).