‎2007 Jul 23 2:59 PM
Hi all,
Is it possible to use an 'OR' condition with read table itab into wa with key addition.?
example: read table itab into wa with key field1 = A
or field1 = B
or field1 = C.
Thanks.
Mungala
‎2007 Jul 23 3:01 PM
Not as I can know... you can but, do a three consecutive READ TABLES, one per each field you want to check 😕
(check the code by Rich Heilman a bit down... it's pretty better than mine :P)
READ TABLE itab INTO wa WITH KEY field1 = X.
IF sy-subrc <> 0.
READ TABLE itab INTO wa WITH KEY field2 = Y.
IF sy-subrc <> 0.
READ TABLE itab INTO wa WITH KEY field3 = Z.
ENDIF.
ENDIF.
CHECK sy-subrc = 0. "Or an IF, of courseMessage was edited by:
Vicenç Lozano
Message was edited (again) by:
Vicenç Lozano
‎2007 Jul 23 3:01 PM
‎2007 Jul 23 3:01 PM
Hi,
We can not use the OR condition in the Read table, but you can use the Comparing option to compare the fields
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm
Regards
Sudheer
‎2007 Jul 23 3:02 PM
‎2007 Jul 23 3:06 PM
It is not possible to use OR command on read but there are different approches to acheive this.
Rgds,
Sairam
‎2007 Jul 23 3:08 PM
Praveena,
That is possible within Loop .. endloop.
You can loop in the internal table and can come out of it, when u find the required record.
Regards,
Sujatha
Message was edited by:
Sujatha
‎2007 Jul 23 3:33 PM
Hi,
Specifying the Search Key
The search key may be either the table key or another key.
Using the Table Key
To use the table key of <itab> as a search key, enter <key> as follows:
READ TABLE <itab> FROM <wa> <result>.
or as follows
READ TABLE <itab> WITH TABLE KEY <k1> = <f1> ... <kn> = <fn> <result>.
In the first case, <wa> must be a work area compatible with the line type of <itab>. The values
of the key fields are taken from the corresponding components of the work area.
In the second case, you have to supply the values of each key field explicitly. If you do not know
the name of one of the key fields until runtime, you can specify it as the content of a field <ni>
using the form (<ni>) = <fi>. If the data types of <fi> are not compatible with the key fields, the
system converts them.
The system searches for the relevant lines as follows:
Standard tables
Linear search, where the runtime is in linear relation to the number of table entries.
Sorted tables
Binary search, where the runtime is in logarithmic relation to the number of table entries.
Hashed tables
The entry is found using the hash algorithm of the internal table. The runtime is
independent of the number of table entries.
Using a Different Search Key
To use a key other than the table key as a search key, enter <key> as follows:
READ TABLE <itab> WITH KEY = <f> <result>.
or as follows
READ TABLE <itab> WITH KEY <k1> = <f1> ... <kn> = <fn> <result>.
In the first case, the whole line of the internal table is used as the search key. The contents of the entire table line are compared with the contents of field <f>. If <f> is not compatible with the line type of the table, the value is converted into the line type. The search key allows you to find entries in internal tables that do not have a structured line type, that is, where the line is a single field or an internal table type.
In the second case, the search key can consist of any of the table fields <k1>...<kn>. If you do not know the name of one of the components until runtime, you can specify it as the content of a field <ni> using the form (<ni>) = <fi>. If <ni> is empty when the statement is executed, the search field is ignored. If the data types of <fi> are not compatible with the components in the internal table, the system converts them. You can restrict the search to partial fields by
specifying offset and length.
The search is linear for all table types. The runtime is in linear relation to the number of table lines.
Regards,
Bhaskar
‎2007 Jul 23 3:39 PM
Hi,
HAve a look at this link:
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/read.htm
Pls reward points.
Regards,
Ameet