Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Inline internal table declarations in ABAP 7.40

34,672

Hello folks,

I've been coming across the new capabilities ABAP 7.40 has to offer which really has helped transform the traditional convention and reduced the coding effort and complexity. However, there are some areas where I'm unable to get any explanation in terms of reading a table which has been declared inline on OpenSQL while querying from a HANA database:

Apparently it is advised to use SORTED or HASHED table declarations as this does not require additional BINARY SEARCH mechanism which is used to read a record from internal table very fast as we all know that the functionality of binary search it divides the into parts and searches. For example(Before ABAP 7.40):

* Sorted Table Declaration
DATA: lt_vbpa TYPE SORTED TABLE t_vbpa WITH UNIQUE KEY vbeln.

SELECT vbeln 
       posnr
FROM vbpa 
INTO TABLE lt_vbpa
WHERE vbeln IN s_vbeln. "Input from Selection Screen
IF sy-subrc EQ 0.
  * Reading Table (No Binary Search Required)
  READ TABLE lt_vbpa ASSIGNING FIELD-SYMBOL(<fs_vbpa>) WITH KEY vbeln = '1200873520'.
  IF sy-subrc EQ 0.
   lv_posnr = <fs_vbpa>-posnr.
  ENDIF.
ENDIF.

(After ABAP 7.40 HANA)

* OpenSQL statement
SELECT vbeln
       posnr
FROM vbpa
INTO TABLE @DATA(lt_vbpa) "Inline declaration with dynamic type assignment
WHERE vbeln IN s_vbeln. "Input from Selection Screen
IF sy-subrc EQ 0.
  * New read statement replacement in 7.40 table expression
  lv_posnr = lt_vbpa[ vbeln = '1200873520' ]-posnr.
ENDIF.

In the above example with OpenSQL statement with inline internal table declaration and table expression for reading and assigning value to a variable we can understand that no sorted table declaration or explicit sorting is being performed before the table expression, hence no binary search. I want to confirm whether the new syntax automatically takes care of such things or is there a way to perform such operations if required in terms of performance improvement.

Thanks.

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
5,131

You should search the documentation, everything is explained there :

"intot table @data(itab) declares a STANDARD TABLE itab of this row type with an empty table key"

So you should declare a HASHED or SORTED table to access it more quickly (as it's more easy to use than BINARY SEARCH).

However, an inline declaration is temporarily useful because Eclipse ADT can convert the inline declaration into an explicit declaration, and you may then easily replace "standard".

9 REPLIES 9

Sandra_Rossi
Active Contributor
5,132

You should search the documentation, everything is explained there :

"intot table @data(itab) declares a STANDARD TABLE itab of this row type with an empty table key"

So you should declare a HASHED or SORTED table to access it more quickly (as it's more easy to use than BINARY SEARCH).

However, an inline declaration is temporarily useful because Eclipse ADT can convert the inline declaration into an explicit declaration, and you may then easily replace "standard".

matt
Active Contributor
0 Kudos
5,131

However, an inline declaration is temporarily useful because Eclipse ADT can convert the inline declaration into an explicit declaration, and you may then easily replace "standard".

Hmm. I didn't know that.

5,131

Matthew Billingham check below illustration:

Before:

After (type "helper_type" generated automatically):

0 Kudos
5,131

However, an inline declaration is temporarily useful because Eclipse ADT can convert the inline declaration into an explicit declaration, and you may then easily replace "standard".

Can you show how we can change the type explicitly for inline table declarations. In the above example given by you I can see that the structure for helper_type is already being declared and the same has been used in the query for @xx, so does that mean we have to specify the type before inline declaration in case of SORTED or HASHED tables?

5,131

Noman Mohamed Hanif Context menu "convert to local variable" or "convert to attribute". It generates the type as I show in the screenshots "before" and "after" convert.

0 Kudos
5,131

Hello Sandra,

can you tell me where i can find the "convert to local variable" function ? (a screenshot would be very useful)

Best regards,

Domenik

5,131

d_enkel place the cursor at the beginning of the variable, and press Ctrl + 1 (or remap it to other key combination if it doesn't work with your keyboard)

5,131

thank you for your support !

matt
Active Contributor
5,131

For HASHED and SORTED tables you must explicitly define before you use them in a SELECT.