2007 Aug 15 8:13 PM
I am a newbie trying to search in an internal table. I tried the following, but I am getting an error message saying that it expected type "string" for the internal table:
DATA:
BEGIN OF WA_TAB1,
WA_COLUMN1 TYPE TAB2-COLUMN1,
WA_COLUMN2 TYPE TAB2-COLUMN2,
END OF WA_TAB1,
TBL_TAB1 LIKE TABLE OF WA_TAB1
WITH KEY WA_COLUMN1,
TBL_TAB1_RESULT TYPE MATCH_RESULT_TAB.
FIND ALL OCCURRENCES OF 'ABC'
IN TABLE TBL_TAB1
RESULTS TBL_TAB1_RESULT.
How can I do a search like this within an internal table (like SELECT in SQL)? I expect to get several rows back and I need the content of all columns for these rows.
Thanks for your help,
D.
2007 Aug 15 8:24 PM
It appears that the system rather have the fields of the internal table as character type as opposed to string typed. This seems to work for me.
REPORT zrich_0002.
TYPES: BEGIN OF tab2,
column1(20) TYPE c,
column2(20) TYPE c,
END OF tab2.
DATA: BEGIN OF wa_tab1,
wa_column1 TYPE tab2-column1,
wa_column2 TYPE tab2-column2,
END OF wa_tab1,
tbl_tab1 LIKE TABLE OF wa_tab1
WITH KEY wa_column1,
tbl_tab1_result TYPE match_result_tab,
wa_tab1_result LIKE LINE OF tbl_tab1_result.
wa_tab1-wa_column1 = 'Column 1'.
wa_tab1-wa_column2 = 'Column 2'.
APPEND wa_tab1 TO tbl_tab1.
wa_tab1-wa_column1 = 'This is ABC in this column'.
wa_tab1-wa_column2 = 'Column 2'.
APPEND wa_tab1 TO tbl_tab1.
wa_tab1-wa_column1 = 'Column 1'.
wa_tab1-wa_column2 = 'Column 2'.
APPEND wa_tab1 TO tbl_tab1.
wa_tab1-wa_column1 = 'Column 1'.
wa_tab1-wa_column2 = 'This is ABC in this column'.
APPEND wa_tab1 TO tbl_tab1.
FIND ALL OCCURRENCES OF 'ABC' IN TABLE tbl_tab1
RESULTS tbl_tab1_result IN CHARACTER MODE.
LOOP AT tbl_tab1_result INTO wa_tab1_result.
READ TABLE tbl_tab1 INTO wa_tab1 INDEX wa_tab1_result-line.
IF sy-subrc = 0.
WRITE:/ 'Line:', wa_tab1_result-line, 'Offset:', wa_tab1_result-offset.
WRITE: 'Value is:', wa_tab1+wa_tab1_result-offset(3).
ENDIF.
ENDLOOP.
Regards,
Rich Heilman
Message was edited by:
Rich Heilman
I am a newbie trying to search in an internal table. I tried the following, but I am getting an error message saying that it expected type "string" for the internal table:
DATA:
BEGIN OF WA_TAB1,
WA_COLUMN1 TYPE TAB2-COLUMN1,
WA_COLUMN2 TYPE TAB2-COLUMN2,
END OF WA_TAB1,
TBL_TAB1 LIKE TABLE OF WA_TAB1
WITH KEY WA_COLUMN1,
TBL_TAB1_RESULT TYPE MATCH_RESULT_TAB.
FIND ALL OCCURRENCES OF 'ABC'
IN TABLE TBL_TAB1
RESULTS TBL_TAB1_RESULT.
How can I do a search like this within an internal table (like SELECT in SQL)? I expect to get several rows back and I need the content of all columns for these rows.
Thanks for your help,
D.
2007 Aug 15 8:17 PM
For picking Single record from internal table use READ TABLE ITAB index..
for multiple rows
LOOP at itab.
write the logic.
Endloop.
-Kriss
2007 Aug 15 8:20 PM
This sounds very inefficient for me. Is there no "Select" or "Find" statement I could use?
2007 Aug 15 8:24 PM
HI,
No Find will work with internal table of type string.. how ever you can loop and find.
loop at itab.
if itab-firstfield cp 'ABC' or itab-secondfiled cp 'ABC'.
resulttab = itab.
append resulttab.
endif.
endloop.
Thanks
Mahesh
2007 Aug 15 8:18 PM
HI,
your intrnal table should be of type string.. check this example
DATA: itab TYPE TABLE OF string,
results TYPE match_result_tab.
...
FIND ALL OCCURRENCES OF REGEX '\b(Huey|Dewey|Louie)\b'
IN TABLE itab
RESPECTING CASE
RESULTS results.
Thanks
MaHESH
2007 Aug 15 8:22 PM
Mahesh,
I do not quite understand why I should have a table of type string (I saw that in the SAP help). The internal table I would like to search has a different structure with several columns of different types.
Does this mean I cannot use the "Find" statement?
2007 Aug 15 8:22 PM
Hello
write something like:
option 1
read table TBL_TAB1 into wa_bla with table key wa_column = 'criteria'.
option 2
loop at TBL_TAB1.
code....
endloop.
Hope this helps
Gabriel
2007 Aug 15 8:23 PM
I guess I can use option 1 only if I expect no more than 1 result row, correct?
2007 Aug 15 8:24 PM
It appears that the system rather have the fields of the internal table as character type as opposed to string typed. This seems to work for me.
REPORT zrich_0002.
TYPES: BEGIN OF tab2,
column1(20) TYPE c,
column2(20) TYPE c,
END OF tab2.
DATA: BEGIN OF wa_tab1,
wa_column1 TYPE tab2-column1,
wa_column2 TYPE tab2-column2,
END OF wa_tab1,
tbl_tab1 LIKE TABLE OF wa_tab1
WITH KEY wa_column1,
tbl_tab1_result TYPE match_result_tab,
wa_tab1_result LIKE LINE OF tbl_tab1_result.
wa_tab1-wa_column1 = 'Column 1'.
wa_tab1-wa_column2 = 'Column 2'.
APPEND wa_tab1 TO tbl_tab1.
wa_tab1-wa_column1 = 'This is ABC in this column'.
wa_tab1-wa_column2 = 'Column 2'.
APPEND wa_tab1 TO tbl_tab1.
wa_tab1-wa_column1 = 'Column 1'.
wa_tab1-wa_column2 = 'Column 2'.
APPEND wa_tab1 TO tbl_tab1.
wa_tab1-wa_column1 = 'Column 1'.
wa_tab1-wa_column2 = 'This is ABC in this column'.
APPEND wa_tab1 TO tbl_tab1.
FIND ALL OCCURRENCES OF 'ABC' IN TABLE tbl_tab1
RESULTS tbl_tab1_result IN CHARACTER MODE.
LOOP AT tbl_tab1_result INTO wa_tab1_result.
READ TABLE tbl_tab1 INTO wa_tab1 INDEX wa_tab1_result-line.
IF sy-subrc = 0.
WRITE:/ 'Line:', wa_tab1_result-line, 'Offset:', wa_tab1_result-offset.
WRITE: 'Value is:', wa_tab1+wa_tab1_result-offset(3).
ENDIF.
ENDLOOP.
Regards,
Rich Heilman
Message was edited by:
Rich Heilman
2007 Aug 15 8:31 PM
Rich,
I think "FIND ALL OCCURRENCES" will not support.i checked the syntax for FIND
"FIND p IN [SECTION OFFSET off LENGTH len OF] text"
aRs
2007 Aug 15 8:33 PM
FIND ALL OCCURRENCES is new in BI 7.0. I am testing Rich's solution right now.
Thanks,
D.
2007 Aug 15 8:36 PM