Data Deletion from table | DML Operation | X++ Language
Table of Content:
Scenario:
We have a to delete a row of the EmployeeTable. Before the deletion the table will be look like below table.
EmpId | EmpName | DeptId |
E001 | Rumman Ansari | D001 |
E002 | Osman Ali Sk | D002 |
Task 1: You have to delete single row from the table.
Task 2: You have to delete all the rows from the table which matches the specific conditions.
Delete data from a table X++ code | Single Row Deletion
This code will delete only the first row
static void DataInsertionJob(Args _args) { // in this case only single row will delete ttsbegin; select forupdate empdet where empdet.DeptId == "D001"; empdet.delete(); ttscommit; info("Data Deleted"); }
Output of the code:
The first row is deleted from the table.
EmpId | EmpName | DeptId |
E002 | Osman Ali Sk | D002 |
Delete data from a table X++ code | All rows deletion which matches the conditions
We have a table like this. We want to delete the data of a few employees where Dept Id is D001.
EmpId | EmpName | DeptId |
E001 | Rumman Ansari | D001 |
E002 | Osman Ali Sk | D001 |
This code will delete all the rows present in the data set which matches the conditions.
static void DataInsertionJob(Args _args) { EmployeeMy empdet; // the above and this code delete all the related data delete_from empdet where empdet.DeptId == "D001"; info("All Data Deleted"); }
Output of the code
All the data will be deleted because for both of the rows dept id was D001
.
EmpId | EmpName | DeptId |