2010 Sep 07 10:05 AM
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.
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
2010 Sep 07 10:11 AM
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.
2010 Sep 07 10:28 AM
Hi,
This option is only for Z tables.So its not a ploblem.
Edited by: KRISHNA CHAITANYA on Sep 7, 2010 2:58 PM
2010 Sep 07 11:33 AM
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).
2010 Sep 07 11:40 AM
>
> 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?'.
2010 Sep 07 11:35 AM
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
2010 Sep 07 12:02 PM
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
2010 Sep 07 1:20 PM
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
2010 Sep 07 1:45 PM
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
2010 Sep 07 2:23 PM
>
> I did same thing but it is deleting all the records....
You're playing with fire. I'd stop right now.
Rob
2010 Sep 07 2:25 PM
2010 Sep 07 2:27 PM
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
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |