![]() ![]() If a line is not found, the OPTIONAL addition returns an initiial line while the DEFAULT addition returns a given value, that can be specified as an expression, especially another table expression. Not everybody liked this behavior.Īs a workaround, you can place a table expression inside a VALUE or REF expression, that contains a OPTIONAL or DEFAULT addition. Up to now, an exception was raised anytime if a table line specified in the square brackets could not be found. Table expressions itab cannot support sy-subrc. Neat if you're on SP08 or higher already: when used in the table function line_index, where the value 0 is returned.when used in the predicate function line_exists, where the logical value "false" is returned,.a table expression is used in the statement ASSIGN, where sy-subrc is set to the value 4,.a default value is specified in the definition of the type of the result,.If the specified row is not found, a handleable expression of theĬlass CX_SY_ITAB_LINE_NOT_FOUND is raised in all operand positions, Having said that, the documentation mentions: About the exception: The thing that matters most in the end is whether or not your program crashes, and whether or not you're displaying meaningful data.Īs for design principles, over the whole I think I'd rather put some effort into the DRY principle if you do a lot of this in your program. You have an additional issue - depending on your table definitions, I can't see those - that aedat might not be a primary key in which case you might be trying to cram another table type into a work area. Technically, in the old scenario you should also be catching SUBRCs before moving into structures too. This is debatable I guess but my 2 cents: Sometimes ignoring an exception is OK, for instance if you just want to, in your case, display an empty cell. ![]() I was typing a comment but it's getting to long. Is there any way to improve the readability of these table expressions? Am I using them improperly? Since every individual read might need to fail or succeed individually this quickly balloons out of proportion: TRY. Which is both longer and makes any simple read logic look incredibly complex and hard to read. However, it fails to mention that if a table expression fails to find a line it will raise exception CX_SY_ITAB_LINE_NOT_FOUND, so really that notation should actually be: TRY. With a single-line lv_order = lt_aufk-aufnr. Read about more such ABAP expressions and exciting new syntaxes: ABAP Expressions (7.An official SAP presentation discussing new ABAP programming features in NetWeaver 7.4 (CD261) makes a big deal about table expressions, replacing the old syntax to read from an internal table: READ TABLE lt_aufk INTO ls_aufk WITH KEY aedat = sy-datum. SELECT * FROM sflight INTO TABLE it_flights. DATA : it_flights TYPE SORTED TABLE OF sflight Binary Search in new READ syntaxĪdvertisements Before I end this post, an important question is – what about BINARY SEARCH? Well, use sorted table and binary search would be used implicitly. So do not use this just to avoid using try-catch but use it only when there is an actual need. Here, you have to be careful as the variable/structure will be blank in case the read fails. ls_flight = VALUE #( it_flights OPTIONAL ). In the scenarios where handling the case where READ failed is not at all required, you can skip the try-catch using the OPTIONAL keyword. In this case, the exception is not required to be handled but a sy-subrc check works just fine. The result of the expression can be assigned to a fiel d symbol as well. It can be used in IF blocks IF it_flights-planetype = 'A319'. data(plane_type) = it_flights-planetype.Ģ. A field from the result can be used with – the field name. AdvertisementsĪs this is an expression and not a statement, it can be used at any operand position, which was impossible with the READ TABLE statement.ġ. You can handle the SY-SUBRC 0 cases in CATCH block. The control will move to CATCH block when READ fails. Raises an exception CX_SY_ITAB_LINE_NOT_FOUND when the read expression fails "Write read expressions in TRY-CATCH blocks.important thing to note here is that the new expression If you are trying out the above code example – please add the below code block before these statements. One free key READ TABLE it_flights INTO ls_flight WITH KEY carrid = 'SQ'Ĭonnid = '0026'. Read with free key READ TABLE it_flights INTO ls_flight Variable READ TABLE it_flights INTO ls_flight INDEX lv_idx. Number READ TABLE it_flights INTO ls_flight INDEX 1. It is possible to use inline data declaration here to create an internal table and work area but it is declared explicitly at the top so that we can focus on the READ TABLE syntax Context Before ABAP 7.40 From ABAP 7.40 Read with index ![]()
0 Comments
Leave a Reply. |