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

Deleting multiple values from an internal table

Former Member
0 Likes
14,921

I'm fairly new to ABAP and i'm trying to delete entries from the internal table that don't contain certain value/s.

Below is a code that worked for me:

LOOP AT BASIS.

  IF pa_WKZS = 'X' AND BASIS-ARBPL NE '2056'

    DELETE BASIS.

  ENDIF.

ENDLOOP.

If pa_WKZS is checked at selection I want it to only show ARBPL with value = 2056.

but how would I do the same for another checkbox that should only show 2301 2302 2303 for example. tried with strings but didn't have any luck. or am i approaching this from the wrong angle?

any help is appreciated!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
6,887

Try below logic.

data: table1 type standard table of basis,

        table2 type standard table of basis,

        table3 type standard table of basis,

        table4 type standard table of basis.

table1 = BASIS.

table2 = BASIS.

table3 = BASIS.

table4 = BASIS.

refresh basis.

if cb1 = 'X'.

DELETE table1 where ARBPL NE '2056'.

endif.

if cb2 = 'X'.

DELETE table2 where ARBPL NE '2031'.

endif.

if cb3 = 'X'.

DELETE table3 where ARBPL NE '2032'.

endif.

if cb4 = 'X'.

DELETE table4 where ARBPL NE '2033'.

endif.

append lines of table1 to basis.

append lines of table2 to basis.

append lines of table3 to basis.

append lines of table4 to basis.

I'm fairly new to ABAP and i'm trying to delete entries from the internal table that don't contain certain value/s.

Below is a code that worked for me:

LOOP AT BASIS.

  IF pa_WKZS = 'X' AND BASIS-ARBPL NE '2056'

    DELETE BASIS.

  ENDIF.

ENDLOOP.

If pa_WKZS is checked at selection I want it to only show ARBPL with value = 2056.

but how would I do the same for another checkbox that should only show 2301 2302 2303 for example. tried with strings but didn't have any luck. or am i approaching this from the wrong angle?

any help is appreciated!

12 REPLIES 12
Read only

Former Member
0 Likes
6,887

Hey,

Your question is not too clear. Please explain in detail about 'another checkbox functionality'.

what i understood from your problem is that you want to restrict data on the basis of  pa_WKZS and BASIS-ARBPL

for selection screen field, you can restrict the values by

AT SELECTION-SCREEN ON  pa_WKZS .

** Here write a perform to restrict the values.

Or you can do the direct deletion by

IF pa_WKZS = 'X'.

DELETE BASIS where BASIS-ARBPL NE '2056'.

ENDIF.

(though NE should not be used for comparision, as it affects the performance)

Read only

koolspy_ultimate
Active Contributor
0 Likes
6,887

Hi Aaron Karger,

Just try this instead of your code.

  IF pa_wkzs = 'X' .

    delete basis where ARBPL <> '2056' .

endif.

regards,

Madhumahesh.

Read only

Former Member
0 Likes
6,887

if pa_wkzs = 'X'.

DELETE BASIS where ARBPL NE '2056'.

endif.

Read only

former_member209120
Active Contributor
0 Likes
6,887

Hi,

Try like this

LOOP AT BASIS.

  IF pa_WKZS = 'X' .    

    DELETE BASIS WHERE BASIS-ARBPL NE '2056'.

  ENDIF.

  IF pa_WKZS_2 = 'X' .    

    DELETE BASIS WHERE BASIS-ARBPL NE '2301'

                             AND      BASIS-ARBPL NE '2302'

                             AND      BASIS-ARBPL NE '2303'.

  ENDIF.

ENDLOOP.



Read only

Former Member
0 Likes
6,887
thanks for the replies,
well the code i posted worked fine and does what i need it to, but how would i do the same for:
IF pa_GRAF = 'X' AND BASIS-ARBPL NE    2301 2302 2303  (more than one value)
    DELETE BASIS.
  ENDIF.
Read only

Former Member
0 Likes
6,887

HI Aaron,

do the following code,

if pa_wkzs = 'X

  if pa_wkzs2 = 'X'

  get data from basis where arbpl in r_arbpl. (define ranges for arbpl values.)

  else.

  get data from basis relating to first checkbox.

else.

  get data from basis relating to second checkbox.

endif.'

Read only

Former Member
0 Likes
6,887

Hi Aaron

