It is very important to know how to enhance a component. It is rare to create a new UI component. Most of the times, we need to change the existing SAP standard component according to our adjustment.
So we need enhance the existing components to tailor it as we wanted. This is very important feature of any software. Because it is impossible to create a software to cover all business scenarios. When we enhancement a component, we will create one new bsp application in the customer name space, which reuses the standard application. Whatever the changes we do, are part of this new bsp application and sap standard component is untouched. Later if we want to delete the enhancement, the new bsp application will be deleted without creating any problem to standard component.
Sap has provided a container to store all changes to a component while enhancing. This container is called enhancement set. There may be more than one enhancement set available in the system. However, only one enhancement set should be active during runt time. So if we do any change to a UI component under one enhancement set, same changes reflected at runtime when we load same component under same enhancement set.
Pressing F2 button on any field in the web ui will show a popup in which we can about active enhancement set in the system.
Let us enhance one standard component. Go to the transaction BSP_WD_CMPWB and choose the component that you want to enhance.
The highlighted button (1) is used to toggle enhancement set field. If you click it, enhancement field will be hidden and you can display the sap component as it is. If enhancement set field is visible, then you should specify an existing enhancement set to display the component.
Let us create the enhancement set. Click on the create button and give required details in the next Dialog box.
Enhancement set is created and will be displayed in the enhancement set field.
Now click on display button. We will receive below message at bottom of the screen if that particular component has not been enhanced under the provided enhancement set.
Enhancement set ZTESTENHANCE does not contain an enhancement for component BT126H_MAIL
复制代码
Click on the enhance component button.
First it will ask for an enhancement set. Give the enhancement set that we created in the above step.
Choose continue, then it will ask for new bsp application. Generally we give same component name with prefix Z. (we can choose any suitable name here).
If application does not exist in the system, it will ask to create it or not. Choose yes.
In the next step, it will ask for Repository.xml page, just continue
After this step, if there is any application exists with the same name you have given, system will ask you to overwrite it. Don’t choose yes in these situations if you are not sure. Somebody might be created it under any other enhancement set. Choose no and it will take you back to the previous dialog box, just cancel it. Again click on enhance component and give new application name and continue.
Once every step is completed save the entries. We have successfully enhanced the component. If a component is enhanced and if we open that component under same enhancement set, you can see a button at top ‘delete enhancement ‘. This means that component has been enhanced. Now we can see the same button in our case.
We just enhanced the component. In order to change any view or window and even component controller, we need to enhance them as well. Generally if open a component under any enhancement set, all non-enhanced parts are greyed out. If you right click on them, you can see an option Enhance.
Let us enhance the view as well. Right click on it and choose the option Enhance. System will automatically create new Z classes for view and context. If these classes already exist in the system, then it will ask user to choose correct name for classes.
Here in my case, it asking to change the view implementation class as it already there in the system.
Just change the name if the dialog box appears and continue. I just added 1 to the name and saved the entries. Now I could see new generated classes for view and context.
Here observe the class highlighted with red color. Still it is showing the standard class not z class. When we enhance only view and context classes will be enhanced not the context nodes. If we want to change the any context node, then we need to enhance them separately. Right click any context node and enhance it.
Once we enhanced, the view name is in black color before it was greyed out. Observe the difference. Once enhanced, customer can carry on according to his requirements.
HOW MAKE USE OF NEWLY CREATED ENHANCEMENT SET IN RUN TIME?
Yes, we have created enhancement set and we enhanced our UI component under it. Now we need to do something to open the same component under our set on web ui. For this there is one special BADI COMPONENT_LOADING. We need to create one new implementation for this BADI and code inside the method IF_BSP_WD_CMP_LOADING_BADI~GET_ACTIVE_ENHANCEMENT_SET.
Sample code look like below.
Whatever the enhancement set mentioned in above method , will be the active enhancement set.
So we need enhance the existing components to tailor it as we wanted. This is very important feature of any software. Because it is impossible to create a software to cover all business scenarios. When we enhancement a component, we will create one new bsp application in the customer name space, which reuses the standard application. Whatever the changes we do, are part of this new bsp application and sap standard component is untouched. Later if we want to delete the enhancement, the new bsp application will be deleted without creating any problem to standard component.
Sap has provided a container to store all changes to a component while enhancing. This container is called enhancement set. There may be more than one enhancement set available in the system. However, only one enhancement set should be active during runt time. So if we do any change to a UI component under one enhancement set, same changes reflected at runtime when we load same component under same enhancement set.
Pressing F2 button on any field in the web ui will show a popup in which we can about active enhancement set in the system.
Let us enhance one standard component. Go to the transaction BSP_WD_CMPWB and choose the component that you want to enhance.
The highlighted button (1) is used to toggle enhancement set field. If you click it, enhancement field will be hidden and you can display the sap component as it is. If enhancement set field is visible, then you should specify an existing enhancement set to display the component.
Let us create the enhancement set. Click on the create button and give required details in the next Dialog box.
Enhancement set is created and will be displayed in the enhancement set field.
Now click on display button. We will receive below message at bottom of the screen if that particular component has not been enhanced under the provided enhancement set.
Click on the enhance component button.
First it will ask for an enhancement set. Give the enhancement set that we created in the above step.
Choose continue, then it will ask for new bsp application. Generally we give same component name with prefix Z. (we can choose any suitable name here).
If application does not exist in the system, it will ask to create it or not. Choose yes.
In the next step, it will ask for Repository.xml page, just continue
After this step, if there is any application exists with the same name you have given, system will ask you to overwrite it. Don’t choose yes in these situations if you are not sure. Somebody might be created it under any other enhancement set. Choose no and it will take you back to the previous dialog box, just cancel it. Again click on enhance component and give new application name and continue.
Once every step is completed save the entries. We have successfully enhanced the component. If a component is enhanced and if we open that component under same enhancement set, you can see a button at top ‘delete enhancement ‘. This means that component has been enhanced. Now we can see the same button in our case.
We just enhanced the component. In order to change any view or window and even component controller, we need to enhance them as well. Generally if open a component under any enhancement set, all non-enhanced parts are greyed out. If you right click on them, you can see an option Enhance.
Let us enhance the view as well. Right click on it and choose the option Enhance. System will automatically create new Z classes for view and context. If these classes already exist in the system, then it will ask user to choose correct name for classes.
Here in my case, it asking to change the view implementation class as it already there in the system.
Just change the name if the dialog box appears and continue. I just added 1 to the name and saved the entries. Now I could see new generated classes for view and context.
Here observe the class highlighted with red color. Still it is showing the standard class not z class. When we enhance only view and context classes will be enhanced not the context nodes. If we want to change the any context node, then we need to enhance them separately. Right click any context node and enhance it.
Once we enhanced, the view name is in black color before it was greyed out. Observe the difference. Once enhanced, customer can carry on according to his requirements.
HOW MAKE USE OF NEWLY CREATED ENHANCEMENT SET IN RUN TIME?
Yes, we have created enhancement set and we enhanced our UI component under it. Now we need to do something to open the same component under our set on web ui. For this there is one special BADI COMPONENT_LOADING. We need to create one new implementation for this BADI and code inside the method IF_BSP_WD_CMP_LOADING_BADI~GET_ACTIVE_ENHANCEMENT_SET.
Sample code look like below.
Whatever the enhancement set mentioned in above method , will be the active enhancement set.