Application Development and Automation 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: 
Read only

Binary Search with Dynamic Tables

Former Member
0 Likes
1,426

Hi guys,

i created a dynamic table using following code:


call method cl_alv_table_create=>create_dynamic_table
     exporting
       it_fieldcatalog = LT_FIELDCATALOG
     importing
       ep_table = r_dyn_table
...

btw: that part creates a dynamic table with a flexible/dynamic structure.

After that i filled the dynamic table with thousands of datarecords.

later in my program i try to update one specific row of that table.

So, i need a binary search mechanism for my dynamic table. is there already a possibility to do that easyly or do i have to write my own binary search mechanism ?

Please help me.

Thanks

sven

.

Edited by: Sven Delangle on Nov 12, 2010 9:51 AM

Edited by: Sven Delangle on Nov 12, 2010 9:57 AM

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,049

Hello Sven,

No need to build your own Binary Search algo You can use dynamic tokens with SORT & READ TABLE commands.

Check this code snippet:

FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.

SORT <itab> BY ('FIELD1') ('FIELD2').

READ TABLE <itab> TRANSPORTING NO FIELDS 
WITH KEY ('FIELD1') = VAL1
         ('FIELD2') = VAL2 BINARY SEARCH.

Here FIELD1 & FIELD2 are components of the dynamic table <itab>.

BR,

Suhas

4 REPLIES 4
Read only

Former Member
0 Likes
1,049

Hi,

The internal table I guess is filled with data from database tables which is dynamic here in your name. What you could do is do a select on DD03L and get the tabname, fieldname where AS4LOCAL = active and keyflag = 'X'. You will get the list of key fields. Put them into an internal table against the table name. Loop at this internal table and assign the key field names into separate variables (key fields wouldn't obviously be more in number)

Sort your dynamic internal table based on the table name using these variables like


SORT itab BY (lv_field1) (lv_field2).

Have never tried out. So not sure how effective this would be.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,050

Hello Sven,

No need to build your own Binary Search algo You can use dynamic tokens with SORT & READ TABLE commands.

Check this code snippet:

FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.

SORT <itab> BY ('FIELD1') ('FIELD2').

READ TABLE <itab> TRANSPORTING NO FIELDS 
WITH KEY ('FIELD1') = VAL1
         ('FIELD2') = VAL2 BINARY SEARCH.

Here FIELD1 & FIELD2 are components of the dynamic table <itab>.

BR,

Suhas

Read only

matt
Active Contributor
0 Likes
1,049

You could also use the RTTS to create your dynamic table directly as SORTED or HASHED, for even greater efficiency.

matt

Read only

Former Member
0 Likes
1,049

Hi Matt,

my problem was already solved by the previous post.

but thanks for the hint.