Try the below code...

if pa_wkzs = 'X'.

Delete Basis where ARBPL NE '2056.

Elseif  .... = 'X'.

Delete Basis where ARBPL NE '2301'.

Delete Basis where ARBPL NE '2302'.

Delete Basis where ARBPL NE '2303'.

endif.

Regards,

Suganya

Read only

Former Member
0 Likes
6,887

Hi,

I think you have multiple check boxes on selection screen.

Say you have

checkbox1 2056

checkbox2 2301

checkbox3 2302

checkbox4 2303

create one RANGE say r_number using RANGES keyword

you have to take AT SELECTION SCREEN Event..in this

if checkbox1 EQ 'X'

  r_number-low = '2056'.

  r_number-sign = 'I'.

  r_number-option = 'EQ'.

   append r_number.

ENDIF.

if checkbox2 EQ 'X'

  r_number-low = '2301'.

  r_number-sign = 'I'.

  r_number-option = 'EQ'.

  append r_number.

ENDIF.

and so on for other check boxes..

Now in the logic for deleting entries from table BASIS.. do as following..

your table must be containing all records with field ARBPL

so write

DELETE BASIS where ARBPL NOT IN r_number.

please try this..

Regards

Tejas

Message was edited by: tejas patil

Read only

Former Member
0 Likes
6,887

If you use multiple checkbox I think you can use case statement.

example, if you used for pa_wkzs for arbpl 2056, pa_wkzs1 for arbpl 2301, pa_wkzs2 for arbpl 2302

CASE 'X'.

WHEN PA_WKZS.

DELETE BASIS WHERE ARBPL NE '2056'.

WHEN PA_WKZS1.

DELETE BASIS WHERE ARBPL NE '2301'.

WHEN PA_WKZS2.

DELETE BASIS WHERE ARBPL NE '2302'.

ENDCASE.

Regards,

Ikrar

Read only

Former Member
0 Likes
6,888

Try below logic.

data: table1 type standard table of basis,

        table2 type standard table of basis,

        table3 type standard table of basis,

        table4 type standard table of basis.

table1 = BASIS.

table2 = BASIS.

table3 = BASIS.

table4 = BASIS.

refresh basis.

if cb1 = 'X'.

DELETE table1 where ARBPL NE '2056'.

endif.

if cb2 = 'X'.

DELETE table2 where ARBPL NE '2031'.

endif.

if cb3 = 'X'.

DELETE table3 where ARBPL NE '2032'.

endif.

if cb4 = 'X'.

DELETE table4 where ARBPL NE '2033'.

endif.

append lines of table1 to basis.

append lines of table2 to basis.

append lines of table3 to basis.

append lines of table4 to basis.

Read only

Former Member
0 Likes
6,887

Hi Aaron,

Seems you need two level filtering.

Try this,

data :  lt_tab1 "Internal table of type of structure of Basis Table       

           ls_basis " Work area of type of structure of Basis Table

If pa_1 = 'X'.

read table basis into ls_basis with key arbpl = '2056' "arbpl may need leading zeroes just check

if sy-subrc eq 0.

append ls_basis to lt_tab1.

endif.

elseif pa_2 = 'X'.

read table basis into ls_basis with key arbpl = '<Value 2>' "arbpl may need leading zeroes just check

if sy-subrc eq 0.

append ls_basis to lt_tab1.

endif.

elseif......

endif.

BR,

Ankit.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
6,887

Are you speaking of checkboxes or of a radiobutton group, in second case the code could look like

CASE abap_true.
   WHEN p_option1.
     DELETE itab WHERE field NE value1.
   WHEN p_option2.
     DELETE itab WHERE field NE value2.
   WHEN p_option3.
     DELETE itab WHERE field NE value3.
   WHEN OTHERS.
     " etc.
ENDCASE.

With independant checkboxes, a delete where statement should not be adequate, try a loop like

LOOP AT itab ASSIGNING <fs>.
   CHECK NOT ( p_option1 EQ abap_true AND <fs>-field EQ value1 ). " valid ercord, next
   CHECK NOT ( p_option2 EQ abap_true AND <fs>-field EQ value2 ).
   CHECK NOT ( p_option3 EQ abap_true AND <fs>-field EQ value3 ).
   DELETE itab." invalide record, delete
ENDLOOP.

Regards,

Raymond