ABAP 7.40 Quick Reference
ABAP 7.40 Quick Reference
40 Quick Reference
72304922,983
Contents
1. Inline Declarations
2. Table Expressions
3. Conversion Operator CONV
4. Value Operator VALUE
5. FOR operator
6. Reduction operator REDUCE
7. Conditional operators COND and SWITCH
8. CORRESPONDING operator
9. Strings
10. Loop at Group By
11. Classes/Methods
12. Meshes
13. Filter
14. Document Purpose
1. Inline Declarations
Before 7.40 With 7.40
Data
DATA text TYPE string. DATA(text) = 'ABC'.
text = 'ABC'.
Loop at
into DATA wa like LINE OF itab. LOOP AT itab INTO DATA(wa).
work LOOP AT itab INTO wa. ...
... ENDLOOP.
area
ENDLOOP.
Call
method DATA a1 TYPE ... oref->meth(
DATA a2 TYPE ... IMPORTING p1 = DATA(a1)
IMPORTING p2 = DATA(a2) ).
oref->meth(
IMPORTING p1 = a1
IMPORTING p2 = a2 ).
Loop at
assignin FIELD-SYMBOLS: <line> type … LOOP AT itab
g ASSIGNING FIELD-SYMBOL(<line>).
LOOP AT itab ASSIGNING ...
1
<line>. ENDLOOP.
...
ENDLOOP.
Read
assignin FIELD-SYMBOLS: <line> type … READ TABLE itab
g ASSIGNING FIELD-SYMBOL(<line>).
READ TABLE itab
ASSIGNING <line>.
Select
into tabl DATA itab TYPE TABLE OF SELECT * FROM dbtab
e dbtab. INTO TABLE @DATA(itab)
WHERE fld1 = @lv_fld1.
SELECT * FROM dbtab
INTO TABLE itab
WHERE fld1 = lv_fld1.
Select
single SELECT SINGLE f1 f2 SELECT SINGLE f1 AS my_f1,
into FROM dbtab f2 AS abc
INTO (lv_f1, lv_f2) FROM dbtab
WHERE ... INTO DATA(ls_struct)
WHERE ...
WRITE: / lv_f1, lv_f2.
WRITE: / ls_struct-my_f1,
ls_struct-abc.
2. Table Expressions
If a table line is not found, the exception CX_SY_ITAB_LINE_NOT_FOUND is raised. No sy-
subrc.
Read Table
using key READ TABLE itab INDEX wa = itab[ KEY key INDEX idx ].
idx
USING KEY key
INTO wa.
2
Read Table
with key READ TABLE itab wa = itab[ col1 = … col2 = … ].
WITH KEY col1 = …
col2 = …
INTO wa.
Read Table
with key READ TABLE itab wa = itab[ KEY key col1 = …
components WITH TABLE KEY key col2 = … ].
COMPONENTS col1 = …
col2 = …
INTO wa.
Does record
exist? READ TABLE itab ... IF line_exists( itab[ ... ] ).
TRANSPORTING NO ...
FIELDS. ENDIF.
IF sy-subrc = 0.
...
ENDIF.
Get table
index DATA idx type sy- DATA(idx) =
tabix. line_index( itab[ ... ] ).
NB: There will be a short dump if you use an inline expression that references a non-existent record.
SAP says you should therefore assign a field symbol and check sy-subrc.
3
CONV dtype|#( … )
II. Example
Method cl_abap_codepage=>convert_to expects a string
Before 7.40
helper = text.
With 7.40
OR
4
TYPES: BEGIN OF ty_columns1, “Simple structure
cols1 TYPE i,
cols2 TYPE i,
END OF ty_columns1.
OR
itab = VALUE #( ( ) ( 1 ) ( 2 ) ).
5
5. FOR operator
I. Definition
FOR wa|<fs> IN itab [INDEX INTO idx] [cond]
II. Explanation
This effectively causes a loop at itab. For each loop the row read is assigned to a work area (wa) or field-
symbol(<fs>).
This wa or <fs> is local to the expression i.e. if declared in a subrourine the variable wa or <fs> is a local
variable of
Given:
III. Example 1
Populate internal table GT_CITYS with the cities from GT_SHIPS.
Before 7.40
6
Before 7.40
With 7.40
IV. Example 2
Populate internal table GT_CITYS with the cities from GT_SHIPS where the route
is R0001.
Before 7.40
With 7.40
Note: ls_ship does not appear to have been declared but it is declared implicitly.
7
TYPES:
BEGIN OF ty_line,
col1 TYPE i,
col2 TYPE i,
col3 TYPE i,
END OF ty_line,
ty_tab TYPE STANDARD TABLE OF ty_line WITH EMPTY KEY.
Before 7.40
DO.
j = j + 10.
IF j > 40. EXIT. ENDIF.
APPEND INITIAL LINE TO gt_itab ASSIGNING <ls_tab>.
<ls_tab>-col1 = j.
<ls_tab>-col2 = j + 1.
<ls_tab>-col3 = j + 2.
ENDDO.
With 7.40
II. Note
8
While VALUE and NEW expressions can include FOR expressions, REDUCE must include at least one
FOR expression. You can use all kinds of FOR expressions in REDUCE:
with IN for iterating internal tables
with UNTIL or WHILE for conditional iterations
III. Example 1
Count lines of table that meet a condition (field F1 contains “XYZ”).
Before 7.40
With 7.40
IV. Example 2
Sum the values 1 to 10 stored in the column of a table defined as follows
Before 7.40
With 7.40
V. Example 3
Using a class reference – works because “write” method returns reference to instance object
9
With 7.40
DATA(time) =
COND string(
WHEN sy-timlo < '120000' THEN
|{ sy-timlo TIME = ISO } AM|
WHEN sy-timlo > '120000' THEN
|{ CONV t( sy-timlo - 12 * 3600 )
TIME = ISO } PM|
WHEN sy-timlo = '120000' THEN
|High Noon|
ELSE
THROW cx_cant_be( ) ).
DATA(text) =
NEW class( )->meth(
10
SWITCH #( sy-langu
WHEN 'D' THEN `DE`
WHEN 'E' THEN `EN`
ELSE THROW cx_langu_not_supported( ) ) ).
8. Corresponding Operator
I. Definition
… CORRESPONDING type( [BASE ( base )] struct|itab [mapping|except] )
With 7.40
III. Output
11
IV. Explanation
Given structures ls_line1 & ls_line2 defined and populated as above.
1
CLEAR ls_line2. ls_line2 = CORRESPONDING #( ls_line1 ).
MOVE-CORRESPONDING
ls_line1
TO
ls_line2.
2
MOVE-CORRESPONDING ls_line2 = CORRESPONDING #
ls_line1 ( BASE ( ls_line2 ) ls_line1 ).
TO
ls_line2.
3
DATA: ls_line3 like DATA(ls_line3) = CORRESPONDING line2
ls_line2. ( BASE ( ls_line2 ) ls_line1 ).
ls_line3 = ls_line2.
MOVE-CORRESPONDING
ls_line1
TO
ls_line2.
1. The contents of ls_line1 are moved to ls_line2 where there is a matching column name. Where there
is no
2. This uses the existing contents of ls_line2 as a base and overwrites the matching columns from ls_line1.
3. This creates a third and new structure (ls_line3) which is based on ls_line2 but overwritten by matching
columns of ls_line1.
12
MAPPING allows you to map fields with non-identically named components to qualify for the data transfer.
… MAPPING t1 = s1 t2 = s2
EXCEPT allows you to list fields that must be excluded from the data transfer
… EXCEPT {t1 t2 …}
9. Strings
I. String Templates
A string template is enclosed by two characters “|” and creates a character string.
Literal text consists of all characters that are not in braces {}. The braces can contain:
data objects,
calculation expressions,
constructor expressions,
table expressions,
predefined functions, or
functional methods and method chainings
Before 7.40
cl_demo_output=>display( output ).
With 7.40
II. Concatenation
Before 7.40
13
Before 7.40
With 7.40
III. Width/Alignment/Padding
IV. Case
V. ALPHA conversion
DATA(lv_vbeln) = '0000012345'.
WRITE / |{ lv_vbeln ALPHA = OUT }|. “or ALPHA = IN to go in other direction
LOOP AT itab result [cond] GROUP BY key ( key1 = dobj1 key2 = dobj2 …
[gs = GROUP SIZE] [gi = GROUP INDEX] )
14
[ASCENDING|DESCENDING [AS TEXT]]
[WITHOUT MEMBERS]
[{INTO group}|{ASSIGNING <group>}]
…
[LOOP AT GROUP group|<group>
…
ENDLOOP.]
…
ENDLOOP.
II. Explanation
The outer loop will do one iteration per key. So if 3 records match the key there will only be one iteration
for these 3 records. The structure “group” (or
“<group>” ) is unusual in that it can be looped over using the “LOOP AT GROUP” statement. This will
loop over the 3 records (members) of the group. The
structure “group” also contains the current key as well as the size of the group and index of the group ( if
GROUP SIZE and GROUP INDEX have been
assigned a field name). This is best understood by an example.
III. Example
With 7.40
15
With 7.40
ASCENDING
ASSIGNING FIELD-SYMBOL(<group>).
CLEAR: gv_tot_age.
"Average age
gv_avg_age = gv_tot_age / <group>-size.
WRITE: / |Average age: { gv_avg_age }|.
SKIP.
ENDLOOP.
IV. Output
11. Classes/Methods
I. Referencing fields within returned structures
16
Before 7.40
ls_lfa1= My_Class=>get_lfa1( ).
lv_name1 = ls_lfa1-name1.
With 7.40
Before 7.40
IF My_Class=>return_boolean( ) = abap_true.
…
ENDIF.
With 7.40
IF My_Class=>return_boolean( ).
…
ENDIF.
NB: The type “BOOLEAN” is not a true Boolean but a char1 with allowed values X,- and <blank>.
Using type “FLAG” or “WDY_BOOLEAN” works just as well.
Before 7.40
17
Before 7.40
With 7.40
12. Meshes
Allows an association to be set up between related data groups.
I. Problem
Populated as follows:
18
6 Tom 2000 Jason
II. SolutionGet the details of Jerry’s manager and all developers managed by Thomas.
With 7.40
III. Output
Jerry’s manager: Jason Salary: 3000
Thomas’ developers:
19
13. Filter
Filter the records in a table based on records in another table.
I. Definition
… FILTER type( itab [EXCEPT] [IN ftab] [USING KEY keyname]
WHERE c1 op f1 [AND c2 op f2 […]] )
II. Problem
Filter an internal table of Flight Schedules (SPFLI) to only those flights based on a filter table that contains the
fields Cityfrom and CityTo.
III. Solution
With 7.40
Note: using the keyword “EXCEPT” (see definition above) would have returned the exact opposite records i.e
all records EXCEPT for those those returned above.
20
14. Document Purpose
So you’re an experienced ABAP programmer wanting to leverage off the fantastic new functionality
available to you in ABAP 7.40!
However, searching for information on this topic leads you to fragmented pages or blogs that refer to only a
couple of the new features available to you.
What you need is a quick reference guide which gives you the essentials you need and shows you how the
code you are familiar with can be improved with ABAP 7.40.
It gives examples of “classic” ABAP and its 740 equivalent. It goes into more details on the more difficult
topics normally via examples. This allows the reader to dive in to the level they desire. While this document
does not contain everything pertaining to ABAP 740 it certainly covers the most useful parts in the experience
of the author.
The document has been compiled by drawing on existing material available online as well as trial and error by
the author. In particular the blogs by Horst Keller have been useful and are the best reference I have found
(prior to this document ). He has a landing page of sorts for his various blogs on the topic here:
Credit also goes to Naimesh Patel for his useful explanations and examples on ABAP 7.40. Here is his
example of the “FOR iteration expression” which I leaned on (links to his other 740 articles can be found at the
bottom of the link):
http://zevolving.com/2015/05/abap-740-for-iteration-expression/
I compiled the below document to make the transition to using ABAP 740 easier for myself and my project
team. It has worked well for us and I hope it will do the same for you.
FollowLikeRSS Feed
Alert Moderator
Assigned Tags
740
ABAP Development
SAP NetWeaver
abap
document
overveiw
reference
View more...
21
Similar Blog Posts
ABAP News for Release 7.40 - What is ABAP 7.40?
By Horst KellerMay 22, 2013
ABAP News for Release 7.50 - What is ABAP 7.50?
By Horst KellerOct 20, 2015
Old and new ABAP syntax - overview sheet
By Thomas KrüglMar 02, 2016
Related Questions
SE21 - what happend to PACKTYPE ?
By Joachim ReesJan 11, 2017
ABAP code for multiple releases
By Phil SoadyApr 13, 2016
SapGui problem
By Morales Lozano Joel AngelJul 23, 2013
72 Comments
You must be Logged on to comment or reply to a post.
Jitendra Soni
October 25, 2015 at 1:42 pm
Hi Jeffrey,
ABAP version:
Jeffrey Towell
22
Blog Post Author
October 26, 2015 at 8:42 am
Thanks Jitendra.
I am not sure which bits of ABAP 7.40 come in with exactly which version but
here is some working code. If this does not work on your box then its fair to say
you do not have the relevant version yet.
Hi Jitendra/Jeffrey,
the new open sql syntax was created in ABAP 7.40 SP05 and enhanced in SP08.
More information in ABAP News for 7.40, SP08 - Open SQL.
BR,
Christiano.
Like 0
Share
Paul Bakker
23
October 25, 2015 at 9:52 pm
Unfortunately some of the code (inside the black borders) is truncated on the
cheers
Paul
Like 0
Share
Jeffrey Towell
Blog Post Author
October 26, 2015 at 12:10 am
Was also concerned about truncation on the right but found that if you click on
the text and drag to the right that it all becomes visible. Alternatively the scroll
bar at the bottom works but it's a bit inconvenient scrolling down to find it.
Cheers,
Jeff
Like 0
Share
Former Member
October 26, 2015 at 5:03 am
Very much useful document Paul!
Like 0
24
Share
Manu Kapur
October 26, 2015 at 11:22 am
Raphael Pacheco
October 26, 2015 at 11:45 am
Just a suggestion ... I believe that would be less harmful to the blocks with commands have
Jeffrey Towell
Blog Post Author
October 26, 2015 at 12:05 pm
Good point Raphael! If I can find a relatively easy way to do that I think I will.
Like 0
Share
Former Member
October 27, 2015 at 1:18 pm
Brilliant, looking forward for future blogs..
Like 0
Share
25
Former Member
October 28, 2015 at 12:20 pm
very helpful, can't wait to use some of the inline expressions
Like 0
Share
Guy Lamoureux
October 28, 2015 at 1:34 pm
Very Interesting. But I see that clarity and "ease of reading"continues to be
Jeffrey Towell
Blog Post Author
October 29, 2015 at 2:30 am
Guy, I thought the exact same thing at first along with others I have chatted to.
However, after using it a while I realise it becomes more clear as you get more
familiar with the syntax. After years of using the old syntax it has become so
familiar to us that it feels like we have to think too much to understand what is
being coded in the new syntax. Soon it will be second nature to you and hence
easy to read.
Like 1
Share
Guy Lamoureux
October 29, 2015 at 11:37 am
Hi Jeffrey,
"after using it a while" the problem is right here. Not everybody is an ABAP
programmer and not everybody programs in ABAP on a regular base. I've seen a
lot of functional analyst who can follow what's going on in an ABAP program.
They do it for many reasons but it's part of their job and the more we change the
language to something more obscure, the less they will be able to do it. They will
need help from ABAP programmers. This will slow down the process.
26
On my part, I've worked as an ABAP programmer for 10 years, followed by 10
years of BW developement. I don't write ABAP code on a regular base. This new
syntax will keep being obscure.
Like 1
Share
Christoph Schreiner
October 29, 2015 at 7:59 am
Former Member
November 8, 2015 at 10:56 am
Great job! Thank you for making our life easy...
Like 0
Share
Aslam MD
27