You need to make changes to the field list of a database table that already contains data. Depending on the nature of the change, the system request you to adjust the table.
Task 1: Copy Template (Optional)
Copy the template database table definition. If you finished the previous exercise, you can skip this task and continue editing your database table Z##EMPLOY.
Steps
Copy database table definition /LRN/EMPLOY to your own package (suggested name: Z##EMPLOY, where ## stands for your group number).
In the Project Explorer view, right-click database table definition /LRN/EMPLOY to open the context menu.
From the context menu, choose Duplicate ....
Enter the name of your package in the Package field. In the Name field, enter the name Z##EMPLOY, where ## stands for your group number.
Confirm the transport request and choose Finish.
Activate the copy.
Press Ctrl + F3 to activate the database table definition.
Task 2: Handle Direct Changes
In the field list of your database table, add a new field (suggested name: DEPARTMENT_ID) and type it with built in type CHAR and length 40. After activating the table with the new field, reduce the length of the field to 20 and adjust the table on the database.
Steps
Before theANNUAL_SALARY field, add a new field (suggested name: DEPARTMENT_ID) and type it with built in type CHAR and length 40.
Adjust the code as follows:
12345678
birth_date : z##birth_date;
entry_date : z##entry_date;
department_id : abap.char(40);
@Semantics.amount.currencyCode : 'z##employ.currency_code'
annual_salary : z##annual_salary;
currency_code : waers;
Activate the database table definition.
Press Ctrl + F3 to activate the development object.
Display the Dictionary Log for the table.
Right-click anywhere in the source code and choose Open With → Dictionary Log.
Navigate to the Dictionary Log tab that appears below the editor.
Hold down the Ctrl key and click on the row starting with See log.
From the toolbar on the Dictionary Log tab, choose Show Search Toolbar.
Enter the name of your database table in the Find: field and press Enter.
The update strategy is mentioned after the row Adjust table in DB >>>.
Reduce the length of the new field from 40 to 20.
Adjust the code as follows:
12345678
birth_date : z##birth_date;
entry_date : z##entry_date;
department_id : abap.char(20);
@Semantics.amount.currencyCode : 'z##employ.currency_code'
annual_salary : z##annual_salary;
currency_code : waers;
Activate the database table definition.
Press Ctrl + F3 to activate the development object.
Analyze the ABAP log.
On the dialog window with the error message, choose Open ABAP Log to display the Dictionary Log.
On the Dictionary Log tab, hold down the Ctrl key and click on the row starting with See log.
From the toolbar on the Dictionary Log tab, choose Show Search Toolbar.
Enter the name of your database table in the Find: field and press Enter.
The update strategy is mentioned after the row Adjust table in DB >>>.
Use the quick fix to convert the content of your database table.
Navigate to the source code of your database table definition.
In the code row that starts with define table, place the cursor on the table name and press Ctrl + 1 to invoke the quick fix.
From the list of available quick fixes, choose Adjust and activate database table, convert data.
Task 3: Handle Indirect Changes
Replace the hard-coded type with a new data element (suggested name: Z##_DEPARTMENT_ID, where ## is your group number) which uses a new domain ((suggested name: Z##_DEPARTMENT_ID). In the domain, use technical type CHAR with a length of 20. After activating the database table, change the length in the domain to 10. Then activate and adjust the database table.
Steps
In your database table definition, replace abap.char(20) with Z##_DEPARTMENT_ID and use a quick fix to create the new data element.
Adjust the code as follows:
12345678
birth_date : z##_birth_date;
entry_date : z##_entry_date;
department_id : z##_department_id;
@Semantics.amount.currencyCode : 'z##employ_dep.currency_code'
annual_salary : z##_annual_salary;
currency_code : waers;
Click on z##_department_id, and press Ctrl + 1 to open the quick fix menu.
From the quick fix menu, double-click Create data element ....
Confirm the package and the name, enter a description, for example, Department Identification, and choose Next.
Assign the new object to a transport request and choose Finish.
Under Type Name, enter Z##_DEPARTMENT_ID and enter the following field labels:
Field | Value |
---|
Short | Dep. |
Medium | Department |
Long | Department ID |
Heading | Department ID |
Save the data element. Then use forward navigation to create the domain with technical type CHAR and a length of 20.
Press Ctrl + S to save the data element.
Choose the Type Name: label to start creating the domain.
Confirm the package and the name, enter a description, for example, Department Identification, and choose Next.
Assign the new object to a transport request and choose Finish.
Enter CHAR as Data Type and 20 as Length.
Save the domain. Then activate the domain, the data element, and the database table definition.
Press Ctrl + S to save the domain.
Choose Activate inactive ABAP development objects. Alternatively, press Ctrl + Shift + F3.
Choose Select All and then Activate.
In your domain for the department ID, reduce the technical length and the display length from 20 to 10.
Navigate to your domain Z##_DEPARTMENT_ID.
Change the value in the Length field from 20 to 10.
Remove the value in the Output Length field (this will be filled automatically during activation).
Try to activate the domain and analyze the messages on the Problems view.
Press Ctrl + F3 to activate the domain.
Open the Problems view below the editor to display the error messages.
Use the quick fix for the error message Domain ... cannot be activated due to dependent tables.
In the Problems view, place the cursor on the error message that starts with Domain ... and press Ctrl + 1 to invoke the quick fix.
Choose Finish.
From the Previous Result section on the lower right, choose Activation Log to analyze the activation log.
Use a quick fix to adjust and convert the dependent database table, that is, your database table Z##EMPLOY.
Navigate to the source code of your database table definition.
In the code row that starts with define table, place the cursor on the table name and press Ctrl + 1 to invoke the quick fix.
From the list of available quick fixes, choose Adjust and activate database table, convert data.
Activate the domain for the department ID.
Navigate to the definition of your domain for the department ID.
Press Ctrl + F3 to activate the development object.