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: 

Dynamic where clause in deleting table entries

Former Member
0 Kudos

Hello all i want to delete rows of Itab from a dynamic table based upon dynamic field and dynamic values. i hope you got it.

eg. i am using some field symbol to assign value for field name dynamically and field value dynamically. i want to use them to delete data fro dynamic table based upon where condition

my read feature is working fine to read data from dynamic table based upon dynamic field name and dynamic value.

ASSIGN component 'FROM_F' OF STRUCTURE <wa_ITAB2> TO <dyn_FIELD>.

ASSIGN component <wa_it1>-to_f of structure <WA_itab1> to <DYN_FIELDVALUE>.

READ table <dyn_tab1> ASSIGNING <dyn_watab1> WITH KEY (<DYN_Fieldname>) = <DYN_FIELDvalue> BINARY SEARCH.

ITS WORKING FINE.

i want to use something like this to delete table's data

data: v_strng(200) type c,

it_where like table of v_strng.

concatenate '<DYN_Field>' 'NE' '<DYN_FIELDvalue>' into v_strng.

append v_strng to it_where .

Delete <dyn_itab5> where (it_where) .

i tried this way also

Delete <dyn_itab5> where <DYN_Field> <> <DYN_FIELDvalue>.

is is possible either way?

i hope i cleared my intention.

Mani

1 ACCEPTED SOLUTION

Former Member
0 Kudos

According to the help, you can use the same sort of dynamic WHERE conditions for DELETE that you can use for SELECT.

Rob

11 REPLIES 11

Former Member
0 Kudos

According to the help, you can use the same sort of dynamic WHERE conditions for DELETE that you can use for SELECT.

Rob

0 Kudos

Well simple where clause will work i guess using direct field names (but not sure) but the problem is i dont know even field name untill runtime along with field value to compare. As per F1 help i didn't find if the specify we can use field symbol in where clause identification field.

So i didn't find answer yet.

Chordia

i allready tried that option but not working

Delete <dyn_itab5> where (<DYN_Fieldname>) NE <DYN_FIELDvalue>

any reply will be appreciated

Mani

0 Kudos

Mani - you can ignore my response. I didn't pick up on the fact that these are internal rather than database tables.

Rob

0 Kudos

Hi Mani,

I have written a sample code with an example of scarr.

Please try to debug and check the values of fiel-symbols at runtime so that you understand better what is happening at the background...

TABLES :
scarr.

DATA : t_itab TYPE TABLE OF scarr.
DATA : carrid TYPE s_carr_id.
DATA string TYPE string.

FIELD-SYMBOLS : <dyn_itab> TYPE INDEX TABLE.
FIELD-SYMBOLS : <dyn_field> TYPE ANY, <dyn_fieldvalue> TYPE ANY, <dyn_wa> TYPE ANY,
<dyn_waname> TYPE ANY.

SELECT * FROM scarr INTO TABLE t_itab.

LOOP AT t_itab INTO scarr.
  WRITE : / scarr.
ENDLOOP.
SKIP.
WRITE : '*******************'.
SKIP.
carrid = 'AA'.
ASSIGN 'scarr' TO <dyn_waname>.
ASSIGN scarr TO <dyn_wa>.
ASSIGN 'carrid' TO <dyn_field>.
ASSIGN carrid TO <dyn_fieldvalue>.
ASSIGN t_itab TO <dyn_itab>.
CONCATENATE <dyn_waname> '-' <dyn_field> INTO string.
UNASSIGN <dyn_waname>.
ASSIGN (string) TO <dyn_waname>.

LOOP AT <dyn_itab> INTO <dyn_wa> . 
  IF <dyn_waname> EQ <dyn_fieldvalue>.
    DELETE <dyn_itab>.
  ENDIF.
ENDLOOP.

LOOP AT t_itab INTO scarr.
  WRITE : / scarr.
ENDLOOP.

Hope this tells you what you have to write in your code

Regards,

Siddarth

0 Kudos

Well this could be alternative solution but i am trying to reduce number of loops not to increase number of loops .

I appreciate your reply but i can't afford it in my situation. I actually want to reduce number of entry and in turn number of loops and as a bi product to reduce used memory during runtime.

I am still waiting for concrete reply if its possible through DELETE statment.

Mani

Former Member
0 Kudos

Hi,

Try using this..

Delete <dyn_itab5> where (<DYN_Fieldname>) NE <DYN_FIELDvalue>

Former Member
0 Kudos

Hi,

Try this one,

FIELD-SYMBOLS: 
      <l_line>  TYPE ANY,
      <l_field> TYPE ANY.

DATA: new_line  TYPE REF TO data.
...
CREATE DATA new_line LIKE LINE OF <outtab>.
ASSIGN new_line->* TO <l_line> .

...
LOOP AT <dyn_itab> ASSIGNING <l_line>.
  ASSIGN COMPONENT dynamic_field OF STRUCTURE <l_line> TO <l_field>.
  IF <l_field> EQ (condition you give in where.
    DELETE TABLE <dyn_itab> FROM <l_line> .
  ENDIF.
ENDLOOP.

Let me know if it works.

Regards,

Manoj Kumar P

0 Kudos

well i dont want to "LOOP" and then delete.

Cause the whole purpose is to reduce number of entry in dynamic ITAB and eventually number of loop and memory used during runtime.

Mani

0 Kudos

Hi,

Then in this case I don't think its possible to do it without loop, if you want to do it,

then you can use if conditions in this way....

for example table used are SCARR, SFLIGHT.

if <dyn_itab> = 'SCARR'.
 delete scarr where carrid = <dyn_fieldvalue>.
elseif <dyn_itab> = 'SFLIGHT'.
 delete sflight where carrid = <dyn_fieldvalue>.
endif.

in this way you can reduce loop.

Regards,

Siddarth

0 Kudos

WELL I THINK I NEED TO DO IT ALTERNATIVE WAY THANKS FOR YOUR ANSWERS ANYWAY.

Mani

Former Member
0 Kudos

alternative ways.