Académique Documents
Professionnel Documents
Culture Documents
40,
SP08 - More for Internal Tables
Posted by Horst Keller 6 Oct, 2014
Besides the already mentioned REDUCE operator, the conditional FOR and LINES OF inside VALUE & Co.
and the grouping of internal tables, there are some other ABAP enhancements for internal tables in 7.40,
SP08:
FILTER expressions
The new FILTER operator enables two kinds of filtering an internal table.
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
...
DATA(result) = VALUE #( itab[ id = ... ] DEFAULT def ).
9872 Views
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
Sorry, I was thinking of an OPTIONAL shorter variant for a common/default case of this expression. I forgot to
write this.
By the way: I am quite new to posting in SCN. Is there something like a private message, to avoid long public
discussions?
Horst Keller in response to Edo von Glan on page 3
15 Jan, 2016 9:30 AM
Yes, but the expression is not restricted to those ...
Edo von Glan in response to Horst Keller on page 3
15 Jan, 2016 9:26 AM
I was thinking of tables which have exactly the same type. That is a programming task that occurs quite
frequently for me: Here is a list of objects (not in an OO sense) from source A (or time t1), here is another one
from source B (or time t2). Now we need to know which objects are only in the A list, or which ones are in both
lists, ...
Shai Sinai in response to Edo von Glan on page 3
14 Jan, 2016 2:57 PM
Well, this might be another topic (which Horst has already responded to), but, for the matter of fact, I was
talking about the primary/secondary key definition and not about omitting the WHERE criteria.
Horst Keller in response to Edo von Glan on page 3
14 Jan, 2016 12:50 PM
Even then, how to decide which key field to compare with which?
By data type, by name, by position ...?
Edo von Glan in response to Horst Keller on page 3
14 Jan, 2016 12:45 PM
ok, but I think the case "complete key fields" is the 90% case. So it would be nice to have this as the default,
and an optional WHERE part for the two cases that you mention.
Horst Keller in response to Edo von Glan on page 3
14 Jan, 2016 12:09 PM
Why not
omitting the WHERE statement for the key fields
Because you can compare arbitrary columns from spfli_tab as LHS with key fields from filter_tab as
RHS.
Because for sorted keys it is possible to cover only a part of the key.
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
ENDCLASS.
CLASS test_expression IMPLEMENTATION.
METHOD test.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
TYPES: BEGIN OF ty_data,
i TYPE i,
s TYPE string,
END OF ty_data,
tty_data TYPE HASHED TABLE OF ty_data
WITH UNIQUE KEY i.
DATA(items) = VALUE tty_data( ( i = 1 s = 'Test' )
( i = 2 s = 'Hello World' )
( i = 3 s = 'xyz') ).
DATA(filtered_data) = FILTER #( items EXCEPT WHERE i = 1 ).
IF lines( filtered_data ) > 0.
ENDIF.
DATA(sum) = REDUCE i( INIT result = 0
FOR item IN filtered_data
NEXT result = result && item-i ).
NEW test_expression( )->test( filtered_data ).
If i inline the filter expression replacing the filtered_data variable like this, i get 2 syntax errors.
" Syntax error here: Unexpected operator "FILTER"
IF lines( FILTER #( items EXCEPT WHERE i = 1 ) ) > 0."
ENDIF.
" Syntax error here: "FILTER ANY( )" is not an internal table
DATA(sum) = REDUCE i( INIT result = 0
FOR item IN FILTER #( items EXCEPT
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
WHERE i = 1 )
NEXT result = result && item-i ).
" No syntax error here
NEW test_expression( )->test( FILTER #( items EXCEPT
WHERE i = 1 ) ).
It seems that the compiler can't recognize the result type of a filter expression as table. And so i can't use filter
expressions where (any) table is expexted, right?
So that would explain the first two errors. But i wonder why is then the method call possible? It seems in this
case the compiler is able to recognize the result of the filter expression as a table.
Interestingly enough, if i replace the # with tty_data it works for the reduce expression, but not for the lines
operator
" Still a syntax error here: Unexpected operator "FILTER"
IF lines( FILTER tty_data( items EXCEPT WHERE i = 1 ) ) > 0."
ENDIF.
" No syntax error anymore !
DATA(sum) = REDUCE i( INIT result = 0
FOR item IN FILTER tty_data(
items EXCEPT WHERE i = 1 )
NEXT result = result && item-i ).
I can't find anything about that in the documentation. Maybe i'm missing the obvious. Can you explain that?
Regards Christian
Brian O'Neill in response to Jrgen Lukasczyk on page 7
20 Mar, 2015 4:04 PM
Seriously, your posts are not trending enough
Jurgen,
You need to get a Horst Keller tracker! Click his name to view his profile and click receive email notifications.
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
You get an email every time Horst posts to SCN. That is an email for every post and comment, so it can be a
lot emails, but it is totally worth it and makes it easy to stay on top of the latest news when you are not able to
regularly login in to SCN.
Horst Keller in response to Jrgen Lukasczyk on page 7
20 Mar, 2015 8:03 AM
your posts are not trending enough
Hello, it's ABAP ...
Yes, some jerks gave this one only 4 stars. I'd expect more trending somewhere in 2025 when most ABAPers
finally get access to 7.4.
Jrgen Lukasczyk
19 Mar, 2015 8:07 PM
Do any of your blog posts receive less than a 5-star rating?
Seriously, your posts are not trending enough, because I recall having had that exact requirements (filtering
a table by a converted value and using itab[ ... ] expression w/o the error being thrown) couple of weeks ago,
thinking "Darn, I cannot use expressions here!" and coded the old way.
Today I see this blog, going "Darn, couldn't he have posted that earlier?!".
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
Pablo Pessoa
18 Mar, 2015 7:48 PM
Hi
it is possible to do something like:
DATA(itab2) = itab1[ WHERE col = "XXX"]
i mean, a way to move a part of itab1 to itab2 and get a table as a result and not only an structure.
thanks and regards.
Thomas Wertsch in response to Horst Keller on page 8
11 Feb, 2015 5:13 PM
Well partly correct always implies an error happened - since the assumptions made during coding were not met
-> exit
It is just that that the coding will get bloated again after. Youll get the point, but since you said an expression
must be side-effect free - ill guess ill have to stick / adapt to this behaviour.
(but basically expressions are nothing more than a nicely wrapped set of reads, loops, deletes reads, etc etc
which itself do set a subrc). Thxs for the quick reply.
or deeply nested expressions using sy-subrc? From sy-subrc <> 0 you would only derive that the result is partly
correct, and then?
An expression works or it doesn't An expression must be side-effect free and must not influence system fields.
Functional methods should be programmed side-effect free too (unfortunately, for historical reasons sy-subrc
is set to 0 when calling them, but never to another value).
Thomas Wertsch
11 Feb, 2015 2:44 PM
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
Hi Horst,
to be honest i am really missing the subrc (for ALL the newly added expressions).
Any chance to add them in one of the next sp?
I believe this really is an gap - on the one hand we try to keep the code small and clean and on the other hand
well need to to code around missing subrc and even have to handle exceptions.
Cheers, Thomas
Suhas Saha in response to J#nis B on page 9
8 Oct, 2014 8:57 AM
But then I probably still know too little about "application basis" and "application".
My "simple logic" was telling me that one should somehow be able to upgrade "basis" and "application basis"
without disrupting too much or rendering "application" inoperable, and that it should have been less of an effort
than doing full fledged ERP EHP...
"application".
But then I probably still know too little about "application basis" and
cheers
Janis
Horst Keller in response to Jelena Perfiljeva on page 10
7 Oct, 2014 6:30 PM
No really, I am writing the ABAP language documentation (day in, day out) and I can only blog about things
I happen to know. I also tried to explain what is ABAP 7.40, but I can't tell you how to get your hands on it.
What I intend to do is to give you a simple sneak preview of new features in ABAP to come. It is far, far out of
my reach to influence someone to make it more easily available. But it is absolutely perfect that you liked the
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
blog of Julie Plummer. She works in Karl Kessler's team and its really those guys who can tell you more about
release policy.
Jelena Perfiljeva in response to Horst Keller on page 10
7 Oct, 2014 5:20 PM
Horst, I believe you are way too modest about your importance.
The thing is - there needs to be information available in simple lanuage that ABAPers and even some
functional folks could easily understand and digest. All the information I've seen so far appears to be written by
Basis for Basis, so to say. Most ABAPers don't need a 6 page document about the release strategy (it's TMTR,
quite frankly) but some simple chart with dependencies. What Julie Plummer did in her blog about NWBC is an
excellent example of how such information could be presented.
Peter Inotai in response to Jelena Perfiljeva on page 14
7 Oct, 2014 1:25 PM
As far as I know there was also a HANA compatible version of ERP Ehp6 with 7.40 BASIS. It was SAP_APPL
616.
Horst Keller in response to Jelena Perfiljeva on page 14
7 Oct, 2014 12:44 PM
Hi Jelena,
better place your demand here http://scn.sap.com/docs/DOC-58352, that's where the more important guys are
involved.
Horst Keller in response to Shai Sinai on page 10
7 Oct, 2014 12:40 PM
FILTER is translated to DELETE and VALUE FOR to LOOP. DELETE is faster (in fact the "full text search" in
the ABAP Keyword Documentation is nothing but a DELETE on the text index table).
Couldn't it be optional (with the risk bad performance)?
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
What is shorter?
DATA(jtab) = FILTER #( itab WHERE ... ).
or
DATA(jtab) = itab.
jtab = VALUE #( FOR wa IN itab WHERE ( ... ) ( wa ) ).
And retranslated to statements, what is faster?
jtab = itab.
DELETE jtab WHERE NOT ...
or
LOOP AT itab INTO DATA(wa) WHERE ...
INSERT wa INTO TABLE jtab.
ENDLOOP.
Doesn't VALUE (FOR) uses table key when possible?
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
No, same as for LOOP. You must specify USING KEY in order to keep programs stable in case a (dictionary)
type is enhanced with secondary keys lateron.
Shai Sinai
7 Oct, 2014 11:48 AM
Regarding "FILTER with single values",
1. I know it might sound petty, bu how is it shorter then VALUE (FOR)?
2. Why is there a prerequisite for sorted/hashed key? Doesn't VALUE (FOR) uses table key when possible?
Horst Keller in response to Suhas Saha on page 12
7 Oct, 2014 11:11 AM
Ok, I added it also to the text.
Suhas Saha in response to Horst Keller on page 12
7 Oct, 2014 11:07 AM
You caught me there, my bad! I realised it a couple of minutes after posting the comment, hence i deleted it.
Horst Keller
7 Oct, 2014 11:03 AM
So, it doesn't work on standard tables.
It does work on standard tables with secondary keys and the USING KEY addtition of FILTER.
Eitan Rosenberg in response to Horst Keller on page 12
7 Oct, 2014 10:13 AM
Hi,
Thanks for prompt response .
Yes I understand that "ABAP is not like Java" .
I am not saying that it should. But it seems to me that for the benefit of programmers productivity and code
quality a quick upgrade is something to wish for .
Organization simply do not upgrade because of the overhead involve.
I am not happy....
Regards.
Horst Keller in response to Eitan Rosenberg on page 14
7 Oct, 2014 8:35 AM
I just install a new JDK and I have all the new features
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
ABAP is not like Java. ABAP is the programming language of the ABAP Application Server (AS ABAP) of SAP
Netweaver. You need an AS ABAP and an underlying database to work in ABAP. In former times this was the
so called SAP Basis as part of an R/3 System and you normally had to have access to such a system in order
to work with ABAP. Standalone SAP Basis systems (R/3 without application programs so to say) were more or
less rare.
Nowadays the namings and environments have become more and more complex and I (as the ABAP language
documentation writer) am far from having a synoptic view of this. Here people with more knowledge come into
play. See e.g. Karl Kessler's contributions to this subject, e.g. Understanding Kernel Releases for the SAP
NetWeaver AS ABAP or Demystifying SAPs Support Strategy for SAP NetWeaver 7.4.
But all in all it hasn't changed too much, that you need to have access to an AS ABAP of Release 7.40,
SP08 in order to work with the features of ABAP Language 7.40, SP08. And on this AS ABAP, everything
has to match. You must have the respective Kernel Release (742 for ABAP 7.40, SP08), the respective
ABAP Support Package (tools, texts, and other repository objects must match the kernel requirements) and
meanwhile you even need a matching database version (e.g. some new built-in ABAP CDS functions are
delivered with required database versions only)!
How to get there is another question. Possiblities can include upgrading your ERP, BW, or whatsoever,
installing a standalone Newtweaver or AS ABAP, or getting access to a trial version in the cloud once it is
available (see Christopher Kstner's contributions). To my knowledge, the free AS ABAP Trial Versions for
local installation are not available any more.
But this discussion is far out of scope of my blogging about some ABAP Language news. For this there are
places like SAP NetWeaver Application Server or SAP NetWeaver Technology Platform. There you find
another more general document http://scn.sap.com/docs/DOC-58352, that might to be a much better starting
point for asking these questions.
J#nis B in response to Jelena Perfiljeva on page 14
7 Oct, 2014 8:12 AM
According to our Basis, for "technical use ECC systems", we need to upgrade to EHP7 for SAP ERP 6.00 in
order to get to Netweaver 7.40.
Nikolay Evstigneev in response to Jelena Perfiljeva on page 14
7 Oct, 2014 7:54 AM
Hi, Elena!
We also decided it would be easier to upgrade from EhP6 to EhP7 to get new ABAP
Couldn't but quote your words about
"what comes with what" or "how to get from here to there".
Unfortunately, it's really not evident at all.
Custodio de Oliveira in response to Jelena Perfiljeva on page 14
ABAP Development: ABAP News for 7.40, SP08 - More for Internal Tables
I am reading about all this wonderful enhancements to ABAP and I do like them.
But I wander what needs to be done to get those new shining tools ?
For example when a new Java release is out I just install a new JDK and I have all the new features , I do not
need to do any thing else.
Regards.