‎2009 Jan 29 11:47 AM
Hi Folks!
And again I got a little question abount accessing dynamically created data structures 😃
I got a table type called zzcca_t_data which has a REF TO DATA as rowtype.
I am creating the type of each row in runtime, because it depends on users input.
I was wondering, if there is a way to random access a certain row in that table by using a key, like:
READ TABLE ..... WITH KEY = ...I am afraid, that there is no standard way to do that, maybe some special object components etc?
My idea is to make sure, that the table is sorted by a certain criteria and the implement a binary search on it using an index and access the table using
READ TABLE ..... INDEX ...Is there a better way to do that?
Thanks a lot in advance!!
Best regards!
Kamil
‎2009 Jan 29 9:22 PM
Hi,
You probably deref it to a field-symbol.
DATA: dref TYPE REF TO data,
CREATE DATA dref TYPE vbak.
assign dref->* to <fs> "<fs> points to internal table
Now you can read this table using the following syntax.
data key(20) type c.
key = 'VBELN' " for example
read table <fs> with key (key) = '0000000001'.
regards,
Advait
‎2009 Jan 29 8:26 PM
Have you tried "FROM wa" instead of "WITH KEY ..."? But even "FROM wa" needs to know the key of the table, so this might not work...
Otherwise the form "WHERE table_key CS ..." might work...
But the above solutions are only tricks. I suggest that you build a new table where you store only the search key AND the tabix to the original table. Even if you don't know the key you should be able to use "WITH KEY table_line = ..." (note the equality operator) and then use the tabix to access the big table.
‎2009 Jan 29 8:47 PM
I got a table type called zzcca_t_data which has a REF TO DATA as rowtype.
As each of your table row can only store reference of some data objects you can't read this table with read table ... with key.... You simply don't know what will be the address inside a row.
I suggest to rebuild your table adding first field as a key field
types: begin of t_tab,
key_field type ...,
data type ref to data,
end of t_tab.
types: tt_tab type table of t_tab with key key_field.
Then you can access in with a key. Otherwise you can't even sort such table.
Regards
Marcin
‎2009 Jan 29 9:13 PM
You need to assign the data to the Field Symbol (type any table) to do any operation like: READ, LOOP etc.
DATA: L_REF TYPE REF TO DATA.
FIELD-SYMBOLS: <LT_TEXT> TYPE ANY TABLE,
<LA_TEXT> TYPE ANY.
ASSIGN L_REF->* TO <LT_TEXT>.
READ TABLE <LT_TEXT> ASSIGNING <LA_TEXT> INDEX 1.
Regards,
Naimesh Patel
‎2023 Sep 25 10:43 AM
This cant work, check attached pic.2023-09-25-11-43-07-window.jpg
‎2009 Jan 29 9:22 PM
Hi,
You probably deref it to a field-symbol.
DATA: dref TYPE REF TO data,
CREATE DATA dref TYPE vbak.
assign dref->* to <fs> "<fs> points to internal table
Now you can read this table using the following syntax.
data key(20) type c.
key = 'VBELN' " for example
read table <fs> with key (key) = '0000000001'.
regards,
Advait
‎2009 Jan 30 10:12 AM
EDITED:
Problem solved!! 😃
The Problem was that I haven created the table with a certain type but I created every row on its own. Now I created the data reference with a certain table type and now it works the way below.
Thank you very much!!
Best regards from Vienna!
Kamil
-
Hi all!!
Thank you very much for your helpful replies.
I tried to user the way of Advait Gode with
DATA: dref TYPE REF TO data,
CREATE DATA dref TYPE zzcca_t_data.
field-symbols:
<fs1> type zzcca_t_data, "Tabletype with REF TO DATA as ROWTYPE
<fs2> type any.
assign dref->* to <fs1> .
data key(20) type c.
key = 'POSNR' " the structire zzccbo_belpos
read table <fs> with key (key) = '00001'. "NUMC5
Unfortunately I get a pretty shortdump "ITAB_ILLEGAL_COMPONENT" because it says that there is no element POSNR in <fs1>.
=/
Thanks in advance!!
Best regards,
Kamil
Edited by: Kamil Kubicki on Jan 30, 2009 11:35 AM
‎2009 Jan 30 1:31 PM
Hi Kamil,
key = 'POSNR' " the structire zzccbo_belpos
I am not sure what is structure zzccbo_belpos but here all you need is row type with POSNR field as key field.
What you wrote is interpreted like:
"create a pointer to a table (typed zzcca_t_data)
CREATE DATA dref TYPE zzcca_t_data.
"declare a field symbol which is able to get the content of a table under address stored by pointer
field-symbols:
<fs1> type zzcca_t_data,
"now poiter still has table address by also field symbol allows us to get table content (as it doesn't have name)
assign dref->* to <fs1> .
read table <fs> with key (key) = '00001'. "NUMC5
"now read table content (which is get throught field symbol) where key field is POSNR
"this is wrong because your table seems not to have this field, you said it is of row type ref to data so it is type like this
types: begin of zzcca_t_data,
some_ref_field type ref to data,
end of zzcca_t_data.
"and should be
types: begin of zzcca_t_data,
posnr type numc5, "this field is must exist otherwise you can't read this table supplyijng this field as key field
some_ref_field type ref to data,
end of zzcca_t_data.
"I gusess what you did is that you replaced
types: zzcca_t_data type table of ref to data.
"...with above 1st declaration, but these statements are excatly the same. In second case you only use
"field name to address table row but no difference in logic (still you can't read it with key access as there is no such)
"what I suggest you is either add POSNR field to a table type (as above) or read it with index access as my predeccesors said
Hope this claryfies you bug
Marcin
PS: Advait's code is correct because he is typing his table with VBAK so it already has key fields inside, therefore he is later able to access that table with particular key
Edited by: Marcin Pciak on Jan 30, 2009 2:32 PM