‎2007 Sep 11 9:29 AM
Hi All,
I want to read a table for which a key is defined in another z table. So basically I want to achieve the following :-
Ideally we write a read statement like this :-
READ TABLE ITAB WITH KEY MATNR = '2021'.
But I want to read in the following way :-
data : var1 type string.
var1 = 'MATNR = ''2021'''.
READ TABLE ITAB WITH KEY VAR1.
The fields and conditions for the key are defined in a z table so I have to pass them dynamically to the read statement.
Please suggest how I can achieve this.
Thanks in advance,
Archana.
‎2007 Sep 11 9:34 AM
u cud try to use use field symbols
field-symbols: <fs_f>.
lv_feld = 'MATNR'.
assign (lv_feld) to <fs_f>.
READ TABLE ITAB WITH KEY <fs_f> = '022'.
‎2007 Sep 11 9:36 AM
Hi archana,
assing var1 value to work area. and use that work area as key.
Bohra.
‎2007 Sep 11 9:43 AM
Hi all,
I have already tried using field symbols but that doesn't work either. Plus the fact that I would not even know the value '2021'. Means the whole condition is to be taken from another table.
I also tried using the work area but it doesnt work. Is there a tested code you have tried ?
‎2007 Sep 11 9:58 AM
Hi,
try this...it is the way how we get the field dynamically...
tables: spfli.
<b>parameters</b>: field(10) type c,
value(10) type c.
data:
itab like standard table of spfli,
wa like line of itab.
select * from spfli into table itab.
condense field.
condense value.
read table itab with key <b>(field) = value</b> into wa.
if sy-subrc eq 0.
endif.
‎2007 Sep 11 11:13 AM
Hi All,
Actually I have a z table as follows :
RULE CONDITION
MER prodid = '10'
Now in the program I will select this row. I have an internal table which will already have a field 'prodid'. Now I want to read the records which satifies the condition 'prodid = 10'. This condition is only defined in the table and can be any field and any operand and any fixed value.
So i have this condition stored in a variable of string type var 1, where var1 = 'prodid=''10'''.
now I have to read the table with this condition.
READ TABLE ITAB WITH KEY VAR1.
Now this syntax is not accepted, so can anybody please suggest how we can achieve this ? I tries using field symbols as well but nothing worked.
The operand and fixed value are also not known so the whole condition has to be taken from the ztable.
Please suggest.
Thanks in advance,
Archana
‎2007 Sep 11 9:39 AM
Hi Archana,
You can do this by reading all MATNR values from DB table into an internal table and then looping it. You can give READ statment inside this loop and do further processing.
<b>DATA: BEGIN OF itab1 occurs 0,
matnr TYPE MATNR.
END OF itab1.
SELECT MATNR FROM <TABLE> INTO itab1 WHERE <conditions>.</b>
<b>LOOP AT itab1.
READ TABLE ITAB WITH KEY matnr = itab1-matnr.
.
.
.
.
ENDLOOP.</b>
*Reward points if it helps.
Regards,
Amit
‎2007 Sep 11 9:43 AM
hi
good
call function 'DDIF_FIELDINFO_GET'
exporting
tabname = v_tabname "<< dynamic table name
langu = sy-langu
tables
dfies_tab = i_dfies
exceptions
not_found = 1
internal_error = 2
others = 3.
if sy-subrc eq 0.
loop at i_dfies where fieldname ne 'MANDT' and keyflag eq 'X'.
assign component i_dfies-position of structure <xtab> to <f3>.
<< Here you get the key field value in the field symbol>>
endloop.
endif.
thanks
mrutyun^
‎2009 Feb 27 9:23 AM