‎2014 Mar 13 7:21 AM
Dear All,
I have a requirement in which i need to delete all the transaction data from a particular client.
I need to give table as input field.
The data from the entered table should then be cleared.
Could you suggest as to how do i make my select query dynamic such that it will accept the table name which is input & then delete all the entries from that table.
Regards,
RK
‎2014 Mar 13 9:02 AM
Hi Ronak,
ur scenario can be achieved with help of field symbols.
Below program is to display any table data given on selection screen.
similarly instead of select write as delete statement.
*"Type-pool............................................................
TYPE-POOLS : slis.
*"Parameters elements..................................................
PARAMETERS : p_table TYPE tabname OBLIGATORY.
*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables *
*"--------------------------------------------------------------------*
DATA:
w_dref TYPE REF TO data, " w_dref reference variable
t_line TYPE c LENGTH 20. " w_line to hold a line
*"--------------------------------------------------------------------*
* Internal table to hold field catalog structure *
*"--------------------------------------------------------------------*
DATA :
t_fcat TYPE slis_t_fieldcat_alv.
FIELD-SYMBOLS: <t_itab> TYPE STANDARD TABLE .
*"--------------------------------------------------------------------*
* START-OF-SELECTION EVENT *
*"--------------------------------------------------------------------*
START-OF-SELECTION.
SELECT SINGLE
tabname " Table Name
FROM dd02l
INTO t_line
WHERE tabname EQ p_table
AND as4vers EQ ' '
AND as4local EQ 'A'
AND tabclass NE 'INTTAB'
AND tabclass NE 'APPEND'.
IF sy-subrc EQ 0.
CREATE DATA w_dref TYPE STANDARD TABLE OF (p_table).
ASSIGN w_dref->* TO <t_itab>.
IF sy-subrc EQ 0.
SELECT * " All Fields
FROM (p_table)
INTO TABLE <t_itab>." package size 100.
IF sy-subrc EQ 0.
PERFORM fill_catalog.
PERFORM display.
ELSE.
MESSAGE text-002 TYPE 'S'.
EXIT.
ENDIF. " IF sy-subrc EQ 0...
ELSE.
MESSAGE text-003 TYPE 'S'.
EXIT.
ENDIF.
ELSE.
MESSAGE text-003 TYPE 'S'.
EXIT.
ENDIF. " IF sy-subrc EQ 0...
*&---------------------------------------------------------------------*
*& Form DISPLAY *
*&---------------------------------------------------------------------*
* This subroutine displays the data *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*----------------------------------------------------------------------*
FORM display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = t_fcat
TABLES
t_outtab = <t_itab>
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno DISPLAY LIKE 'E'
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF. " IF sy-subrc <> 0...
*&---------------------------------------------------------------------*
*& Form FILL_CATALOG *
*&---------------------------------------------------------------------*
* This subroutine fills the field catalog *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*----------------------------------------------------------------------*
FORM fill_catalog .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_structure_name = p_table
CHANGING
ct_fieldcat = t_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno DISPLAY LIKE 'E'
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF. " IF sy-subrc <> 0...
‎2014 Mar 13 8:29 AM
dyd you search for dynamic select statements first before posting?
‎2014 Mar 13 9:02 AM
Hi Ronak,
ur scenario can be achieved with help of field symbols.
Below program is to display any table data given on selection screen.
similarly instead of select write as delete statement.
*"Type-pool............................................................
TYPE-POOLS : slis.
*"Parameters elements..................................................
PARAMETERS : p_table TYPE tabname OBLIGATORY.
*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables *
*"--------------------------------------------------------------------*
DATA:
w_dref TYPE REF TO data, " w_dref reference variable
t_line TYPE c LENGTH 20. " w_line to hold a line
*"--------------------------------------------------------------------*
* Internal table to hold field catalog structure *
*"--------------------------------------------------------------------*
DATA :
t_fcat TYPE slis_t_fieldcat_alv.
FIELD-SYMBOLS: <t_itab> TYPE STANDARD TABLE .
*"--------------------------------------------------------------------*
* START-OF-SELECTION EVENT *
*"--------------------------------------------------------------------*
START-OF-SELECTION.
SELECT SINGLE
tabname " Table Name
FROM dd02l
INTO t_line
WHERE tabname EQ p_table
AND as4vers EQ ' '
AND as4local EQ 'A'
AND tabclass NE 'INTTAB'
AND tabclass NE 'APPEND'.
IF sy-subrc EQ 0.
CREATE DATA w_dref TYPE STANDARD TABLE OF (p_table).
ASSIGN w_dref->* TO <t_itab>.
IF sy-subrc EQ 0.
SELECT * " All Fields
FROM (p_table)
INTO TABLE <t_itab>." package size 100.
IF sy-subrc EQ 0.
PERFORM fill_catalog.
PERFORM display.
ELSE.
MESSAGE text-002 TYPE 'S'.
EXIT.
ENDIF. " IF sy-subrc EQ 0...
ELSE.
MESSAGE text-003 TYPE 'S'.
EXIT.
ENDIF.
ELSE.
MESSAGE text-003 TYPE 'S'.
EXIT.
ENDIF. " IF sy-subrc EQ 0...
*&---------------------------------------------------------------------*
*& Form DISPLAY *
*&---------------------------------------------------------------------*
* This subroutine displays the data *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*----------------------------------------------------------------------*
FORM display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = t_fcat
TABLES
t_outtab = <t_itab>
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno DISPLAY LIKE 'E'
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF. " IF sy-subrc <> 0...
*&---------------------------------------------------------------------*
*& Form FILL_CATALOG *
*&---------------------------------------------------------------------*
* This subroutine fills the field catalog *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*----------------------------------------------------------------------*
FORM fill_catalog .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_structure_name = p_table
CHANGING
ct_fieldcat = t_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno DISPLAY LIKE 'E'
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF. " IF sy-subrc <> 0...
‎2014 Mar 13 10:23 AM
@ All Many thanks for your inputs.
@ Vineesh your solution worked...