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

Problem while reading the data from Selection Screen

Former Member
0 Likes
1,251

Hi,

Thank You very much for reading this query.

I have designed a selection Screen which contains 2 fields.

First field is field in which user has to give table name.

second field is a field in which user has to give field name from that data base table.

I need to write a logic that I should delete the data from given data base table where given field = to-day'date.

My selection-Screen code i s

p_table TYPE rsdodso-odsobject OBLIGATORY,

p_field(20) OBLIGATORY,

I have written query like this.

delete from table (p_table) where (p_field) = sy-datum which is giving error message saying that (p_field) doesnot exist.

Can any one advise me on this how to go.

Thank and Regards,

K.krishna.

11 REPLIES 11
Read only

Former Member
0 Likes
1,209

erm, not that i dont want to help you, but you know that this is higly risky what you are trying to do?

giving someone a possibility to delete database records of certain tables isnt good.

People can then delete MARA records while leaving MARC recods in system etc. tell your consultant that this task is a NO-GO.

Read only

0 Likes
1,209

Hi,

This option is only for Z tables.So its not a ploblem.

Edited by: KRISHNA CHAITANYA on Sep 7, 2010 2:58 PM

Read only

0 Likes
1,209

I am not sure you can delete the entries or not. Please find below sample code.


Data : v1 type string,
       v2 type string.

     v1 = p_table.
  concatenate p_field ' = ' sy-datum into v2 SEPARATED BY space.
  delete from (v1) where (v2).

Read only

0 Likes
1,209

>

> Hi,

>

> This option is only for Z tables.So its not a ploblem.

>

> Edited by: KRISHNA CHAITANYA on Sep 7, 2010 2:58 PM

And who's to say that a user will only use a Z-table? Already i'm imagining the next thread 'A user deleted some records from standard SAP table.. how do i get the records back?'.

Read only

Former Member
0 Likes
1,209

Hi,

We can't have a dynamic condition in where condition for delete table. you can find the same in SCN.

Hope it helps.

Sujay

Read only

Former Member
0 Likes
1,209

Hi try this way...


 START-of-selection.
    tables : dd03l.
data : w_char(30). 
PARAMETERS : p_table TYPE dd02l-tabname OBLIGATORY,
                     p_field  TYPE dd03l-fieldname OBLIGATORY.

at selection-screen.
    select single * from dd03l where TABNAME = p_table
                                              and fieldname      = p_field
                                              and datatype       = 'DATS'.
   If sy-subrc ne 0.
        "combination is not valid.
   ENDIF.
START-OF-SELECTION.
CONCATENATE p_field 'eq' sy-datum INTO w_char SEPARATED BY space.
  DELETE FROM (p_table) WHERE (w_char).

Prabhudas

Read only

0 Likes
1,209

Hi,

Thank You very much.

I did same thing but it is deleting all the records....

Edited by: KRISHNA CHAITANYA on Sep 7, 2010 5:58 PM

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,209

Hello Prabhu,

When using Open SQL statements involving dynamic token make sure to keep it in a TRY ... CATCH block.

DATA: lcx_sql_error TYPE REF TO cx_sy_dynamic_osql_semantics,
      v_msg TYPE string.

TRY .
    DELETE FROM (p_table) WHERE (w_char).
  CATCH cx_sy_dynamic_osql_semantics INTO lcx_sql_error.
    v_msg = lcx_sql_error->get_text( ).
ENDTRY.

BR,

Suhas

PS: No need to check against the table DD03L to check if the field is in the table or rather

Read only

0 Likes
1,209

>

> I did same thing but it is deleting all the records....

You're playing with fire. I'd stop right now.

Rob

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,209

+ 1

Read only

0 Likes
1,209

oh if it was just fire ).

Playing with fire you may get hurt/burned. But playing with a customers SAP system, may get you to a situation where you rather would had gotten burnt