Sunday, December 29, 2013

How to access one context node's data from another context node

Assume we have 2 context nodes BUILHEADER(Header) and BUILROLES(Roles). And from Roles context node class if we need to access Header CN:

1. Create an attribute ZHEADER type ref to ZL_ZROLES_ROLESLIST_CN01 in the Roles context node class.


2. In the Create Header method of context node class add the following code.



3. In the get_attr method of the Roles context node, the header context node can be accessed.



Setting for navigation between components

What settings are to be done to navigate between components -

1. From the outbound plug of your source window call( ).
nav_service = cl_crm_ui_navigation_service=>get_instance

CALL METHOD nav_service->navigate
EXPORTING

iv_link_id
= linkid. The link id is your logical link id.

2. Create your logical link with a target id and an object type. You can get a target id when you create a inbound plug entries for your target view/window.

3. In CRMC_UI_NBLINKS connect the logical link, target id and the object type.

Creating a view in CRM WEB UI

Custom BO creation:
A BOL entity is a business object whose structure is same as the structure you want to display in your view. A BOL entity is of type CL_CRM_BOL_ENTITY.
How to create a BOL entity if there does not exist one with the structure you need?
1. First create a DB table in SE11, with all the fields you need in your view.
2. Then create a lock object for this view with the kind of lock you need.
3. Now assign a BO to this table and lock object in the view CRMV_TBLOBJ_OBJ
4. Now in SPRO->CRM->CROSS APP COMP->GENIL COMP->SPECIAL SETTING->DEFINE BO, mention your BO, DB table, Interface details.
This completes creation of a BO.

Creating a table view:
1. Create a table view with the desired context node.
2. Create the buttons in the controller class, and set the CONFIG TABLE details in the .htm page to set the table config.
3. Create buttons CREATE, EDIT, DELETE in the DO_PREPARE_OUTPUT method of the view controller class.
4. Add event handler methods for each of the buttons.
Code details:
You use the component controller(CoCo) of the component to access the context nodes of other views in the component. CoCo basically acts like a global place holder and context nodes assigned to component controller can be accessed from any view's controller class.
How to access a context node of some other view from your custom view?
lr_comp ?= me->comp_controller
lr_comp->typed_context->campaign->collection_wrapper->get_current( ).
5. Create a ON_NEW_FOCUS method which acts as a event handler for NEW_FOCUS event.
This method is used to determine the BOL entities of dependent model nodes as a collection at run time and to assign them to the collection wrapper of the dependent model node. In other words, if the focus of the collection of the leading context node changes, its collection wrapper sends a NEW_FOCUS event to the dependent collection node which updates its context structure accordingly. This event is triggered by the publish_current method of the collection_wrapper of your leading context node.
The ON_NEW_FOCUS method is created in the context node class of your view and set that as an event handler method for the class CL_BSP_WD_COLLECTION_WRAPPER and event NEW_FOCUS.
Go to CTXT class of Order and in the CONNECT_NODES method set the handler to activate 
coll_wrapper = campaign->get_collection_wrapper
set HANDLER me->order->on_new_focus for coll_wrapper ACTIVATION iv_activate.
6. For the SAVE action:
You have used the component controller to access other views context node, now for other views to access your context node your context node has to be tied up to the component controller. The save is in the over view page, and to inform the Save button that there is an other view which it has to save and commit, we tie the data/context nodes to the component controller.
In the create_order method of your context class, after the binding call the ON_NEW_FOCUS method so that we can pass the entity or the FOCUS_BO parameter to the ON_NEW_FOCUS method.
In the save action:
get, the current entity and add it to the transaction context and transaction manager saves and commits all the bol collection at a time.
A transaction context is like a buffer where all the bol entities are stored, and after the save action all the bol entities are together saved and committed to the DB.
At the end also call the publish_current method  from the collection wrapper class.
7. ON_NEW_FOCUS method: In here you write the query method to get the query result and display your output. In addition to this you can also set conditions to inform the view about when it has to fetch the data.

Custom controller

1. How to configure a .htm page to get the CONFIGURATION tab?

<chtmlb: config mode       = "RUNTIME"
                 display mode   = "TRUE"
                 xml                  = "<%= controller->configuration_descr->get_config_data( ) %>" />


2. Details on Custom Controller?

A Custom Controller is used when you want to access data from one view in an other view belonging to the same component.
To do this -
1. You can use the wizard, create a CuCo and attach the context node. By doing this the binding is done by the wizard itself and you need not add any other extra code piece to bind the CuCo and the context node.
2. Now for ex: You have a table in your new custom view for which you have the CuCo, and the save event is obviously in your main over view page. Now how does your CuCo help your save event no that there is another context node data that has to be saved?
  • Create a ref variable which is of type your component controller, this class has an attribute COMP_CONTROLLER, we need to access this component.
  • Through this COMP_CONTROLLER's ZTYPED_CONTEXT attribute we access the context node, the collection wrapper. With this we will have access to the TRANSACTION CONTEXT which is added to the save context and saved and committed.

Creating a BSP component

1. Tcode BSP_WD_CMPWB
2. Add a model, if you do not know the component set you can use ALL, but make sure you add the right component set because the right one can only give you your desired BO entity.
3. To get config page, in the details page add
<chtmlb:overviewFormConfig/>
4. An overview page does not have .htm
5. You create all the views you need, and all those views/assignment blocks are to be added into the over view page. You don't add any fields in the over view page as such. All the over view page has multiple assignment blocks. So as the over view page is a combination of many views, it can be called a view set.
6. .htm page
This page takes care of configuring your config tab or any buttons you have etc.
chtmlb is the name space for configuration
thtmlb is the name space for toolbar
Ex: You want to add a button in a particular view -
First add a button in the IMPL class of the view,
Add properties for the button in the DO_PREPARE_OUTPUT method.
Once the button is ready, you need to give a position where you need the button to be displayed that can be done in the toolbar.
< thtmlb toolbar is the bsp extension for toolbar that SAP has provided now pass the parameters it needs to put your button in the toolbar of your view.
like
<thtmlb toolbar id                    = "HeaderToolbar"
                        buttons            = <%= controller->gt_button %>
                        maxButtonNumber  = "3"
                        foreignUse = "TRUE" />

For data to flow between 2 views what we need is plugs and navigation link to connect these plugs.
To navigate between 2 views, create outbound plug, inbound plug and navigational link.
To add a button to navigate back from the toolbar, we can follow the same procedure as mentioned above for the edit button. But for this we got to make sure that there is a BSP extension for the toolbar call back. Otherwise, include the necessary interface in your IMPL class and implement the necessary methods.

Custom controller needs to be created to pass data between 2 views. And after creating it has to be bound with the view so that the view data can be accessible to other views.