cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete record from Database table while validating internal table.

Former Member
0 Kudos
1,946

Hi,

In final internal table I have 5 fields including one Checkbox field.

when I executed this report I will get all this 5 fields.

***

Now when I checked any record there in output screen, I have one pushbutton also. After selecting the records with checkbox when i clicked that pushbutton what ever the records are selected they should be deleted from Data base table where this records are fetched.

***

how....

Thanking you,

Deepak.

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Deepak,

Here is the sample code.

DATA : BEGIN OF itab OCCURS 0,

checkbox(1) TYPE c,

matnr LIKE mara-matnr,

werks LIKE marc-werks,

END OF itab.

DATA : wa LIKE itab.

DATA : it_delete LIKE itab OCCURS 0 WITH HEADER LINE.

itab-matnr = 'M1'. itab-werks = 'W1'. APPEND itab.

itab-matnr = 'M4'. itab-werks = 'W4'. APPEND itab.

itab-matnr = 'M3'. itab-werks = 'W3'. APPEND itab.

itab-matnr = 'M2'. itab-werks = 'W2'. APPEND itab.

LOOP AT itab.

WRITE:/ itab-checkbox AS CHECKBOX, itab-matnr, itab-werks.

ENDLOOP.

AT USER-COMMAND.

CHECK SY-UCOMM EQ 'DELE'.

DO.

READ LINE sy-index LINE VALUE INTO wa.

IF sy-subrc EQ 0.

*--> Collect the selected Records

IF wa-checkbox EQ 'X'.

APPEND wa TO it_delete.

ENDIF.

ELSE.

EXIT.

ENDIF.

ENDDO.

*--> delete the selected records from the databse.

*--> Mass deletion will improve the performance

DELETE MyZTable FROM TABLE it_delete.

Best Regards,

Vijaya Sai M

Former Member
0 Kudos

Hi,

Using the above methods as Judith has given,

you can also proceed this way:

MODULE user_command_9001 INPUT.

  CASE sy-ucomm.
    WHEN 'BUT'.              " your button name
       LOOP AT i_output INTO w_output 
                        WHERE select_flag = c_x.
            DELETE i_output from w_output
            Clear w_output.
       ENDLOOP.
  ENDCASE.

Regards,

Anjali.

Former Member
0 Kudos

Hi,

Here is some logic to delete the check box selected records from the database.

(1) Get the selected records into one internal table

do.

read line sy-index line value into wa.

if sy-subrc eq 0.

if wa-checkbox eq 'X'.

append wa to it_delete.

endif.

else.

exit.

endif.

enddo.

(2) Delete the selected records from the Database table

DELETE dbtabname) FROM TABLE it_delete.

Hope this hint would help you.

Best Regards,

Vijay

Vinod_Chandran
Active Contributor
0 Kudos

Hi,

If your internal table contains key fields from the database table, then use the following command.

DELETE dbtab FROM TABLE itab.

If not, then

LOOP AT ITAB.

DELETE FROM dbtab WHERE fld1 = itab-fld1.

ENDLOOP.

Thanks

Vinod

Former Member
0 Kudos

Hi Vinod,

Thanks for your reply.

In fact my idea is same as you suggested.

From the displayed list I have to collect all the records which user selects through Checkbox into a new internal table and from that internal table i can delete from database table.

Right now I am facing problem in collecting records which are selected through Checkbox.

Please suggest me hoe to collect selected records after user clicks on a pushbutton from application tool bar.

Thanking you...

Vinod_Chandran
Active Contributor
0 Kudos

Hi Deepak,

Are you using list or module pool.

If it is list, then follow this logic.

w_index = 1.

DO.

READ LINE w_tabix LINE VALUE INTO w_output.

IF sy-subrc <> 0.

EXIT.

ELSE.

IF w_output-check = 'X'.

itab-check = 'X'.

modify itab index w_tabix.

ENDIF.

ENDIF.

ENDDO.

w_output is like your internal table.

Former Member
0 Kudos

Hi Vijay,

I tried your code and after READ LINE statement in my WA I am having system date splitted into all fields of WA.

And it is happening same with my code also.

Please suggest me......

My Code:

data: begin of itab occurs 0,

bukrs like ZGLCOD_SCHVI_IND-bukrs,

hkont like ZGLCOD_SCHVI_IND-hkont,

xbilk like ZGLCOD_SCHVI_IND-xbilk,

end of ty_itab.

data: itab type standard table of ty_itab,

l_itab type ty_itab.

data: it_delete type standard table of ty_itab,

l_del type ty_itab.

at user-command.

case sy-ucomm.

when 'DELETE'.

do.

read line sy-index line value into l_del.

read table itab index sy-index into l_itab.

if sy-subrc eq 0.

if xxx eq 'X'.

append l_itab to it_delete.

endif.

else.

exit.

endif.

enddo.

Thanking you,

Deepak.

Former Member
0 Kudos

Hi,

In EDitable ALV using Oops u can do as below

Field-symbols: <lfs_fieldcat> TYPE lvc_s_fcat.
LOOP AT p_fieldcat ASSIGNING <lfs_fieldcat>.
    CASE <lfs_fieldcat>-fieldname.
      WHEN 'X'.
        <lfs_fieldcat>-coltext  = 'X'.
        <lfs_fieldcat>-checkbox = 'X'.
        <lfs_fieldcat>-edit = 'X'.
............



In PBO,

call method o_alvgrid->register_edit_event
                    exporting
                       i_event_id = cl_gui_alv_grid=>mc_evt_modified.

 CALL METHOD o_alvgrid->get_selected_rows
             IMPORTING
             et_index_rows = i_fieldrows.

CASE sy-ucomm.
 WHEN 'XXX'. (fn code for the push button)
   LOOP AT i_fieldrows INTO w_fieldrows.
    READ TABLE i_output INTO w_output INDEX w_fieldrows-    index.
    if sy-subrc = 0.
   DELETE i_output from w_output.
  endif.
 clear: w-output, w_fieldrows.
endloop.
ENDCASE

.

Try this one.

Hope this helps.