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

Tabel control

Former Member
0 Likes
928

Hi all,

I am trying to MODIFY , INSERTand DELETE a record from database using table control. Insert is working fine, but i am not able to modify and delete,

Please advise.

Coding:

WHEN 'DELETE'.

LOOP AT G_table1 INTO G_WA_table1 WHERE IND = 'X'.

IF sy-subrc = 0.

DELETE ZDBTABLE FROM G_WA_table1 .

endif.

ENDLOOP.

*****This logic dosent work.

-


Also suggest how do I modify a record and update the same to database.

6 REPLIES 6
Read only

Former Member
0 Likes
870

hi.

sy-subrc is not required in the LOOP AT.. WHERE..

WHEN 'DELETE'.
LOOP AT G_table1 INTO G_WA_table1 WHERE IND = 'X'.
DELETE ZDBTABLE FROM G_WA_table1 . 
ENDLOOP.
WHEN 'UPDATE'.
LOOP AT G_table1 INTO G_WA_table1 WHERE IND = 'X'.
UPDATE ZDBTABLE FROM G_WA_table1 where <Primary Key condition> . 
ENDLOOP.

Read only

0 Likes
870

Hi All,

DELETE still dosent work, I appreciate your response.

Read only

0 Likes
870

i think u need to refresh ur screen or update screen to reflect changes.

Read only

Former Member
0 Likes
870

Hi,

Try creating another insternal table and append the selected records into this table and then delete those records from the database table.

WHEN 'DELETE'.

LOOP AT G_table1 INTO G_WA_table1 WHERE IND = 'X'.

g_wa_table2-<fieldname> = g_wa_table1-<fieldname>

append g_wa_table2 into g_table2.

delete g_table1 index sy-tabix.

ENDLOOP.

DELETE ZDBTABLE FROM g_table2.

g_table2 is a new table with structure similar to g_table1 without the ind field. .

All records from g_table1 which are selected (IND =X) are placed in the other table (g_table2) and are deleted from the g_table1 table.

Hope this helps you.

Regards,

Sachin

Read only

Former Member
0 Likes
870

Hi....

The below code is for the deletion of records in the table control and the ztable.

it_wizard is the internal table which holds the date of the table control.

it_delete is the internal table which holds the deleted record.

zsel is the character field which captures the selected row of record.

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 success' type 'S'.
endif.

The below code is for the modification of record in the table control and the ztable.

LOOP AT it_wizard INTO wa_wizard.
MOVE-CORRESPONDING wa_wizard TO wa_save.
append wa_save to it_save.
clear: wa_save, wa_wizard.
   endloop.
    MODIFY zfin_goods FROM TABLE it_save.
IF sy-subrc = 0.
message 'Updation success' type 'S'.
endif.

Hope this helps you great.

Thanks and regards.

Bhuvana

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
870

Hi,

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 have to pass 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, if you done any changes in the table control, then all these changes will be reflected to the internal table and now you can manipulate the data as per your requirement.

After selecting records and deleting them, 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