‎2010 Nov 12 8:51 AM
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
‎2010 Nov 12 9:13 AM
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
‎2010 Nov 12 9:08 AM
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.
‎2010 Nov 12 9:13 AM
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
‎2010 Nov 12 10:08 AM
You could also use the RTTS to create your dynamic table directly as SORTED or HASHED, for even greater efficiency.
matt
‎2010 Nov 12 10:33 AM
Hi Matt,
my problem was already solved by the previous post.
but thanks for the hint.