- Assignments
- Data Types
- Enumerated Types (7.51)
- Virtual Sort (7.52)
- Indicators (7.55)
- LOOP AT……STEP n (7.57)
- CORRESPONDING Operator Using the Additions MAPPING and DEFAULT (7.58)
1. Asignments
1.1 Numeric calculation assignment (7.54)
Assignment | Before 7.54 | Since 7.54 |
+=, -=, *=, /= |
DATA(num) = 2. num = num + 1. |
DATA(num) = 2. num += 1. |
1.2 String assignment (7.54)
Assignment | Before Version | Since Version |
&&= |
DATA text TYPE string. text = text && | Me!| |
DATA text TYPE string. text &&= | Me!|. |
Before 7.57 | Since 7.57 |
DATA(field) = ‘exists’. ASSIGN (‘field’) TO FIELD-SYMBOL(<fs>). ASSIGN (‘nofield’) TO <fs>. |
DATA(field) = ‘exists’. ASSIGN (‘field’) TO FIELD-SYMBOL(<fs>). ASSIGN (‘nofield’) TO <fs> ELSE UNASSIGN. IF <fs> IS ASSIGNED. |
1.4 ASSIGN struct-(comp) (7.57)
Before 7.57 | Since 7.57 |
BEGIN OF tystruc, FIELD-SYMBOLS: <struc> TYPE any, <comp> TYPE any. ASSIGN struc TO <struc>. DO 1000 TIMES. “runs in approx. 60 ms |
ASSIGN struc TO <struc>. DO 1000 TIMES. “runs in approx. 50 ms “Or alternatively DO 1000 TIMES. “Runs in approx. 50 ms |
1.5 RETURN [expr] for functional methods (7.58)
Before Version | Since Version |
METHOD square. “IMPORTING root TYPE i r = square. |
METHOD square. “IMPORTING root TYPE i ENDMETHOD. |
2. Data Types
Version | New Data Type | Description |
7.50 |
INT8 |
8-byte integers with signs Value range: -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 Output length: 20 |
7.54 |
DECFLOAT16 DECFLOAT34 |
Decimal floating point number DF16_SCL and DF34_SCL now obsolete |
7.54 |
DATN |
Date in internal format of database Initial value: 0 (DATS has initial value 00000000) |
7.54 |
TIMN |
Time in internal format of database Initial value: 0 (TIMNS has initial value 000000) |
7.54 |
UTCLONG |
Time stamp (exact to 100 ns) Valid Places: 27 Initial value: 0 |
7.54 |
GEOM_EWKB |
Geometric data in EWKB representation Initial value: Empty string |
3. Enumerated Types (7.51)
Syntax
TYPES BEGIN OF ENUM enum_type [STRUCTURE struc] [BASE TYPE dtype].
TYPES val1 [VALUE IS INITIAL],
TYPES val2 [VALUE val],
TYPES val3 [VALUE val],
…
TYPES END OF ENUM enum_type [STRUCTURE struc].
Description
Defines a list of allowed values.
Example
Syntax checker flags invalid assignment:
TYPES: BEGIN OF ENUM planet, DATA planet type planet. planet = earth. |
4. Virtual Sort (7.52)
Syntax
cl_abap_itab_utilities=>virtual_sort( IMPORTING IM_VIRTUAL_SOURCE
IM_FILTER_INDEX
RETURNING RT_VIRTUAL_INDEX )
Description
For the given source table(s) and filter criteria a structure index numbers is returned. These index numbers are in the required order to effectuate the requested sort. This index structure can be used to create a sorted table(s).
Examples
Single Table
For full example see class cl_demo_virtual_sort_simple.
ITAB
COL1 | COL2 | COL3 | COL4 |
6 | 4 | G | I |
1 | 7 | D | F |
6 | 9 | A | B |
2 | 4 | H | B |
1 | 4 | A | H |
4 | 3 | I | J |
10 | 8 | E | E |
2 | 1 | E | D |
9 | 5 | C | G |
1 | 1 | G | B |
v_index
DATA(v_index) = cl_abap_itab_utilities=>virtual_sort( |
Result: v_index = (10, 5, 2, 8, 4, 6, 1, 3, 9, 7) |
sorted_tab
DATA sorted_tab TYPE itab. sorted_tab = VALUE #( FOR idx IN v_index ( itab[ idx ] ) ). |
COL1 | COL2 | COL3 | COL4 |
1 | 1 | G | B |
1 | 4 | A | H |
1 | 7 | D | F |
2 | 1 | E | D |
2 | 4 | H | B |
4 | 3 | I | J |
6 | 4 | G | I |
6 | 9 | A | B |
9 | 5 | C | G |
10 | 8 | E | E |
v_index (re-assigned)
v_index = cl_abap_itab_utilities=>virtual_sort( im_virtual_source = VALUE #( ( source = REF #( itab ) components = VALUE #( ( name = ‘col3’ astext = abap_true descending = abap_true ) ( name = ‘col4’ astext = abap_true descending = abap_true ) ) ) ) ). |
Result: v_index = (6, 4, 1, 10, 7, 8, 2, 9, 5, 3) |
sorted_tab (re-assigned)
sorted_tab = VALUE #( FOR idx IN v_index ( itab[ idx ] ) ). |
4 | 3 | I | J |
2 | 4 | H | B |
6 | 4 | G | I |
1 | 1 | G | B |
10 | 8 | E | E |
2 | 1 | E | D |
1 | 7 | D | F |
9 | 5 | C | G |
1 | 4 | A | H |
6 | 9 | A | B |
Two tables
For full example see class cl_demo_virtual_sort_combined.
ITAB1
COL1 | COL2 |
0 | 0 |
1 | 1 |
1 | 1 |
1 | 1 |
0 | 0 |
1 | 0 |
1 | 0 |
1 | 0 |
0 | 0 |
1 | 1 |
ITAB2
COL1 | COL2 |
X | X |
X | X |
Y | Y |
X | Y |
X | X |
Y | Y |
X | Y |
X | Y |
Y | X |
Y | Y |
v_index
v_index = cl_abap_itab_utilities=>virtual_sort( im_virtual_source = VALUE #( ( source = REF #( itab1 ) components = VALUE #( ( name = ‘col1’ ) ( name = ‘col2’ ) ) ) ( source = REF #( itab2 ) components = VALUE #( ( name = ‘col1’ astext = abap_true descending = abap_true ) ( name = ‘col2’ astext = abap_true descending = abap_true ) ) ) ) ). |
Result: v_index = (9, 1, 5, 6, 7, 8, 3, 10, 4, 2) |
comb_tab
TYPES: FINAL(comb_tab) = VALUE test_tab( FOR i = 1 UNTIL i > 10 |
COL11 | COL12 | COL21 | COL22 |
0 | 0 | Y | X |
0 | 0 | X | X |
0 | 0 | X | X |
1 | 0 | Y | Y |
1 | 0 | X | Y |
1 | 0 | Y | Y |
1 | 1 | Y | Y |
1 | 1 | Y | Y |
1 | 1 | X | Y |
1 | 1 | X | X |
5. Indicators (7.55)
Syntax
TYPES dtype TYPE struct WITH INDICATORS ind [{TYPE type}]. […AS BITFIELD from 7.56]
UPDATE dbtab FROM TABLE itab INDICATORS [NOT] SET STRUCTURE set_ind.
Description
When used with “TYPES” it adds a component ind at the end of the structure struc the same number of first-level components.
This can be used together with UPDATE dbtab to only update the components flagged for update.
Example
For full example see class cl_demo_update_set_indicator.
DB table DEMO_UPDATE:
ID | COL1 | COL2 | COL3 | COL4 |
A | 1 | 10 | 100 | 0 |
B | 2 | 20 | 200 | 0 |
C | 3 | 30 | 300 | 0 |
D | 4 | 40 | 400 | 0 |
E | 5 | 50 | 500 | 0 |
F | 6 | 60 | 600 | 0 |
Internal table ind_tab:
TYPES ind_wa TYPE demo_update WITH INDICATORS col_ind ind_tab = VALUE #( |
ID | COL1 | COL2 | COL3 | COL4 | COL_IND |
D | 0 | 0 | 0 | 4000 | X |
E | 0 | 0 | 0 | 5000 | X |
F | 0 | 0 | 0 | 6000 | X |
Update DB:
UPDATE demo_update FROM TABLE @IND_tab INDICATORS SET STRUCTURE col_ind. |
DB table DEMO_UPDATE:
ID | COL1 | COL2 | COL3 | COL4 |
A | 1 | 10 | 100 | 0 |
B | 2 | 20 | 200 | 0 |
C | 3 | 30 | 300 | 0 |
D | 4 | 40 | 400 | 4000 |
E | 5 | 50 | 500 | 5000 |
F | 6 | 60 | 600 | 6000 |
6. MOVE-CORRESPONDING … EXPANDING NESTED TABLES KEEPING TARGET LINES (7.56)
Example
For full example see class cl_demo_move_crrspndng_itab.
Given 2 internal tables
MOVE-CORRESPONDING itab1 TO itab2.
MOVE-CORRESPONDING itab1 TO itab2 KEEPING TARGET LINES.
MOVE-CORRESPONDING itab1 TO itab2 EXPANDING NESTED TABLES.
MOVE-CORRESPONDING itab1 TO itab2 EXPANDING NESTED TABLES
KEEPING TARGET LINES.
7. LOOP AT……STEP n (7.57)
Description
STEP can be used with LOOP, FOR, APPEND, DELETE, INSERT, VALUE and NEW.
For LOOP and FOR, if n is negative, then the loop starts at the last line of the table and goes backwards with a step size of n.
Example
For full example see class cl_demo_loop_at_itab_using_stp.
DATA itab TYPE HASHED TABLE OF i WITH UNIQUE KEY table_line itab = VALUE #( ( 4 ) ( 3 ) ( 7 ) ( 11 ) ( 1 ) ( 5 ) ). LOOP AT itab ASSIGNING <fs> STEP 2. |
Result: result = [(0, 0, 0) (4, 7, 1)] “Note tabix is always 0. |
LOOP AT itab ASSIGNING <fs> STEP -2. tabix = sy-tabix. result = VALUE #( BASE result ( tabix = tabix value = <fs> ) ). ENDLOOP |
Result: result = [(0, 0, 0) (5, 11, 3)] “Note tabix is always 0. |
8. CORRESPONDING Operator Using the Additions MAPPING and DEFAULT (7.58)
Syntax
CORRESPONDING #( struc1 MAPPING t1 = [s1] DEFAULT expr…)
Explanation
Where struc1 is the source structure and s1 is a component of the source structure.
When s1 is supplied the result of the expression (expr) is only assigned if s1 is initial. Else s1 is assigned.
When s1 is not supplied then the result of the expression is always assigned regardless of whether s1 is initial.
Example
For full example see class cl_demo_corr_op_map_default.
DATA: BEGIN OF struc1, DATA: BEGIN OF struc2, “Empty internal table “Filling structure |
Component |
Value |
|
ID2 |
1 |
|
a |
a |
|
b |
hallo |
src b is initial |
c |
2 |
src c is not initial |
d |
hi |
itab1[1]-d invalid. Would shortdump without DEFAULT |
z |
src e is initial |