Monday, 6 January 2014

Deleting Fields in SAP TABLES

Deleting Fields in SAP TABLES

While infrequent, occasionally there may be a need to remove a field from a table. When doing this, it is important to take special care, as data can be lost in the process. Certainly in the case of key fields.
If, for example, the Currency key field was removed from our table, the foreign key rela-tionship to the TCURC table would be removed. As the SALARY field has to have a related Currency Key this would cause the table to no longer continue working, and likely make the ZEMPLOYEES2 table become inactive.
When deleting fields it is important to ask oneself whether the data being held in the table is being used elsewhere, and whether its deletion will have further consequences. If you do try to delete fields which are being used elsewhere, the SAP system should try to pre-vent this, or at least issue a stern warning. This is not necessarily to be relied upon though, so always ensure to check manually what the effects of deletion are likely to be. Also, if you do delete fields, the table will have to be adjusted via the SE14 transaction to be acti-vated again.
Create a new field, above ‘.INCLUDE’, named ‘ZAWESOME’. Use a previously created Data element, here ZTITLE just to save time, and activate the table
Deleting Fields in SAP TABLES

         
Create a new record in the table. The data here is not important and will be deleted, so the content can be anything
                
Deleting Fields in SAP TABLES

Deleting Fields in SAP TABLES

                                   
Now, to delete the field, highlight it in the ‘Maintain Table’ screen, and click the ‘Remove row’ icon, in the toolbar next to ‘Insert row’. The row will disappear, but when you try to activate the table, an error message will appear
               
Deleting Fields in SAP TABLES

Transaction SE14 must again be used to adjust the table so the change can be applied. Fol-low the same steps as in the previous section to perform this task. Once this is complete, view the table again. The column has disappeared, and the data which was contained within it lost
                 
Deleting Fields in SAP TABLES
                                           
To see what happens when a key field is deleted, return to the ABAP Dictionary initial screen and make a copy of ZEMPLOYEES2, called, unsurprisingly, ZEMPLOYEES3. Doing this will allow the ZEMPLOYEES2 table to not be damaged in this risky procedure. Activate the new table (which, don’t forget, will be empty of records). As before, again make the Sur-name field a key field. Now create some records for this table
Deleting Fields in SAP TABLES

To save time creating new records, the same data was replicated here, with only slight changes to the key fields. Remember that it is only one key field per entry which must be unique for that particularly record to be unique itself.
Now, the surname field will be deleted, and the effects of deleting this key field observed. By removing this key field, the only unique data which will be held for each record will be the Employee Number and Client. Since SMITH and SMITH2, and ANDREWS and AN-DREWS-2 have the same Employee Number and Client, these will no longer hold unique key field data, leaving duplicate records, which the system will not allow.

Remove the Surname field; try to activate the table, and error messages will appear. Go through SE14 to adjust the table for activation. When you now view the table, the Sur-name field is gone, and two records have been lost, leaving only one of the two records for each of the two Employee Numbers used
Deleting Fields in SAP TABLES

No comments:

Post a Comment