‎2009 Jan 02 6:15 AM
Hi all,
In read statement, is there a possibility to use 'contains string (CS)' instead of '=' in with key?
I have a requirement to fetch from an internal table, the record whose field1 value contains a particular string.
Thanks,
David.
‎2009 Jan 02 6:22 AM
hi,
You can have the String operation in READ statement. Instead you need to use the Loop ..Endloop statement.
LOOP AT itab WHERE field CS l_field.
* Do your Process.
ENDLOOP.
‎2009 Jan 02 6:18 AM
Hi David,
The contain string operations cannot be used in the read statement.
instead you use it in the select clause.
for eg.
data: l_srch_str type string.
l_srch_str = 'ABC%'.
select *
from <table>
into table itab
where <fieldname> like l_srch_str.
regards,
Santosh Thorat
‎2009 Jan 02 6:19 AM
Hi David,
LOOP AT <ITAB> where <Field> CS <VALUE>.
**********Do your work here.
EXIT.
ENDLOOP.
Hope it wors for you.
‎2009 Jan 02 6:25 AM
Hi Sanket and Vinod,
Thanks for the reply.
Can you tell me the impact on performance when using loop with where condition instead of a read?
The scenario is:
I have a loop which will have thousands of record.
In this loop, I have to use my requirement of fetching from an internal table.
Thanks,
David.
‎2009 Jan 02 10:16 AM
Hi David,
LOOP will definitely have impact on performance. But if there is no other way then we have to compromise.
SORT the table based on the field u want to check will help a lot when using LOOP with Where clause.
Thanks,
Vinod.
‎2009 Jan 02 10:25 AM
Hi David..
Try using Wild card character % in READ to check for Contains string..
Ex
read table t_vbak into wa_vbak with key vbeln = '%53%'.
Check whether something like the above is givin any error............ i am trying to read the internal table where VBELN contains the string 53
Cheers..
‎2009 Jan 02 6:20 AM
HI,
There is no way u can use any operator other than = with read statement.
Instead u can use loop statement.
CLEAR wa.
LOOP AT itab INTO wa WHERE field CS ur value.
EXIT.
ENDLOOP.
now ur wa contains required data.
Thanks,
Vinod.
‎2009 Jan 02 6:22 AM
hi,
You can have the String operation in READ statement. Instead you need to use the Loop ..Endloop statement.
LOOP AT itab WHERE field CS l_field.
* Do your Process.
ENDLOOP.
‎2009 Jan 02 6:23 AM
Hi,
In Read Statement you cannot use like statement, you can use only =.
Thanks,
Sriram POnna.
‎2009 Jan 02 6:24 AM
HI,
First try to read table with some other key field...
And then use if to check ur condition.
loop at itab.
read table itab1 with key f1 = itab-f1.
if sy-subrc = 0.
if itab1-f2 CS 'abc'.
move data.
endif.
endif.
endloop.
Try this.
Regards,
Mr.A
‎2009 Jan 02 6:26 AM
HI
it won't accept CS in read table clause. syntax error will be displayed.
for more clarity just execute the falloing code.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARA-MATNR,
ERSDA LIKE MARA-ERSDA,
ERNAM LIKE MARA-ERNAM,
END OF ITAB.
SELECT MATNR
ERSDA
ERNAM
FROM MARA
INTO TABLE ITAB
WHERE ERNAM = 'BOHNSTEDT'.
IF SY-SUBRC EQ 0.
SORT ITAB BY MATNR ASCENDING.
READ TABLE ITAB WITH KEY MATNR CS '3'.
IF SY-SUBRC EQ 0.
WRITE: ITAB.
ENDIF.
ENDIF.
‎2009 Jan 02 6:41 AM
Hi David,
As per the performence if u having a lot of record u will follow the Phani Krishna suggestion. Loop logic will fine with small no. of recocords.
‎2009 Jan 02 6:43 AM
you cant use other than = in Read statement.
As you requirement is to find a singe record from a internal table, try these ways
1. Read the table with some other index and try using LOOP at where FROM INDEX
2. Make the table as SORTED with the column as key and then LOOP AT WHERE F1 CS 'XXX'.
for better performance only...
Edited by: Sumanth Nag Kristam on Jan 2, 2009 7:43 AM
‎2009 Jan 02 10:33 AM
Hi,
fatching recordds with read statement.
READ TABLE <ITAB> INTO <WA> INDEX 1.
READ TABLE <ITAB> INTO <WA> WITH KEY <FIELD NAME> = 'VALUE'.
READ TABLE <ITAB> INTO <WA> INDEX 1 TRANSPORTING NO FIELDS.
Regards
Md.MahaboobKhan