2014 Jun 24 10:56 AM
Hi
I have an internal table of the type STRING which may contain thousands of records and I am trying to get to lines which starts with a set of characters. There may be a few lines starting with that sequence and it is possible to do what I have shown below, however, is there a more efficient way to do this?
Ideally what I would like to do is to find the lines or the index (SY-TABIX) using LOOP AT.......WHERE....My current way of doing it is not the best. Any ideas?
DATA t_spooltext TYPE TABLE OF string. "contains thousands of lines
DATA l_text(200) TYPE c.
DATA l_index TYPE i.
LOOP AT t_spooltext INTO DATA(l_current_line).
CONDENSE l_current_line.
l_text = l_current_line.
IF l_text+0(5) EQ 'H046A'.
l_index = sy-tabix.
ELSE
CONTINUE.
ENDIF.
-----------------
-----------------
-----------------
ENDLOOP.
2014 Jun 24 11:25 AM
Hi Archana,
Use this:-
FIND ALL OCCURRENCES OF 'H046A'
in TABLE t_spooltext
in CHARACTER MODE
RESULTS DATA(results_tab).
The results table will contain all the indexes where the search string is found with offset.
Check in debugging you will find out...
Thanks,
Sharath
2014 Jun 24 11:25 AM
Hi Archana,
Use this:-
FIND ALL OCCURRENCES OF 'H046A'
in TABLE t_spooltext
in CHARACTER MODE
RESULTS DATA(results_tab).
The results table will contain all the indexes where the search string is found with offset.
Check in debugging you will find out...
Thanks,
Sharath
2014 Jun 24 4:54 PM
Sharath,
Fixing what you posted, I add the sample code below:
REPORT z_test.
DATA: t_spooltext TYPE TABLE OF string,
results_tab TYPE TABLE OF match_result.
DO 10 TIMES.
APPEND 'H046A' TO t_spooltext.
ENDDO.
DO 3 TIMES.
APPEND 'H046B' TO t_spooltext.
ENDDO.
FIND ALL OCCURRENCES OF 'H046A'
IN TABLE t_spooltext
IN CHARACTER MODE
RESULTS results_tab.
BREAK-POINT.
Archana, in my point of view the user Sharath are correctly, only thing you have to watch is the form that is set to result table, as I showed above
2014 Jun 24 11:26 AM
This should have better performance than loop:
FIND ALL OCCURRENCES OF REGEX .. IN TABLE .. RESULTS ...
But not sure how big performance difference you will get for your number of values.
2014 Jun 24 4:04 PM
Keeping the LOOP, at first glance I would suggest to use a field symbol rather than a workarea.
LOOP AT t_spooltext ASSIGNING <fs_text>
With this, you avoid to copy each internal table register to memory.
Also, maybe you can put filtering in the LOOP sentence to avoid to enter in every table record, so you have to think if you can have already condensed the values to apply filtering.
LOOP AT t_spooltext ASSIGNING <fs_text> WHERE table_line IN 'H046A*'
Also, you can sort the internal table before the loop so you can determine the ranges to process (previous READ TABLE with BINARY SEARCH option), avoiding to process the LOOP from first record to last.
2014 Jun 25 11:39 AM
If you just want all lines that starts in H046A, then use the following code.
DATA t_spooltext TYPE STANDARD TABLE OF SRTIF_MESSAGE.
DELETE t_spooltext WHERE mess NP 'H046A*'.
2014 Jun 25 5:56 PM
What is the significance of CONDENSE statement in your code? If it's actually needed, i.e. if the data is stored like 'H 0 4...', not 'H04...' (or both are possible) then it would limit your options to pretty much what you already have. It looks like the solution depends on what data exactly is in that string.
Also is there any chance not to have thousands of records in a table to begin with?