Of a reader stream type, this type is created. The components of the work area that are notĪre assigned directly to the corresponding columns of the new row. Prerequisites) exactly like the structure of the database table. When a LOB handle structure is specified, it must be constructed (in accordance with the Of the row to be added is taken from the work area wa while ignoring its data type and without converting it from left to right in accordance with the structure of the database table or the When specifying a work area that does not contain any reference variables for Prerequisites for use in Open SQL statements. Host expression), from whose content a row is created for insertion in the database table. Strict modes of the syntax check from Release 7.40, SP05.Īfter VALUES and FROM, a non-table-like work area wa can be specified (as a The escape character must be specified in the Host variables without the escape character are The escape character should precede the work area name or the internal table name (as should be the case with every To be inserted are taken from these data objects. After FROM TABLE, an internal table itab can also be specified. Ī non-table-like data object wa can be specified as a data source after theĪdditions VALUES and FROM of the statement INSERT. Feel free to play with it or even send any updates back via GitHub.SAP NetWeaver AS ABAP Release 752, ©Copyright 2017 SAP AG. It was just a quick-n-dirty originally for comparing just two options and just grew as a copy/paste of alternatives. If we’re talking anything less than thousands in a short space of time then you can safely ignore the impact.Īfter several comments and suggestions, I uploaded my test program to GitHub at abap_itab_perf to use a single catch handler for multiple expressions), but be mindful of the expected failure rate and performance-criticality of the component. TRY-CATCH with table expressions can be a useful way to structure your code (e.g.(Yes, I know, ‘new’ ABAP can be used to make code either more readable or more cryptic, but that’s another discussion) For compact and/or readable code, use table expressions.If performance is number 1 priority and you need the data, READ TABLE is fastest.If you don’t need the data, line_exists( ) is fastest.line_exists( ) became a poor choice in my scenario, because we need to double up the the search in order to also read the record:.the exception was no longer an influence (to be expected). I suspect that this applies to CATCH blocks in general, but that’s another analysis for another day.įor comparison, I also re-ran the same but this time with a lookup value that did exist. I’m happy to sacrifice a little performance for readability, but this is a significant impact. So the take-away here for me is that a TRY-CATCH may be easier to read, but should not be used in performance-sensitive code unless you expect the values to be found most of the time. I tested a million failed lookups on a 7.50 HANA system. Here are the results in microseconds: line_exists( ) : 610,758 ASSIGN itab – which (bizarrely) sets SY-SUBRC instead of producing an exception.The trusty READ TABLE … WITH KEY, with and without TRANSPORTING NO FIELDS.Results:įor completeness, and additionally with suggestions by Former Member, Quynh Doan Manh and Uwe Fetzer in the comments, I also added a couple of other ways to look for an entry in a table: I mean, why use x = VALUE #( y ) when you can just write x = y? The VALUE constructor’s sole purpose here is the OPTIONAL bit that lets us do away with the exception.Īs I was working on a performance-sensitive component, I tested it to see what performs best. This particular usage of VALUE may seem a little awkward. If the matching entry cannot be found, you need to catch the exception: TRY.Īnother alternative is to use a VALUE constructor expression where you can add the keyword OPTIONAL (or DEFAULT) to just initialize any non-found values. So the following READ TABLE can be rewritten using a table expression (the bit in square brackets): READ TABLE itab INTO row WITH KEY id = find_id. I have a table that includes a field “ID”. With table expressions, finding an entry in a table is really neat. Quick primer for those still getting accustomed to 7.4 ABAP (feel free to skip to the results): The unexpected result was that when a row can’t be found, using table expressions with exceptions is ten times slower on average than all other lookup methods, including the good ol’ fashioned READ TABLE with SY-SUBRC. My scenario involved internal table searches where the values would be missing a lot of the time. I got a blog-worthy surprise when I did a quick performance test on two different ways to use the new-ish (7.4) table expressions to perform a search on an internal table.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |