ABAP 7.40 Quick
ABAP 7.40 Quick
ABAP 7.40 Quick
Products
Products Industries
Industries Support
Support Training
Training Community
Community Developer
Developer Partner
Partner
About
About
Home / Community / Blogs + Actions
Jeffrey Towell
more by this author
ABAP Development
SAP NetWeaver | 740 | abap | document | overveiw | reference | sap netweaver
Follow RSS
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 1/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
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.
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.
Regards,
Jeff Towell
Created: 2015
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 2/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Contents
1. Inline Declarations
2. Table Expressions
I. Definition
II. Example
I. Definition
5. FOR operator
I. Definition
II. Explanation
III. Example 1
IV. Example 2
I. Definition
II. Note
III. Example 1
IV. Example 2
V. Example 3
I. Definition
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 3/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
8. CORRESPONDING operator
I. Definition
III. Output
IV. Explanation
9.Strings
I. String Templates
II. Concatenation
III. Width/Alignment/Padding.
IV. Case
V. ALPHA conversion
1. Inline Declarations
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 4/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
2. Table Expressions
If a table line is not found, the exception CX_SY_ITAB_LINE_NOT_FOUND is
raised. No sy-subrc.
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 5/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Read Table READ TABLE itab INDEX idx wa = itab[ KEY key IN
using key
USING KEY key
IF sy-subrc = 0. ENDIF.
…
ENDIF.
TRANSPORTING NO FIELDS.
idx = sy-tabix.
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.
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 6/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
…
ENDIF.
I. Definition
CONV dtype|#( … )
II. Example
Method cl_abap_codepage=>convert_to expects a string
Before 7.40
helper = text.
xstr = cl_abap_codepage=>convert_to( source = helper ).
With 7.40
I. Definition
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 7/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
coln1 TYPE i,
coln2 TYPE ty_columns1,
END OF ty_columns2.
OR
itab = VALUE #( ( ) ( 1 ) ( 2 ) ).
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 8/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
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>).
Given:
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 9/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
III. Example 1
Populate internal table GT_CITYS with the cities from
GT_SHIPS.
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.
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 10/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
TYPES:
BEGIN OF ty_line,
col1 TYPE i,
col2 TYPE i,
col3 TYPE i,
END OF ty_line,
Before 7.40
j = 1.
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
I. Definition
… REDUCE type(
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 11/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
II. Note
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
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 12/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Before 7.40
With 7.40
V. Example 3
Using a class reference – works because “write” method returns reference to
instance object
With 7.40
output->display( ).
I. Definition
… COND dtype|#( WHEN log_exp1 THEN result1
[ ELSE resultn ] ) …
[ ELSE resultn ] ) …
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 13/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
COND string(
|High Noon|
ELSE
THROW cx_cant_be( ) ).
SWITCH #( sy-langu
) ).
8. Corresponding Operator
I. Definition
[mapping|except] )
With 7.40
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 14/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
With 7.40
, ls_line2–col2, ls_line2–col3.
SKIP.
, ls_line3–col2, ls_line3–col3.
III. Output
IV. Explanation
Given structures ls_line1 & ls_line2 defined and populated as above.
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 15/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
MOVE-CORRESPONDING ls_line1
TO ls_line2.
TO ls_line2.
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.
… MAPPING t1 = s1 t2 = s2
EXCEPT allows you to list fields that must be excluded from the data
transfer
… EXCEPT {t1 t2 …}
9. Strings
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 16/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
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
Before 7.40
cl_demo_output=>display( output ).
With 7.40
II. Concatenation
Before 7.40
With 7.40
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 17/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
III. Width/Alignment/Padding
WRITE / |{ ‘Left’ WIDTH = 20 ALIGN = LEFT PAD = ‘0’
}|.
WRITE / |{ ‘Centre’ WIDTH = 20 ALIGN = CENTER PAD = ‘0’
}|.
WRITE / |{ ‘Right’ WIDTH = 20 ALIGN = RIGHT PAD = ‘0’
}|.
IV. Case
WRITE / |{ ‘Text’ CASE = (cl_abap_format=>c_raw) }|.
WRITE / |{ ‘Text’ CASE = (cl_abap_format=>c_upper) }|.
WRITE / |{ ‘Text’ CASE = (cl_abap_format=>c_lower) }|.
V. ALPHA conversion
DATA(lv_vbeln) = ‘0000012345’.
WRITE / |{ lv_vbeln ALPHA = OUT }|. “or use ALPHA = IN
to go in other direction
I. De nition
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
age TYPE i,
END OF ty_employee,
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 19/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
With 7.40
ASCENDING
ASSIGNING FIELD-SYMBOL(<group>).
CLEAR: gv_tot_age.
ENDLOOP.
“Average age
SKIP.
ENDLOOP.
IV. Output
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 20/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
11. Classes/Methods
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
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 21/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Before 7.40
12. Meshes
Allows an association to be set up between related data groups.
I. Problem
Given the following 2 internal tables:
END OF t_manager,
END OF t_developer,
Populated as follows:
1 Jason 3000
2 Thomas 3200
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 22/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Get the details of Jerry’s manager and all developers managed by Thomas.
II. Solution
With 7.40
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 23/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
III. Output
Jerry’s manager: Jason Salary: 3000
Thomas’ developers:
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
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 24/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
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.
Alert Moderator
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 25/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
44 Comments
You must be Logged on to comment or reply to a post.
Jitendra Soni
Hi Jeffrey,
ABAP version:
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.
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 26/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
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.
Paul Bakker
Unfortunately some of the code (inside the black borders) is truncated on the right hand
side. But I think we can work it out
cheers
Paul
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 27/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
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
Jagadesh Divakaran
Manu Kapur
Raphael Pacheco
Just a suggestion … I believe that would be less harmful to the blocks with commands have the edges
a little thinner.
Good point Raphael! If I can find a relatively easy way to do that I think I
will.
Markus V
Guy Lamoureux
Very Interesting. But I see that clarity and “ease of reading”continues to be vastly
underestimated and undervalued. ABAP is going to the dark side
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.
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 29/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Guy Lamoureux
Hi Jeffrey,
Christoph Schreiner
George Mathew
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 30/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Aslam MD
Hi Jeffrey,
Alexander Beckmann
Jakob Mainka
Is there also some way, to have this as a sorted / hashed table or at least add secondary
keys?
Jeffrey Towell
Not that I’m aware of Jakob. If you create a “type” of the kind you want with
sorting etc. and call it say ty_mytab you could do a conversion using CONV:
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 31/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
However, this does not save you any time/typing compared to selecting
directly into your defined internal table:
Wilbert Sison
Jeffrey Towell
Cheers Wilbo!
Michael Calekta
Nevertheless this is the first example I found, where the advantage of meshes can be
seen.
All the best
Michael
The amazing thing is that the code is a copy and paste from a working
program I wrote and still have. I’ve noticed the “<” and “>” get stripped off
my field symbols in this document before. My theory is that when it gets
converted to HTML that the field symbols sometimes look like HTML tags
because they are between the <>. As such they are sometimes stripped out
by this conversion to HTML.
Thanks again.
Michael Calekta
Sorry to interrupt again, but it was not only the <> missing,
which you have corrected, but also the ls_ which is still
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 33/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
I have copied the example and tried it, and it really works fine,
once I could eliminate the syntax-errors because of the
missing letters.
Vinay Mutt
Thanks for documenting all the new changes. This comes as a helpful doc for all who
wants to know the new features of ABAP Programming. The Inline Declaration is a very
helpful feature of ABAP 740 and it solves huge effots of developer.
Regards,
Vinay Mutt
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 34/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Martin Neuß
… wonderful !
I am just trying to gather some Information about Netweaver 7.40 ABAP for a
forthcoming inhouse training here in our company, and found out soon that the original
SAP samples are hardly helpful.
Your examples are really straightforward, easy to understand and useful for “real life”
developers.
Thank you !
Regards,
Martin Neuss
Konstantin Mesnyankin
Hi, experts. How can i fill itab with corresponding fields from structure variable and one
field from another table using one statement ? my example:
data(RT_CONFIG_PERS_DATA) =
<fs>–pers_for_user = wa_touser–low.
ENDLOOP.
Hi Konstantin,
Its possible to get it on one line by using each component of the structure
instead of the “CORRESPONDING”. In your case this would look like:
DATA(rt_config_pers_data) =
( pers_for_user = wa_touser–low
component = rs_config_pers_data–component
viewname = rs_config_pers_data–viewname
role_key = rs_config_pers_data–role_key
component_usage = rs_config_pers_data–component_usage
object_type = rs_config_pers_data–object_type
object_sub_type = rs_config_pers_data–object_sub_type
changed_by = rs_config_pers_data–changed_by
changed_at = rs_config_pers_data–changed_at
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 36/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
config = rs_config_pers_data–config
parameters = rs_config_pers_data–parameters
config_type = rs_config_pers_data–config_type
invalid_flag = rs_config_pers_data–invalid_flag
marking_flag = rs_config_pers_data–marking_flag
check_flag = rs_config_pers_data–check_flag ) ).
Of course your “classic code” is better not just because the above is longer
but also because the above will not work if there is ever a change to the
structure bsp_dlct_pers.
PRUTHVIRAJ DAYAM
Cant we use Filter with Non-Key fields! .. any manipulation possible with declaration?!
Rohit Gupta
Ramesh Kothapally
Hi Jeffrey,
Thanks for sharing very informative document with us.This blog help for all who wants to
know new features and techniques in ABAP 7.4 programming and helpful to getting
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 37/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Ramesh Kothapally
Sawyer Peng
Sawyer Peng
it should be:
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 38/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Anurag Kashyap
sridhar reddy
BTW, how do we READ table using binary search with the new syntax?
Freek Cavens
In the new syntax you would probably use a sorted or hashed table. A
problem that I have encountered numerous times with the binary search is
that the table is not sorted correctly (often because the sort order is
changed in a later adjustment of the code and the binary search is
overlooked), leading to an incorrect result. Using sorted table makes sure
that the sorting of the table is correct. If you need to read the table using
different access paths, you can just declare multiple keys.
data : lt_kunnr TYPE HASHED TABLE OF kna1 WITH UNQUE KEY kunnr
with non-unique sorted key k_city components ORT01,
**Get a specific customer (if no key is specified, the default key is used, in
this case the hashed key)
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 39/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
Ruthiel Trevisan
Antonis Ioannidis
First of all, Great Job Jeffrey Towell! This is an excellent post providing very useful
information. Thank you!
But I cannot stop to wonder, are those new ways of writting any better than the older
ones performance-wise?
In my point of view, if there is no actual performance gain by using the new methods,
apart from some new additions like CONV which are indeed very useful, it seems to me
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 40/42
5/22/2018 ABAP 7.40 Quick Reference | SAP Blogs
that it will just make the code a lot more complex for other programmers, not familiar with
the new methods, to read.
Michael Rudolph
Hi Antonis,
maybe not better than older ones performance-wise. But the way you can
code know safes a lot of performance while your typing! Don’t forgot that
every letter you have not to type are saving time. Isn’t it? Sure at the
beginning it is sometimes hard to read but:it becomes clear after a while.
Now ABAP is a little bit closer to other programming languages.
regards
Micha
Hi Antonis,
Old: var2 = var1. (Is this a conversion or just a shared value between
vars of the same type ?)
Himansu Gyala
Much Informative
https://blogs.sap.com/2015/10/25/abap-740-quick-reference/ 42/42