‎2008 Jan 04 2:42 PM
Consider the scenario.
data: itab type standard table of sflight-connid.
data: wa like line of itab.
how can i retrieve single record from itab using read statement using a logical expression.
read ,,,,,, logi_exprs.
Note: Here there is no header with name connid, so comparing connid = 'LH'
(field1= X) will result in an error.
Edited by: IMRAN PASHA on Jan 4, 2008 4:05 PM
Please suggest if it can be done without usage of index
Edited by: IMRAN PASHA on Jan 4, 2008 4:36 PM
‎2008 Jan 04 3:04 PM
The internal table does not have a structure. So direct comparision of fields will result in an error.
read itab into wa with fields with key connid = 'lh'. will result in an error saying that the structue does not contain any element with project id.
‎2008 Jan 04 2:48 PM
Imran,
If you know the index of the record, XINDEX is your records index
READ TABLE ITAB INDEX XINDEX INTO WA_ITAB.
If you know the key then it would be
READ TABLE ITAB
WITH TABLE KEY FIELD1 = 'XX' FIELD2 = 'YYYY' .
Howe this helps.
Vinodh Balakrishnan
‎2008 Jan 04 2:54 PM
READ TABLE itab INTO wa WITH KEY connid = wa_sflight-connid
different types of read statements are :
READ TABLE <EMPTAB> options:
1 READ TABLE <EMPTAB>.
2 READ TABLE <EMPTAB> WITH KEY <k1> = <v1>
<kn> = <vn>.
3 READ TABLE <EMPTAB> WITH TABLE KEY <k1> = <v1> ...
<kn> = <vn>.
4 READ TABLE <EMPTAB> WITH KEY = <value>.
5 READ TABLE <EMPTAB> WITH KEY . . . BINARY SEARCH.
6 READ TABLE <EMPTAB> INDEX .
7 READ TABLE <EMPTAB> COMPARING <f1> <f2> . . . .
8 READ TABLE <EMPTAB> COMPARING ALL FIELDS.
‎2008 Jan 04 2:56 PM
You can do
READ TABLE ITAB into WA
WITH KEY field1 = valuex
field2 = valuey......
However here you can only specify an equal as condition. If you want to use other logical expressions you need to do
LOOP AT ITAB INTO WA WHERE field1 log_expressionx AND/OR
field2 log_expressiony .......
EXIT.
ENDLOOP.
Hope that helps,
Michael
‎2008 Jan 04 3:01 PM
Hello,
Here is simple & short way to do this:
LOOP AT itab INTO wa WHERE <logi_exprs>.
EXIT.
ENDLOOP.
IF sy-subrc = 0.
Record matching condition was found
ELSE.
Record matching condition was NOT found
ENDIF.
In this manner you will get first record from itab that maches <logi_exprs>.
Regards,
Reinis Dzenis
‎2008 Jan 04 3:04 PM
The internal table does not have a structure. So direct comparision of fields will result in an error.
read itab into wa with fields with key connid = 'lh'. will result in an error saying that the structue does not contain any element with project id.
‎2008 Jan 04 4:17 PM
Hi Imran,
I don't know what your requirements are but here is what you are looking for:
data: itab type standard table of sflight-connid.
data: wa1 like line of itab,
*wa2 like line of itab.*
select connid from sflight
into TABLE itab.
* set the logical expression, can be done in a loop
wa1 = '0017'.
* read the table using a work area instead of a key assignment
READ TABLE itab into wa2
from wa1.
* with key connid = '0017'.
if sy-subrc eq 0.
write :/ wa2.
endif.
Normally, an internal table is read using a key or an index. But in this case, key is not available as there is no structure and no component, we still can make use of FROM WA addition of the READ TABLE statement, see above.
Using index to read the table was definitely not part of the requirement in the initial post sent by you.
Hope this helps.
Thanks
Sanjeev
‎2008 Jan 04 4:23 PM
>
> The internal table does not have a structure.
If that is the case, then what logical expression do you expect to have? Logical expression requires two operands(fields or values) and an operator. If you don't know the operands how do you expect to have a logical expression?
‎2008 Jan 04 4:28 PM
You will have to define your itab like this to have a structure.
TYPES: BEGIN OF ty_itab,
connid TYPE s_conn_id.
TYPES: END OF ty_itab.
DATA: itab TYPE STANDARD TABLE OF ty_itab.
DATA: wa LIKE LINE OF itab.
READ TABLE itab INTO wa WITH KEY connid = 'LH'.
‎2008 Jan 04 3:16 PM
Hi Imran,
You can try like below,
REPORT YSAT_TEST6 .
data: itab type standard table of sflight-connid.
data: wa like line of itab.
wa = '1234'.
append wa to itab.
read table itab index 1 into wa.
if sy-subrc = 0.
write: /10 wa.
endif.
Regards,
Satya