2 Replies Latest reply: Aug 12, 2008 5:12 PM by sreesanth reddy RSS

How to create custom controller for a view ?

sreesanth reddy
Currently Being Moderated


I want to learn about custom controller. I understand that it is used to hold the context after we navigate away from the view.. but I'm looking for some technical information on this..


1) Can someone please tell me what technical property enables custom controller to hold data for longer time ?


2) Does every standard SAP view have custom controller class ? Can we create our own custom controllers ? If yes, is there any standard SAP class that we can inherit from ? (I did do a where used list on cl_bsp_Wd_Custom_controller hoping to find some info.. but I was unsuccessful)


3) How and where do we link the custom controller class to a view ?


Any document or a pointer(to look at or read) describing how a custom controller is created and used with an example will be highly appreciated.






  • Re: How to create custom controller for a view ?
    Carsten Kasper
    Currently Being Moderated

    Hi Sreesanth,



    Short answer: Object lifetime.

    Long answer: The lifetime of a view controller is the time the view is being shown on the UI. The lifetime of a component controller is as long as the component is being used. The lifetime of a custom controller, as far as I experienced, is as long as it is being referenced or explicitly unloaded.

    For instance: You open component BP_HEAD, the component controller is created. You show view DETAIL, the view controller is created. You navigate to Contact Person EDIT. The view DETAIL is no longer shown and the controller, including all data, is destroyed. The component controller lives on. The view for editing contact persons is created. If you create a custom controller in view DEATAIL it will live on and hold the data.



    No, not every SAP view uses custom controllers. There are many ways to live without them.

    Yes, you can create your own custom controllers. There is a wizard for it in the Component Workbench. Just do a right click on Custom Controllers and select create.



    Custom Controllers are handled by the framework. In class CL_BSP_WD_CONTROLLER there is a method  GET_CUSTOM_CONTROLLER that will get an instance of ANY custom controller you like. The class mentioned is in the inheritance of every view, window or controller. Thus you just need to call it in your coding.


    There are many documents available from SAP regarding this topic. As SAP is not giving out CRM 2007 stuff on a great scale you could try and go with the IC Webclient documentation from on CRM 4.0.


    cheers Carsten