2015 Sep 17 9:07 AM
hello experts,
i am facing a problem. i created a webdynpro program in which it saves and delete the data. when i press delete button it will delete only internal table data. but i want also delete in database table. and how can i save the data in database table please suggest me to solve this problem.
here i am uploading my code.
METHOD ONACTIONDELETE .
DATA LO_ND_EMPLOYEE_WAGES TYPE REF TO IF_WD_CONTEXT_NODE.
DATA LO_EL_EMPLOYEE_WAGES TYPE REF TO IF_WD_CONTEXT_ELEMENT.
DATA LS_EMPLOYEE_WAGES TYPE WD_THIS->ELEMENT_EMPLOYEE_WAGES.
DATA GT_EMPLOYEE_WAGES TYPE TABLE OF WD_THIS->ELEMENT_EMPLOYE
DATA GS_EMPLOYEE_WAGES TYPE WD_THIS->ELEMENT_EMPLOYEE_WAGES.
DATA: NODE TYPE REF TO IF_WD_CONTEXT_NODE,
NUM TYPE I.
* gt_employee_wages TYPE TABLE OF if_main=>ELEMENT_employee_wages.
NODE = WD_CONTEXT->GET_CHILD_NODE( NAME = 'EMPLOYEE_WAGES' ).
NODE->GET_STATIC_ATTRIBUTES_TABLE(
IMPORTING
TABLE = GT_EMPLOYEE_WAGES
).
NUM = NODE->GET_LEAD_SELECTION_INDEX( ).
DELETE GT_EMPLOYEE_WAGES INDEX NUM.
**************** DELETE ZEMPLOYEE_WAGES FROM TABLE GT_EMPLOYEE_WAGES .
NODE->BIND_TABLE( GT_EMPLOYEE_WAGES ).
when i delete data using this code it will delete all data of databse table.
if i use DELETE ZEMPLOYEE_WAGES FROM TABLE GT_EMPLOYEE_WAGES this code.
Did you debug a bit the code?
NODE->GET_STATIC_ATTRIBUTES_TABLE(
IMPORTING
TABLE = GT_EMPLOYEE_WAGES
).
and here you get your table, nice (1)
NUM = NODE->GET_LEAD_SELECTION_INDEX( ).
This i guess retrieve a selected row, correct?(2)
DELETE GT_EMPLOYEE_WAGES INDEX NUM.
Here you delete the internal row selected(3)
**************** DELETE ZEMPLOYEE_WAGES FROM TABLE GT_EMPLOYEE_WAGES .
With this you want to delete the selected row from db too, correct? (4)
If i understood all correctly, i see a couple of problems in this code at the following points:
2-> if the user did not select a row, num got 0 and you'll get a bunch of problems! You should check it before going on
3->ok, but you should place it AFTER point 4
4->this point delete from DB all the rows EXCEPT the one marked for deletion since GT_EMPLOYEE_WAGES contains ALL the rows from you WD table minus the selected one that you already deleted!
So, my suggestion is:
2->ok, but with checks
2.5-> read table gt_employee_wages into wa_wages indexc num
3->like now
4-> delete ZEMPLOYEE_WAGES from wa_wages. commit work.
2015 Sep 17 9:52 AM
u can add where clause to your delete statement.
=> DELETE ZEMPLOYEE_WAGES FROM TABLE GT_EMPLOYEE_WAGES where .....
to specify the deleted records to not delete all table content .
2015 Sep 17 11:04 AM
hi peter,
i used where condition but it shows an error like "." expected after gt_employee_wages.
2015 Sep 18 3:20 PM
hi Chirag,
it suppose to be like that :
DELETE FROM <table name> WHERE <conditions>.
2015 Sep 17 11:41 AM
Did you debug a bit the code?
NODE->GET_STATIC_ATTRIBUTES_TABLE(
IMPORTING
TABLE = GT_EMPLOYEE_WAGES
).
and here you get your table, nice (1)
NUM = NODE->GET_LEAD_SELECTION_INDEX( ).
This i guess retrieve a selected row, correct?(2)
DELETE GT_EMPLOYEE_WAGES INDEX NUM.
Here you delete the internal row selected(3)
**************** DELETE ZEMPLOYEE_WAGES FROM TABLE GT_EMPLOYEE_WAGES .
With this you want to delete the selected row from db too, correct? (4)
If i understood all correctly, i see a couple of problems in this code at the following points:
2-> if the user did not select a row, num got 0 and you'll get a bunch of problems! You should check it before going on
3->ok, but you should place it AFTER point 4
4->this point delete from DB all the rows EXCEPT the one marked for deletion since GT_EMPLOYEE_WAGES contains ALL the rows from you WD table minus the selected one that you already deleted!
So, my suggestion is:
2->ok, but with checks
2.5-> read table gt_employee_wages into wa_wages indexc num
3->like now
4-> delete ZEMPLOYEE_WAGES from wa_wages. commit work.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |