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

issue with delete in table control

Former Member
0 Likes
1,048

i had created table control for ztable.in that table control i have added 2 pushbuttons (add and delete).whenever i hit 'add' the record shuld be added in the database table and whenever i hit 'delete' selected records should be deleted in database also.add is working properly but delete is deleting records in table control but it is not deleting the records in database.

the code i had written for delete is as below:

FORM fcode_delete_row

USING p_tc_name TYPE dynfnam

p_table_name

p_mark_name .

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA l_table_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

FIELD-SYMBOLS <wa>.

FIELD-SYMBOLS <mark_field>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE p_table_name '[]' INTO l_table_name. "table body

ASSIGN (l_table_name) TO <table>. "not headerline

*&SPWIZARD: delete marked lines *

DESCRIBE TABLE <table> LINES <tc>-lines.

LOOP AT <table> ASSIGNING <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.

IF <mark_field> = 'X'.

DELETE <table> INDEX syst-tabix.

MODIFY zctf_as400intpro FROM TABLE g_tc_as400intpro_itab.

IF sy-subrc = 0.

<tc>-lines = <tc>-lines - 1.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM.

i had created table control for ztable.in that table control i have added 2 pushbuttons (add and delete).whenever i hit 'add' the record shuld be added in the database table and whenever i hit 'delete' selected records should be deleted in database also.add is working properly but delete is deleting records in table control but it is not deleting the records in database.

the code i had written for delete is as below:

FORM fcode_delete_row

USING p_tc_name TYPE dynfnam

p_table_name

p_mark_name .

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA l_table_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

FIELD-SYMBOLS <wa>.

FIELD-SYMBOLS <mark_field>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE p_table_name '[]' INTO l_table_name. "table body

ASSIGN (l_table_name) TO <table>. "not headerline

*&SPWIZARD: delete marked lines *

DESCRIBE TABLE <table> LINES <tc>-lines.

LOOP AT <table> ASSIGNING <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.

IF <mark_field> = 'X'.

DELETE <table> INDEX syst-tabix.

MODIFY zctf_as400intpro FROM TABLE g_tc_as400intpro_itab.

IF sy-subrc = 0.

<tc>-lines = <tc>-lines - 1.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM.

4 REPLIES 4
Read only

naimesh_patel
Active Contributor
0 Likes
750

MODIFY can be used instead of INSERT or UPDATE. You can't use it for DELETE.

Instead of


MODIFY zctf_as400intpro FROM TABLE g_tc_as400intpro_itab.

you must use:


DELETE from zctf_as400intpro where (condition)

See the extract of the online help:

The MODIFY statement inserts one or several lines specified in source in the database table specified in target, or overwrites existing lines.

Regards,

Naimesh Patel

Read only

0 Likes
750

i hav field mark in tc control where as it is not there in dbtab.based on mark i am able to delete table control records but i m unable to delete those records from dbtable.

how to do this?can anyone plz help me out in this

Read only

0 Likes
750

Hi NEED HELP ,

You have to read the marked record from the table control. then use the values of the key fields of the record read for giving condition in the Delete Query, as specified in previous threads

Regards

Sarath

Read only

Former Member
0 Likes
750

Hi,

In the following code,

IF <mark_field> = 'X'.

DELETE <table> INDEX syst-tabix.

MODIFY zctf_as400intpro FROM TABLE g_tc_as400intpro_itab.

IF sy-subrc = 0.

<tc>-lines = <tc>-lines - 1.

ENDIF.

ENDIF.

ENDLOOP.

you have used an internal table name g_tc_as400intpro_itab. What does it contain?

Use <table> instead of g_tc_as400intpro_itab. I think it has the data to be modified.

If it does not work, you can use the below logic.

Create a fieldsymbol (<fs>) of type any.

Move the key field of the table row to be deleted to this fieldsymbol.

assign component <keyfield> of structure <wa> to <fs>.

DELETE FROM zctf_as400intpro WHERE <keyfield> = <fs>.

Hope this will solve your problem.

Thanks and Regards,

Lakshmi.