ABAP 7.40 Quick Reference
ABAP 7.40 Quick Reference
Community
Je rey Towell
October 25, 2015 23 minute read
So you’re an experienced ABAP programmer wanting to leverage o 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 di cult
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.
Regards,
Follow RSS feed Like
Je Towell
Created: 2015
Contents
1. Inline Declarations
2. Table Expressions
5. FOR operator
8. CORRESPONDING operator
9.Strings
1. Inline Declarations
2. Table Expressions
If a table line is not found, the exception CX_SY_ITAB_LINE_NOT_FOUND is raised. No sy-subrc.
INTO wa.
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 eld symbol and check sy-subrc.
# = compiler must use the context to decide the type to convert to (implicit)
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
OR
itab = VALUE #( ( ) ( 1 ) ( 2 ) ).
5. FOR operator
I. De nition
FOR wa|<fs> IN itab [INDEX INTO idx] [cond]
II. Explanation
This e ectively causes a loop at itab. For each loop the row read is assigned to a work area (wa) or eld-
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
that subroutine. Index like SY-TABIX in loop.
Follow RSS feed Like
Given:
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 Follow RSS feed Like
With 7.40
Note: ls_ship does not appear to have been declared but it is declared implicitly.
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
Before 7.40 Follow RSS feed Like
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
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:
III. Example 1
Count lines of table that meet a condition ( eld F1 contains “XYZ”).
Before 7.40 Follow RSS feed Like
With 7.40
IV. Example 2
Sum the values 1 to 10 stored in the column of a table de ned as follows
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( ).
7. Conditional operators COND and SWITCH
Follow RSS feed Like
I. De nition
… COND dtype|#( WHEN log_exp1 THEN result1
[ WHEN log_exp2 THEN result2 ]
…
[ ELSE resultn ] ) …
8. Corresponding Operator
I. De nition
… CORRESPONDING type( [BASE ( base )] struct|itab [mapping|except] )
II. Example Code
With 7.40
With 7.40
Follow RSS feed Like
, ls_line2–col2, ls_line2–col3.
SKIP.
, ls_line3–col2, ls_line3–col3.
III. Output
IV. Explanation
Given structures ls_line1 & ls_line2 de ned and populated as above.
MOVE-CORRESPONDING ls_line1
TO ls_line2.
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.
… MAPPING t1 = s1 t2 = s2
EXCEPT allows you to list elds 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,
Follow RSS feed Like
table expressions,
predefined functions, or
Before 7.40
cl_demo_output=>display( output ).
With 7.40
II. Concatenation
Before 7.40
With 7.40
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) }|.
Follow RSS feed Like
V. ALPHA conversion
DATA(lv_vbeln) = ‘0000012345’.
WRITE / |{ lv_vbeln ALPHA = OUT }|. “or use ALPHA = IN to go in other direction
I. Definition
LOOP AT itab result [cond] GROUP BY key ( key1 = dobj1 key2 = dobj2 …
[gs = GROUP SIZE] [gi = GROUP INDEX] )
[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
age TYPE i,
END OF ty_employee,
ASCENDING
ASSIGNING FIELD-SYMBOL(<group>).
CLEAR: gv_tot_age.
ENDLOOP.
“Average age
SKIP.
ENDLOOP.
IV. Output
11. Classes/Methods
I. Referencing elds within returned structures
Before 7.40
ls_lfa1 = My_Class=>get_lfa1( ).
lv_name1 = ls_lfa1–name1.
With 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
12. Meshes
Allows an association to be set up between related data groups.
I. Problem
Given the following 2 internal tables:
Populated as follows:
Get the details of Jerry’s manager and all developers managed by Thomas.
II. Solution
With 7.40
With 7.40 Follow RSS feed Like
III. Output
Jerry’s manager: Jason Salary: 3000
13. Filter
Filter the records in a table based on records in another table.
I. De nition
… FILTER type( itab [EXCEPT] [IN ftab] [USING KEY keyname]
Follow RSS feed Like
WHERE c1 op f1 [AND c2 op f2 […]] )
II. Problem
Filter an internal table of Flight Schedules (SPFLI) to only those ights based on a lter table that contains
the elds Cityfrom and CityTo.
III. Solution
With 7.40
Note: using the keyword “EXCEPT” (see de nition above) would have returned the exact opposite records i.e
all records EXCEPT for those those returned above.
Follow RSS feed Like
Alert Moderator
Assigned tags
View more...
Related Questions
59 Comments
Jitendra Soni
Hi Je rey,
“SELECT * FROM dbtab INTO TABLE @DATA(lt_dbtab) WHERE eld1 = @lv_ eld1.”
ABAP version:
SAP_BASIS 740 0007 SAPKB74007 0000 – SAP Basis Component
Follow RSS feed Like
SAP_ABA 740 0007 SAPKA74007 0000 – Cross-Application Component
Like(0)
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.
Like(0)
Hi Jitendra/Je rey,
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)
Paul Bakker
cheers
Paul
Like(0)
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 nd it.
Cheers,
Je
Like(0)
Former Member
Like(0)
Manu Kapur
Like(0)
Raphael Pacheco
Follow RSS feed Like
October 26, 2015 at 11:45 am
Just a suggestion … I believe that would be less harmful to the blocks with commands have the edges a little thinner.
Like(0)
Good point Raphael! If I can nd a relatively easy way to do that I think I will.
Like(0)
Former Member
Like(0)
Former Member
Like(0)
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 😉
Like(1)
Like(0)
Guy Lamoureux
Hi Je rey,
“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.
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(0)
Christoph Schreiner
Like(0)
Former Member
Like(0)
Aslam MD
Hi Je rey,
Very informative matierial.
Follow RSS feed Like
Like(0)
Former Member
Just sent this link to the whole team :-).
Like(0)
Former Member
Is there also some way, to have this as a sorted / hashed table or at least add secondary keys?
Like(1)
Former Member
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:
TYPES ty_mytab TYPE SORTED TABLE OF t001w WITH NON-UNIQUE KEY fabkl.
However, this does not save you any time/typing compared to selecting directly into your de ned internal
table:
Follow RSS feed Like
TYPES ty_mytab TYPE SORTED TABLE OF t001w WITH NON-UNIQUE KEY fabkl.
SELECT * FROM t001w INTO TABLE lt_new_tab.
Like(0)
Wilbert Sison
Like(0)
Former Member
Cheers Wilbo!
Like(0)
Michael Calekta
Nevertheless this is the rst example I found, where the advantage of meshes can be seen.
All the best
Michael
Like(0) Follow RSS feed Like
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 o my eld symbols in this document before. My theory is that when it
gets converted to HTML that the eld 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.
Like(0)
Michael Calekta
Sorry to interrupt again, but it was not only the <> missing, which you have corrected, but also the ls_
which is still missing. I don’t think this can get lost by an html-conversion-error. Perhaps a missing de nition
and value assignment from the original coding.
I have copied the example and tried it, and it really works ne, once I could eliminate the syntax-errors
because of the missing letters.
Like(0)
Interruption appreciated as you are correct that I forgot to add the “ls_” in. However, I can assure you that
the original code has both the “<>” and the “ls_” in. The HTML issue has caused problems in other parts of
this document which is why I know about it. In the “Loop at Group By” section it would not let me save the
code I added. I nally added the code into the document word by word (i.e. saving after each word) and
discovered it was a eld symbol causing the problem. When I renamed the eld symbol it saved.
Like(0)
Former Member
Regards,
Vinay Mutt
Like(0)
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
Like(0)
Former Member
Hi, experts. How can i ll itab with corresponding elds from structure variable and one eld from another
table using one statement ? my example:
data(RT_CONFIG_PERS_DATA) =
ENDLOOP.
Like(0)
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_con g_pers_data) =
( pers_for_user = wa_touser–low
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.
Like(0)
PRUTHVIRAJ DAYAM
Cant we use Filter with Non-Key elds! .. any manipulation possible with declaration?!
Like(0)
Rohit Gupta
Are constructor operators are better in performance ? or It is just a di erent way of writing the code.
Like(0)
Ramesh Kothapally
Ramesh Kothapally
Like(0)
Sawyer Peng
Like(0)
Sawyer Peng
it should be:
Like(0)
Former Member
November 30, 2017 at 1:12 pm
Follow RSS feed Like
This can be written also as :
Like(0)
sridhar reddy
BTW, how do we READ table using binary search with the new syntax?
Like(0)
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 di erent 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 speci c customer (if no key is speci ed, the default key is used, in this case the hashed key)
Like(2)
Follow RSS feed Like
Former Member
Like(0)
Ruthiel Trevisan
Like(1)
Antonis Ioannidis
First of all, Great Job Je rey 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 that it will just make the code a lot more
complex for other programmers, not familiar with the new methods, to read.
Like(0)
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
Like(1)
Follow RSS feed Like
Hi Antonis,
I haven’t tested the performance of old vs new syntax however I would be surprised if SAP have made the
new syntax work slower. Presumably where one line of code in the new syntax does the work of multiple
lines in the old then the new syntax will be quicker as it will be optimized for the speci c function it is
carrying out.
In terms of readability it actually becomes easier to read once you are familiar with the syntax. Taking your
CONV example, previously you might have passed a value from one variable (say Type I) to another (say
Char3) to convert it. While reading this you would not know for sure a conversion is taking place. A value
might just be shared between two variables of the same type. With CONV it is obvious what the intent is.
Old: var2 = var1. (Is this a conversion or just a shared value between vars of the same type ?)
Like(0)
Himansu Gyala
Much Informative
Like(0)
Ebrahim Hatem
it is really interesting and anybody can nd all information which ich related to ABAP 740. But I have an
comment to the II. Methods that return a type BOOLEAN.
ENDIF.
Follow RSS feed Like
IF NOT My_Class=>return_boolean( ). ” false empty
ENDIF.
Regards
Ebrahim
Like(0)
Bärbel Winkler
Rather belated thanks from me as well, Je rey Towell for this detailed and very helpful list (h/t Jonathan
Capps whose recent post linked to yours)!
This list will help me to wrap my head around the (no longer really) new options to write ABAP-statements. I
however also share some misgivings others have mentioned earlier, namely that this shortened and
arguably streamlined way to write ABAP-code is no longer quite as easy to read and parse – esp. for people
new to programming or to folks mostly working on the functional and customizing part of SAP within IT.
With the old “long-form” ABAP with spelled out statements, it was usually possible for a technically-minded
colleague to at least understand the gist of what is going on in a program, while either looking at the code in
SE38/SE80 or during debugging. Considering that I’m having a hard time quickly remembering and
understanding what I’m looking at with many of the “new” constructs I can imagine how even more
confusing this might look for non-developers.
So, I’m wondering if there’s perhaps some additional information needed to highlight the advantage(s) of
the new constructs apart from potentially having to type a few characters less? One such advantage might
be performance or another hightened security. For me, brevity is not always a bonus and longer but more
self-explanatory statements can make life easier once the time comes that changes need to be applied.
Cheers
Baerbel
Like(0)
Your point about non-developers is well taken. Where non-developers have spent years slowly learning what
is now legacy syntax they will now be impeded when trying to read/debug code in new syntax.
If I wrote: “Thx 4 ur comment” it would save me 8 characters. If I was writing this statement frequently it
would start saving me time and I’d be able to read it as quickly as the full version.
I cannot speak to performance in terms of running the code. But in terms of debugging it is quicker as we
now have one line of code doing what multiple lines of code used to do. For example a 15 line case
statement becomes a 1 line COND statement that can be stepped over with one F6 in debug mode. I also
think the COND is as easy to read.
Je
Like(0)
Jayaprakash H J
Hi,
Under many headings i could only nd Before 7.40 . There is nothing in With 7.40 .
Please help.
Regards,
Jp
Like(0)
Srikanth Thogiti
It is really a useful info and It changes our job easy, especially with FILTER, GROUP, VALUE, FOR etc.
Follow RSS feed Like
Like(0)
Vimal Sharma
SELECT kappl,
objky,
kschl,
spras,
FROM nast
INTO TABLE @DATA(gt_nast) .
IF sy-subrc is initial.
ENDIF.
“Declaration of perform
If declare a type and then tries to pass it here , it says type mismatch . So what to do while declaring a
perform for internal table fetched with literals.
Like(0)
Sandra Rossi
Eclipse ADT “quick xes” to declare the variable explicitly (DATA BEGIN OF …), change DATA into TYPES,
and use that type name…
Like(2)
Renuka Behara
Like(0)
Follow RSS feed Like
Vishal Kumar
Hello
Can someone help me with the syntax error in the attached code ?
TYPES:
BEGIN OF ty_for_final,
vbeln TYPE vbeln_va,
vbtyp TYPE vbak-vbtyp,
posnr TYPE vbap-posnr,
END OF ty_for_final.
Thanks
Like(0)
Sandra Rossi
Like(0)
Vishal Kumar
TYPES:
BEGIN OF ty_ord,
vbeln TYPE vbeln_va,
posnr TYPE posnr_va,
vbtyp TYPE vbak-vbtyp,
END OF ty_ord.
DATA:
lv_new_table TYPE REF TO DATA.
Follow RSS feed Like
lv_new_table = NEW ty_ord( ( vbeln = '000000001' posnr = '0000001' vbtyp = 'L' ) ( vbeln = '0
Like(0)
Rajesh Nair
Hi Vishal,
This would work. If you want multiple entries, then you could declare a table type as follows and then your
code would work.
TYPES ty_t_ord TYPE STANDARD TABLE OF ty_ord WITH EMPTY KEY.
Regards,
Rajesh P Nair
Like(0)
Sandra Rossi
the rst one will not work because you still de ne two opening parentheses ( (
Like(0)
Rajesh Nair
May 11, 2020 at 11:20 pm
Hi Sandra, Follow RSS feed Like
You are correct. That was a typo, I have copied from Vishal’s message and removed the closing parenthesis,
but not the opening one. I was suggesting Vishal that multiple entries will not work for the type ty_ord since
it represents a at structure and we can use multiple entries only if we use a table type of ty_ord.
Regards,
Rajesh P Nair
Like(0)
RAMNIK DHAR
Hi Guys,
Suppose I have a table with only one column and my requirement is to get all the contents of the table in a
string separated by (,) and ending with (.) e.g. Value1, Value2, Value3.
Any pointers on how to do this with the new syntax without concatenating.
Like(0)
Find us on
Newsletter Support