Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP efficiency question

Former Member
0 Likes
1,021


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.

1 ACCEPTED SOLUTION
Read only

SharathYaralkattimath
Contributor
0 Likes
986

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

6 REPLIES 6
Read only

SharathYaralkattimath
Contributor
0 Likes
987

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

Read only

0 Likes
986

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

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
986

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.

-- Tomas --
Read only

former_member191569
Active Participant
0 Likes
986

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.

Read only

former_member730258
Participant
986

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*'.

Read only

Jelena_Perfiljeva
Active Contributor
986

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?