Introduction
This Quick reference is a collection of what are subjectively the highlights of ABAP functionality made available in ABAP 7.5x releases. The already good SAP examples are simplified/summarised to allow quicker understanding of the basics of a given new functionality. Links to the full SAP examples are also provided to allow the reader to dive in deeper if desired. The version the functionality was released is also given to aid in determining if it is available in your system.
Contents
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 7.54 | Since 7.54 |
&&= | DATA text TYPE string. text = 'concatenate'. text = text && | Me!| | DATA text TYPE string. text = 'Concatenate'. text &&= | Me!|. |
1.3 ASSIGN … ELSE UNASSIGN (7.57)
Before 7.57 | Since 7.57 |
DATA(field) = 'exists'. ASSIGN ('field') TO FIELD-SYMBOL(<fs>). IF <fs> IS ASSIGNED. … ENDIF. ASSIGN ('nofield') TO <fs>. IF <fs> IS ASSIGNED AND sy-subrc = 0. "assigned on 2nd assign … ENDIF. | DATA(field) = 'exists'. ASSIGN ('field') TO FIELD-SYMBOL(<fs>). IF <fs> IS ASSIGNED. ... ENDIF. ASSIGN ('nofield') TO <fs> ELSE UNASSIGN. IF <fs> IS ASSIGNED. ... ENDIF. |
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>. | ASSIGN struc TO <struc>. |
1.5 RETURN [expr] for functional methods (7.58)
Before 7.58 | Since 7.58 |
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 |
|
7.54 | DECFLOAT16 DECFLOAT34 |
|
7.54 | DATN |
|
7.54 | TIMN |
|
7.54 | UTCLONG |
|
7.54 | GEOM_EWKB |
|
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 of 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 new (combined) sorted table while leaving the original table(s) unsorted.
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 (itab sorted by COL1, COL2 Ascending)
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 (itab sorted by COL3, COL4 Descending)
sorted_tab = VALUE #( FOR idx IN v_index ( itab[ idx ] ) ). |
COL1 | COL2 | COL3 | COL4 |
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 | ITAB2 |
COL1 | COL2 | COL1 | COL2 |
0 | 0 | X | X |
1 | 1 | X | X |
1 | 1 | Y | Y |
1 | 1 | X | Y |
0 | 0 | X | X |
1 | 0 | Y | Y |
1 | 0 | X | Y |
1 | 0 | X | Y |
0 | 0 | Y | X |
1 | 1 | 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,
"Filling structure |
struc2:
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 | 9 | src e is initial |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 |