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

How to delete data in table control

Former Member
0 Likes
4,459

Hi,

I am doing module pool programming. After the user enters the data in table control after saving the data. if the user wants to remove the line item the line item shd be removed from the screen and data base.

Please Give me vaulable Suggestions

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,736

Hi,

Please check with sample code below:

LOOP AT itab into wa_initial1.

IF wa_initial1-mark NE 'X'.

MOVE wa_initial1-<fieldname> to wa_initial2-<fieldname>. (Move all the corresponding fileds)

APPEND wa_initial2 TO itab1. (itab1 will contain unselected entries in the table control)

ELSE.

MOVE wa_initial1-<fieldname> to wa_initial3-<fieldname>. (Move all the corresponding fileds)

APPEND wa_initial3TO itab2.

ENDIF.

ENDLOOP.

IF itab2 IS NOT INITIAL.

DELETE ztable FROM TABLE itab2.

REFRESH itab.

LOOP AT itab1 INTO wa_initial2.

MOVE wa_initial2-<fieldname> to wa_initial1-<fieldname>.(Move all the corresponding fileds)

APPEND wa_initial1 TO itab.(itab will contain the records to be displayed on the screen after deleting)

ENDLOOP.

ENDIF.

10 REPLIES 10
Read only

Former Member
0 Likes
2,736

As I understand, the user will press a delete button after selecting the line.

In that case, in the event User_command, identify the selected record, delete that entry from the internal table as well as the database using the promary key.

regards,

Jinson

Read only

Former Member
0 Likes
2,736

hi,

Refer to this link..

When you delete the record from the internal table try to delete the record fom Database table.

Edited by: avinash kodarapu on Jan 3, 2009 3:32 PM

Read only

Former Member
0 Likes
2,737

Hi,

Please check with sample code below:

LOOP AT itab into wa_initial1.

IF wa_initial1-mark NE 'X'.

MOVE wa_initial1-<fieldname> to wa_initial2-<fieldname>. (Move all the corresponding fileds)

APPEND wa_initial2 TO itab1. (itab1 will contain unselected entries in the table control)

ELSE.

MOVE wa_initial1-<fieldname> to wa_initial3-<fieldname>. (Move all the corresponding fileds)

APPEND wa_initial3TO itab2.

ENDIF.

ENDLOOP.

IF itab2 IS NOT INITIAL.

DELETE ztable FROM TABLE itab2.

REFRESH itab.

LOOP AT itab1 INTO wa_initial2.

MOVE wa_initial2-<fieldname> to wa_initial1-<fieldname>.(Move all the corresponding fileds)

APPEND wa_initial1 TO itab.(itab will contain the records to be displayed on the screen after deleting)

ENDLOOP.

ENDIF.

Read only

Former Member
0 Likes
2,736

This message was moderated.

Read only

Former Member
0 Likes
2,736

Hi

Go through the link given below :

With Regards

Nikunj Shah

Read only

Former Member
0 Likes
2,736

Hi,

Assume the selection button on the grid you have created is named flag. You will have a field in your internal table with a field flag of type c. Now if the user needs to delete a set of records from the table control, he'll first select them on the table control. this would set the value of flag field as X for selected records. Transfer those records into another internal table and delete them from the first internal table Now use the second internal table to delete records from the database. the code would be something like this

Case sy-ucomm.

when ;'DELE'.

Read only

Former Member
0 Likes
2,736

Hi,

Assume the selection button on the grid you have created is named flag. You will have a field in your internal table with a field flag of type c. Now if the user needs to delete a set of records from the table control, he'll first select them on the table control. this would set the value of flag field as X for selected records. Transfer those records into another internal table and delete them from the first internal table Now use the second internal table to delete records from the database. the code would be something like this

Case sy-ucomm.

when ;'DELE'.

loop at itab where flag = 'X'.

jtab = itab.

append jtab.

delete itab index sy-tabix.

endloop.

delete ztable from table jtab.

endcase.

This should solve your problem.

Regards,

Sachin

Sorry for the earlier post as it got submitted accidently before completion.

Read only

Former Member
0 Likes
2,736

Hi Salman,

Refer this thread.it may be helpful to u

revert back for any queries

Regards,

Sravanthi

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
2,736

Hi,

Screen 8002 (with table control) --> select records --> press delete button --> delete selected records

Now you wan to delete those records selected by the user at runtime when DELETE button is clicked.

Take another internal table and work area same as the initial internal table and work area used in screen 8002 which is to be used to delete the selected data.

