Application Development 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: 

Delete pattern in range from internal table

suth
Newcomer
0 Kudos
996

Dear Experts,

If I get a pattern from selection screen as a range, how can I use the range to remove lines with patterns in range from internal table?

For example:

I have r_dummy as a range

r_dummy-low = Dummy


Recorded data in the field in the internal table be like: [ Dummy_aaaaaa, Dummy_123, name2, name2]

how to remove the line?

I tried add * to r_dummy-low
then try like below but it doesn’t work:

DELETE lt_data WHARE field NP r_dummy-low.

And I try use it as a part of selection statement like :

SELECT *
FROM table

INTO TABLE lt_data

WHERE field NOT IN r_dummy

it doesn’t work either.

I need a clue.

Best Regards,

6 REPLIES 6

Sandra_Rossi
Active Contributor
0 Kudos
859

Please use the CODE formatting button. The question would be much more legible:

Dear Experts,

If I get a pattern from selection screen as a range, how can I use the range to remove lines with patterns in range from internal table?

For example:

I have r_dummy as a range

r_dummy-low = Dummy


Recorded data in the field in the internal table be like: [ Dummy_aaaaaa, Dummy_123, name2, name2]

how to remove the line?

I tried add * to r_dummy-low
then try like below but it doesn’t work:

DELETE lt_data WHARE field NP r_dummy-low.

And I try use it as a part of selection statement like :

SELECT *
FROM table
INTO TABLE lt_data
WHERE field NOT IN r_dummy

it doesn’t work either.

I need a clue.

Best Regards,

Sandra_Rossi
Active Contributor
0 Kudos
859

I don't understand your question at all. Why "dummy"? Why do you need to transform your selection screen criteria into something else before using it in SELECT?

Tomas_Buryanek
Active Contributor
0 Kudos
859

Hello,

range table (or SELECT-OPTION, which is also range table) has four fields:

  • SIGN
  • OPTION
  • LOW
  • HIGH

If you want to use pattern correctly, then OPTION field needs to have value (operator) "CP" or "NP". These two are explained here: https://help.sap.com/doc/abapdocu_731_index_htm/7.31/en-US/abenlogexp_strings.htm

In your example r_dummy table should have:

  • SIGN = I
  • OPTION = CP
  • LOW = Dummy* (Asterisk character is important here!)

If it is SELECT-OPTION, then user can enter "Dummy*" and this entry will automatically be with OPTION = CP.

-- Tomas --

fprokopiuk
Active Participant
0 Kudos
859

First prepare your range accordingly to your requirement, so if you want to have Dummy* filtered it should be

r_dummy-sign = `I`. "Include
r_dummy-option = `CP`. "Contains pattern
r_dummy-low = `Dummy*`.
APPEND r_dummy TO rt_dummy.

And then you can either use FILTER statement for it:

DATA(filtered_data) = FILTER #( lt_data WHERE field IN rt_dummy ).

Or you can delete unwanted entries from the internal table instead.

DELETE lt_data WHERE field NOT IN rt_dummy.

Sandra_Rossi
Active Contributor
859

It seems that your question is clear for other people, if I merge their interpretations and what I partly understand from your question, I would opt for a third "answer" which might correspond to what you're looking for:

DATA(r_range_without_dummy) = r_range.

r_range_without_dummy = VALUE #(
    ( LINES OF r_range_without_dummy )
    ( sign   = 'E' 
      option = 'CP'              " CP is case-insensitive
      low    = 'dummy*' ) ).

SELECT *
FROM table
INTO TABLE lt_data
WHERE field IN r_range_without_dummy.

Sandra_Rossi
Active Contributor
0 Kudos
859

'E' being Exclude.