二维码

[教程] ENHANCING STANDARD UI COMPONENT

Twilight发表于 2016-02-05 23:14Twilight 最后回复于 2016-02-05 23:14 [复制链接] 698 0

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.
Enhancement UI 1.jpg

Let us enhance one standard component. Go to the transaction BSP_WD_CMPWB and choose the component that you want to enhance.
Enhancement UI 2.jpg

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 UI 3.jpg

Enhancement set is created and will be displayed in the enhancement set field.
Enhancement UI 4.jpg

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.
  1. Enhancement set ZTESTENHANCE does not contain an enhancement for component BT126H_MAIL
复制代码

Click on the enhance component button.
Enhancement UI 5.jpg

First it will ask for an enhancement set. Give the enhancement set that we created in the above step.
Enhancement UI 6.jpg

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).
Enhancement UI 7.jpg

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
Enhancement UI 8.jpg

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.
10.jpg

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.
Enhancement UI 9.jpg

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.
Enhancement UI 10.jpg

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.
Enhancement UI 11.jpg

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.
Enhancement UI 12.jpg

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.
Enhancement UI 13.jpg

Whatever the enhancement set mentioned in above method , will be the active enhancement set.
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表