Take the names of the input/output fields as work_area-field_name and select column in table control as work_area-flag.

Also take a flag field of size 1 datatype character as the last field in the internal table and work area while declaration.

You must have passed a code in PBO of the screen for reading internal table into the table control.

So it reads the internal table into the table control whenever you perform any action on use command.

All you need to do is to write a code to modify the internal table form the table control while performing any user action.

Remember to change the LINE SEL option in attributes of table control as MULTIPLE.

At screen logic,


PROCESS BEFORE OUTPUT.
  MODULE status_8002. "for pf-status

  LOOP WITH CONTROL po_tab. "po_tab is table control
    MODULE pass_data. "to pass data into table control from internal table
  ENDLOOP.

PROCESS AFTER INPUT.
  MODULE user_command_8002. "for user command(back and exit)

  LOOP WITH CONTROL po_tab.
    MODULE modify_data. "to modify data from table control into table control
  ENDLOOP.

  MODULE delete. "to delete the selected records

In PBO,


*&---------------------------------------------------------------------*
*&      Module  STATUS_8002 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_8002 OUTPUT.
  SET pf-status 'ZAB_PFSTA'. " pf-status
 
  DATA : line_count TYPE i.
 
  DESCIRBE TABLE it_ekpo
  LINES line_count.
 
  po_tab-lines = line_count + 10.
  " to make table control scrollable
ENDMODULE.                 " STATUS_8002  OUTPUT
 
*&---------------------------------------------------------------------*
*&      Module  PASS_DATA  OUTPUT
*&---------------------------------------------------------------------*
MODULE pass_data OUTPUT.
  READ TABLE it_ekpo into wa_ekpo INDEX po_tab-current_line.
ENDMODULE.                 " PASS_DATA  OUTPUT
"it_ekpo is internal table and wa_ekpo is the work area

In PAI,


*&---------------------------------------------------------------------*
*&      Module  MODIFY_DATA  INPUT
*&---------------------------------------------------------------------*
MODULE MODIFY_DATA INPUT.
  MODIFY IT_EKPO INDEX PO_TAB-CURRENT_LINE FROM WA_EKPO.
  "modify records from table control into the internal table
ENDMODULE.                 " MODIFY_DATA  INPUT

*&---------------------------------------------------------------------*
*&      Module  DELETE  INPUT
*&---------------------------------------------------------------------*
MODULE DELETE INPUT.

  OK_CODE = SY-UCOMM.

  CASE OK_CODE.

    WHEN 'DELETE'. "when delete button is clicked
      SORT IT_EKPO BY FLAG DESCENDING. "sort by flag(selection column value)
      CLEAR WA_EKPO1.
      CLEAR WA_EKPO.
      REFRESH IT_EKPO1.
      LOOP AT IT_EKPO INTO WA_EKPO WHERE FLAG = 'X'.
        DATA : J TYPE I.
        CLEAR J.
        J = SY-TABIX. "assign index value if a record is selected
        MOVE-CORRESPONDING WA_EKPO TO WA_EKPO1. "append selected records to another
        "work area and append to another internal table to delete
        APPEND WA_EKPO1 TO IT_EKPO1.
        DELETE IT_EKPO. "delete the selected records from initial internal table
        " to reflect the changes on the table control
      ENDLOOP.

      IF J = 0.
        MESSAGE I006. "if no record selected
      ELSE. "if some records are selected
        DELETE ZEKPO FROM TABLE IT_EKPO1. "delete from database table
        COMMIT WORK.
        IF SY-SUBRC = 0.
          MESSAGE S007. "success message (records deleted)
        ENDIF.
      ENDIF.

  ENDCASE.
ENDMODULE.                 " DELETE  INPUT

Now at PAI, you have delete records and these changes are reflected back to the internal table.

Now when PBO is executed it will again read the initial internal table and will not show the deleted records.

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir

Read only

Former Member
0 Likes
2,736

Hi.....

it_wizard is the internal table which holds the data in table control.

it_delete is the internal table which holds the data which are deleted.

zsel is the character field which holds the selected row in table control.

LOOP AT it_wizard into wa_wizard WHERE zsel = 'X'.
       MOVE-CORRESPONDING wa_wizard TO wa_delete.
       APPEND wa_delete TO it_delete.
       delete table it_wizard from wa_wizard.
 DELETE  FROM zfin_goods WHERE ZFG = WA_delete-ZFG.
 if sy-subrc eq 0.
message 'Deletion successful' type 'S'.
endif.

Hope this is useful.

Thanks and Regards

Bhuvana